annotate src/util.c @ 4824:d544c32dcf19

[gaim-migrate @ 5149] A Mayan pilot needs to plane committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 18 Mar 2003 17:30:07 +0000
parents 677d3cb193a1
children 0ed37c803503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 278
diff changeset
22 #ifdef HAVE_CONFIG_H
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
23 #include <config.h>
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 278
diff changeset
24 #endif
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
25
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
26 #ifndef _WIN32
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <unistd.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
28 #include <sys/time.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
29 #include <sys/wait.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
30 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
31 #include <direct.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
32 #include <io.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
33 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
34
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 #include <errno.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <stdio.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include <stdlib.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 #include <sys/types.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 #include <sys/stat.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 #include <string.h>
210
ec0686b3b03f [gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 209
diff changeset
41 #include <ctype.h>
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
42 #ifdef HAVE_ICONV
3361
9bb2e904fadb [gaim-migrate @ 3380]
Sean Egan <seanegan@gmail.com>
parents: 3331
diff changeset
43 #include <iconv.h>
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
44 #endif
1376
730a1a19b4cc [gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1293
diff changeset
45 #include <math.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 #include "gaim.h"
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1560
diff changeset
47 #include "prpl.h"
4687
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4676
diff changeset
48 #include "gtklist.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49
4672
6e3b8a8a143f [gaim-migrate @ 4983]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
50 #include <sys/socket.h>
6e3b8a8a143f [gaim-migrate @ 4983]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
51 #include <arpa/inet.h>
6e3b8a8a143f [gaim-migrate @ 4983]
Mark Doliner <mark@kingant.net>
parents: 4650
diff changeset
52
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
53 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
54 #include "win32dep.h"
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
55 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
56
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
57 #ifndef MAXPATHLEN
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
58 #define MAXPATHLEN 1024
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
59 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
60
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
61 static char home_dir[MAXPATHLEN];
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
62
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
63 char *full_date()
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
64 {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
65 char *date;
70
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
66 time_t tme;
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
67
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
68 time(&tme);
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
69 date = ctime(&tme);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
70 date[strlen(date) - 1] = '\0';
70
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
71 return date;
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
72 }
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
73
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
74 G_GNUC_CONST static gint badchar(char c)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
76 switch (c) {
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
77 case ' ':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
78 case ',':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
79 case '(':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
80 case ')':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
81 case '\0':
976
2586b2a3725e [gaim-migrate @ 986]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 970
diff changeset
82 case '\n':
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
83 case '<':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
84 case '>':
1706
e6671b80a1f2 [gaim-migrate @ 1716]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1622
diff changeset
85 case '"':
413
7ea55575cc01 [gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 373
diff changeset
86 return 1;
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
87 default:
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
88 return 0;
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
89 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92
1376
730a1a19b4cc [gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1293
diff changeset
93 gchar *sec_to_text(guint sec)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94 {
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
95 int daze, hrs, min;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
96 char *ret = g_malloc(256);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
98 daze = sec / (60 * 60 * 24);
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
99 hrs = (sec % (60 * 60 * 24)) / (60 * 60);
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
100 min = (sec % (60 * 60)) / 60;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
101 sec = min % 60;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
103 if (daze) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
104 if (hrs || min) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
105 if (hrs) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
106 if (min) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
107 g_snprintf(ret, 256,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
108 "%d day%s, %d hour%s, %d minute%s.",
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
109 daze, daze == 1 ? "" : "s",
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
110 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s");
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
111 } else {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
112 g_snprintf(ret, 256,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
113 "%d day%s, %d hour%s.",
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
114 daze, daze == 1 ? "" : "s", hrs, hrs == 1 ? "" : "s");
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
115 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
116 } else {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
117 g_snprintf(ret, 256,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
118 "%d day%s, %d minute%s.",
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
119 daze, daze == 1 ? "" : "s", min, min == 1 ? "" : "s");
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
120 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
121 } else
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
122 g_snprintf(ret, 256, "%d day%s.", daze, daze == 1 ? "" : "s");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
123 } else {
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
124 if (hrs) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
125 if (min) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
126 g_snprintf(ret, 256,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
127 "%d hour%s, %d minute%s.",
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
128 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s");
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
129 } else {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
130 g_snprintf(ret, 256, "%d hour%s.", hrs, hrs == 1 ? "" : "s");
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
131 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
132 } else {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
133 g_snprintf(ret, 256, "%d minute%s.", min, min == 1 ? "" : "s");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
134 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
135 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
137 return ret;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 gint linkify_text(char *text)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
142 char *c, *t;
1622
1acef460964a [gaim-migrate @ 1632]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1609
diff changeset
143 char *cpy = g_malloc(strlen(text) * 3 + 1);
1acef460964a [gaim-migrate @ 1632]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1609
diff changeset
144 char url_buf[BUF_LEN * 4];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
145 int cnt = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
146 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
148 strncpy(cpy, text, strlen(text));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
149 cpy[strlen(text)] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
150 c = cpy;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
151 while (*c) {
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
152 if (!g_ascii_strncasecmp(c, "<A", 2)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
153 while (1) {
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
154 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
155 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
156 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
157 text[cnt++] = *c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
158 c++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
159 if (!(*c))
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
160 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
161 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
162 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || (!g_ascii_strncasecmp(c, "https://", 8)))) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
163 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
164 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
165 if (badchar(*t)) {
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
166
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
167 if (*(t) == ',' && (*(t + 1) != ' ')) {
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
168 t++;
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
169 continue;
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
170 }
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
171
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
172 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
173 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
174 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
175 url_buf[t - c] = 0;
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
176 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>",
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
177 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
178 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
179 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
180 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
181 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
182 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
183 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
185 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
186 } else if (!g_ascii_strncasecmp(c, "www.", 4)) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
187 if (c[4] != '.') {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
188 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
189 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
190 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
191 if (t - c == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
192 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
193 }
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
194
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
195 if (*(t) == ',' && (*(t + 1) != ' ')) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
196 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
197 continue;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
198 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
199
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
200 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
201 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
202 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
203 url_buf[t - c] = 0;
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
204 cnt += g_snprintf(&text[cnt], 1024,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
205 "<A HREF=\"http://%s\">%s</A>", url_buf,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
206 url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
207 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
208 break;
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
209 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
210 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
211 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
212 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
213 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
214 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
215 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
216 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
217 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
218 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
219 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
220 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
221 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
222 url_buf[t - c] = 0;
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
223 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>",
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
224 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
225 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
226 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
227 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
228 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
229 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
230 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
232 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
233 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
234 if (c[4] != '.') {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
235 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
236 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
237 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
238 if (t - c == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
239 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
240 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
241 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
242 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
243 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
244 url_buf[t - c] = 0;
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
245 cnt += g_snprintf(&text[cnt], 1024,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
246 "<A HREF=\"ftp://%s\">%s</A>", url_buf,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
247 url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
248 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
249 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
250 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
251 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
252 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
253 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
254 }
924
f6aa60716419 [gaim-migrate @ 934]
Rob Flynn <gaim@robflynn.com>
parents: 915
diff changeset
255 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
256 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
257 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
258 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
259 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
260 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
261 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
262 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
263 url_buf[t - c] = 0;
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
264 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>",
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
265 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
266 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
267 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
268 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
269 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
270 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
271 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
273 }
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
274 } else if (c != cpy && (*c == '@')) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
275 char *tmp;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
276 int flag;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
277 int len = 0;
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
278 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0";
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
279 url_buf[0] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
281 if (strchr(illegal_chars,*(c - 1)) || strchr(illegal_chars, *(c + 1)))
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
282 flag = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
283 else
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
284 flag = 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
285
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
286 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
287 while (flag) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
288 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
289 cnt -= (len - 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
290 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
291 } else {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
292 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
293 tmp = g_malloc(len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
294 tmp[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
295 tmp[0] = *t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
296 strncpy(tmp + 1, url_buf, len - 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
297 strcpy(url_buf, tmp);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
298 url_buf[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
299 g_free(tmp);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
300 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
301 if (t < cpy) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
302 cnt = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
303 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
304 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
305 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
306 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
308 t = c + 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
310 while (flag) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
311 if (badchar(*t)) {
3331
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
312 char *d;
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
313
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
314 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--)
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
315 *d = '\0';
3330
af52fdf06166 [gaim-migrate @ 3348]
Christian Hammond <chipx86@chipx86.com>
parents: 3279
diff changeset
316
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
317 cnt += g_snprintf(&text[cnt], 1024,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
318 "<A HREF=\"mailto:%s\">%s</A>", url_buf,
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
319 url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
320 text[cnt] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
323 c = t;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
325 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
326 } else {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
327 strncat(url_buf, t, 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
328 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
329 url_buf[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
330 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
332 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
333 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
334 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
335
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
336 if (*c == 0)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
337 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
338
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
339 text[cnt++] = *c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
340 c++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
341
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
342 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
343 text[cnt] = 0;
845
647b110f7a1a [gaim-migrate @ 855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 831
diff changeset
344 g_free(cpy);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
345 return cnt;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
346 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
347
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
348
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
349 const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/";
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
350
3147
3805d9d344f2 [gaim-migrate @ 3163]
Sean Egan <seanegan@gmail.com>
parents: 3105
diff changeset
351 /* XXX Find bug */
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
352 char *tobase64(const char *text)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
353 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
354 char *out = NULL;
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
355 const char *c;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
356 unsigned int tmp = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
357 int len = 0, n = 0;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
358
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
359 c = text;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
360
1829
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
361 while (*c) {
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
362 tmp = tmp << 8;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
363 tmp += *c;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
364 n++;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
365
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366 if (n == 3) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
367 out = g_realloc(out, len + 4);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
368 out[len] = alphabet[(tmp >> 18) & 0x3f];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
369 out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
370 out[len + 2] = alphabet[(tmp >> 6) & 0x3f];
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
371 out[len + 3] = alphabet[tmp & 0x3f];
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
372 len += 4;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
373 tmp = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
374 n = 0;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
375 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
376 c++;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
377 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
378 switch (n) {
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
379
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
380 case 2:
1829
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
381 tmp <<= 8;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
382 out = g_realloc(out, len + 5);
1829
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
383 out[len] = alphabet[(tmp >> 18) & 0x3f];
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
384 out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
385 out[len + 2] = alphabet[(tmp >> 6) & 0x3f];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
386 out[len + 3] = '=';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
387 out[len + 4] = 0;
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
388 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
389 case 1:
1829
bdfb37ae28b4 [gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1826
diff changeset
390 tmp <<= 16;
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
391 out = g_realloc(out, len + 5);
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
392 out[len] = alphabet[(tmp >> 18) & 0x3f];
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
393 out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
394 out[len + 2] = '=';
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
395 out[len + 3] = '=';
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
396 out[len + 4] = 0;
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
397 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
398 case 0:
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
399 out = g_realloc(out, len + 1);
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1829
diff changeset
400 out[len] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
401 break;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
402 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
403 return out;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
404 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
405
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
406
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
407 void frombase64(const char *text, char **data, int *size)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
408 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
409 char *out = NULL;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
410 char tmp = 0;
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
411 const char *c;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
412 gint32 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
413 int len = 0, n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
414
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
415 if (!text || !data)
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
416 return;
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
417
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
418 c = text;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
419
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
420 while (*c) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
421 if (*c >= 'A' && *c <= 'Z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
422 tmp = *c - 'A';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
423 } else if (*c >= 'a' && *c <= 'z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
424 tmp = 26 + (*c - 'a');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
425 } else if (*c >= '0' && *c <= 57) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
426 tmp = 52 + (*c - '0');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
427 } else if (*c == '+') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
428 tmp = 62;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
429 } else if (*c == '/') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
430 tmp = 63;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
431 } else if (*c == '=') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
432 if (n == 3) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
433 out = g_realloc(out, len + 2);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
434 out[len] = (char)(tmp2 >> 10) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
435 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
436 out[len] = (char)(tmp2 >> 2) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
437 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
438 } else if (n == 2) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
439 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
440 out[len] = (char)(tmp2 >> 4) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
441 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
442 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
443 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
444 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
445 tmp2 = ((tmp2 << 6) | (tmp & 0xff));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
446 n++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
447 if (n == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
448 out = g_realloc(out, len + 3);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
449 out[len] = (char)((tmp2 >> 16) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
450 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
451 out[len] = (char)((tmp2 >> 8) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
452 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
453 out[len] = (char)(tmp2 & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
454 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
455 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
456 n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
457 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
458 c++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
459 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
460
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
461 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
462 out[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
463
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
464 *data = out;
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
465 if (size)
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
466 *size = len;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
467 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
468
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
469
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
470 char *normalize(const char *s)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
471 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
472 static char buf[BUF_LEN];
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
473 char *tmp;
4282
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
474 int i, j;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
475
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
476 g_return_val_if_fail((s != NULL), NULL);
26
b9e90a914e20 [gaim-migrate @ 35]
Rob Flynn <gaim@robflynn.com>
parents: 25
diff changeset
477
4282
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
478 strncpy(buf, s, BUF_LEN);
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
479 for (i=0, j=0; buf[j]; i++, j++) {
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
480 while (buf[j] == ' ')
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
481 j++;
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
482 buf[i] = buf[j];
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
483 }
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
484 buf[i] = '\0';
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
485
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
486 tmp = g_utf8_strdown(buf, -1);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
487 g_snprintf(buf, sizeof(buf), tmp);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
488 g_free(tmp);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
489
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
490 return buf;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
491 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
492
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
493 char *date()
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
494 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
495 static char date[80];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
496 time_t tme;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
497 time(&tme);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
498 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
499 return date;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
500 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
501
3806
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
502 void clean_pid(void)
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
503 {
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
504 #ifndef _WIN32
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
505 int status;
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
506 pid_t pid;
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
507
3890
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
508 do {
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
509 pid = waitpid(-1, &status, WNOHANG);
3891
a611ec77d1d2 [gaim-migrate @ 4043]
Luke Schierer <lschiere@pidgin.im>
parents: 3890
diff changeset
510 } while (pid != 0 && pid != (pid_t)-1);
3890
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
511 if(pid == (pid_t)-1 && errno != ECHILD) {
3806
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
512 char errmsg[BUFSIZ];
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
513 sprintf(errmsg, "Warning: waitpid() returned %d", pid);
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
514 perror(errmsg);
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
515 }
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
516 #endif
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
517 }
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
518
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
519 struct gaim_account *gaim_account_find(const char *name, int protocol)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
520 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
521 char *who = g_strdup(normalize(name));
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
522 GSList *accts = gaim_accounts;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
523 struct gaim_account *account;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
524
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
525 while (accts) {
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
526 account = (struct gaim_account *)accts->data;
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
527 if (!strcmp(normalize(account->username), who)) {
1030
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
528 if (protocol != -1) {
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
529 if (account->protocol == protocol) {
1030
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
530 g_free(who);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
531 return account;
1030
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
532 }
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
533 } else {
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
534 g_free(who);
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
535 return account;
1030
38452403563b [gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1009
diff changeset
536 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
537
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
538 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
539 accts = accts->next;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
540 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
541 g_free(who);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
542 return NULL;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
543 }
180
0ff9f19b9b23 [gaim-migrate @ 190]
Rob Flynn <gaim@robflynn.com>
parents: 79
diff changeset
544
206
610b7ffc4821 [gaim-migrate @ 216]
Rob Flynn <gaim@robflynn.com>
parents: 194
diff changeset
545
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
546 /* Look for %n, %d, or %t in msg, and replace with the sender's name, date,
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
547 or time */
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
548 char *away_subs(char *msg, char *name)
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
549 {
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
550 char *c;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
551 static char cpy[BUF_LONG];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
552 int cnt = 0;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
553 time_t t = time(0);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
554 struct tm *tme = localtime(&t);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
555 char tmp[20];
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
556
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
557 cpy[0] = '\0';
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
558 c = msg;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
559 while (*c) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
560 switch (*c) {
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
561 case '%':
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
562 if (*(c + 1)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
563 switch (*(c + 1)) {
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
564 case 'n':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
565 /* append name */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
566 strcpy(cpy + cnt, name);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
567 cnt += strlen(name);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
568 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
569 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
570 case 'd':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
571 /* append date */
2161
757e10018950 [gaim-migrate @ 2171]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2155
diff changeset
572 strftime(tmp, 20, "%m/%d/%Y", tme);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
573 strcpy(cpy + cnt, tmp);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
574 cnt += strlen(tmp);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
575 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
576 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
577 case 't':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
578 /* append time */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
579 strftime(tmp, 20, "%r", tme);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
580 strcpy(cpy + cnt, tmp);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
581 cnt += strlen(tmp);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
582 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
583 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
584 default:
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
585 cpy[cnt++] = *c;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
586 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
587 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
588 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
589 default:
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
590 cpy[cnt++] = *c;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
591 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
592 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
593 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
594 cpy[cnt] = '\0';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
595 return (cpy);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
596 }
603
9b0717b4a490 [gaim-migrate @ 613]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 592
diff changeset
597
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
598 char *stylize(gchar *text, int length)
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
599 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
600 gchar *buf;
2016
9a2e3902658c [gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1985
diff changeset
601 char *tmp = g_malloc(length);
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
602
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
603 buf = g_malloc(length);
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
604 g_snprintf(buf, length, "%s", text);
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
605
831
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
606 if (font_options & OPT_FONT_BOLD) {
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
607 g_snprintf(tmp, length, "<B>%s</B>", buf);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
608 strcpy(buf, tmp);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
609 }
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
610
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
611 if (font_options & OPT_FONT_ITALIC) {
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
612 g_snprintf(tmp, length, "<I>%s</I>", buf);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
613 strcpy(buf, tmp);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
614 }
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
615
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
616 if (font_options & OPT_FONT_UNDERLINE) {
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
617 g_snprintf(tmp, length, "<U>%s</U>", buf);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
618 strcpy(buf, tmp);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
619 }
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
620
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
621 if (font_options & OPT_FONT_STRIKE) {
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
622 g_snprintf(tmp, length, "<S>%s</S>", buf);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
623 strcpy(buf, tmp);
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
624 }
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
625
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
626 if (font_options & OPT_FONT_FACE) {
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
627 g_snprintf(tmp, length, "<FONT FACE=\"%s\">%s</FONT>", fontface, buf);
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
628 strcpy(buf, tmp);
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
629 }
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
630
1441
5c67b8794991 [gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1376
diff changeset
631 if (font_options & OPT_FONT_SIZE) {
5c67b8794991 [gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1376
diff changeset
632 g_snprintf(tmp, length, "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf);
5c67b8794991 [gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1376
diff changeset
633 strcpy(buf, tmp);
5c67b8794991 [gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1376
diff changeset
634 }
5c67b8794991 [gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1376
diff changeset
635
831
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
636 if (font_options & OPT_FONT_FGCOL) {
4171
858822a27529 [gaim-migrate @ 4400]
Luke Schierer <lschiere@pidgin.im>
parents: 4162
diff changeset
637 g_snprintf(tmp, length, "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", fgcolor.red/256,
858822a27529 [gaim-migrate @ 4400]
Luke Schierer <lschiere@pidgin.im>
parents: 4162
diff changeset
638 fgcolor.green/256, fgcolor.blue/256, buf);
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
639 strcpy(buf, tmp);
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
640 }
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
641
831
97f1ae636ed7 [gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 804
diff changeset
642 if (font_options & OPT_FONT_BGCOL) {
4171
858822a27529 [gaim-migrate @ 4400]
Luke Schierer <lschiere@pidgin.im>
parents: 4162
diff changeset
643 g_snprintf(tmp, length, "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", bgcolor.red/256,
858822a27529 [gaim-migrate @ 4400]
Luke Schierer <lschiere@pidgin.im>
parents: 4162
diff changeset
644 bgcolor.green/256, bgcolor.blue/256, buf);
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
645 strcpy(buf, tmp);
764
a566fc987db9 [gaim-migrate @ 774]
Todd Kulesza <fflewddur>
parents: 759
diff changeset
646 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
647
2016
9a2e3902658c [gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1985
diff changeset
648 g_free(tmp);
765
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
649 return buf;
bf31bf916f53 [gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 764
diff changeset
650 }
915
378c862a2381 [gaim-migrate @ 925]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 856
diff changeset
651
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
652 void show_usage(int mode, char *name)
1009
d496fe2614a6 [gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 976
diff changeset
653 {
d496fe2614a6 [gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 976
diff changeset
654 switch (mode) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
655 case 0: /* full help text */
3474
cfbdfe334975 [gaim-migrate @ 3525]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
656 printf("Gaim %s\n"
cfbdfe334975 [gaim-migrate @ 3525]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
657 "Usage: %s [OPTION]...\n\n"
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
658 " -a, --acct display account editor window\n"
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
659 " -w, --away[=MESG] make away on signon (optional argument MESG specifies\n"
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
660 " name of away message to use)\n"
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
661 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n"
3726
d85208a99af2 [gaim-migrate @ 3862]
Luke Schierer <lschiere@pidgin.im>
parents: 3699
diff changeset
662 " account(s) to use, seperated by commas)\n"
3530
f38516e5d1ab [gaim-migrate @ 3603]
Sean Egan <seanegan@gmail.com>
parents: 3479
diff changeset
663 " -n, --loginwin don't automatically login; show login window\n"
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
664 " -u, --user=NAME use account NAME\n"
1560
72235e3fcff6 [gaim-migrate @ 1570]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1525
diff changeset
665 " -f, --file=FILE use FILE as config\n"
2823
cd23279122ed [gaim-migrate @ 2836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2662
diff changeset
666 " -d, --debug print debugging messages to stdout\n"
3474
cfbdfe334975 [gaim-migrate @ 3525]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
667 " -v, --version display the current version and exit\n"
cfbdfe334975 [gaim-migrate @ 3525]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
668 " -h, --help display this help and exit\n", VERSION, name);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
669 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
670 case 1: /* short message */
3474
cfbdfe334975 [gaim-migrate @ 3525]
Sean Egan <seanegan@gmail.com>
parents: 3466
diff changeset
671 printf("Gaim %s. Try `%s -h' for more information.\n", VERSION, name);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
672 break;
1009
d496fe2614a6 [gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 976
diff changeset
673 }
d496fe2614a6 [gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 976
diff changeset
674 }
d496fe2614a6 [gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 976
diff changeset
675
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
676 GSList *message_split(char *message, int limit)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
677 {
1100
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
678 static GSList *ret = NULL;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
679 int lastgood = 0, curgood = 0, curpos = 0, len = strlen(message);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
680 gboolean intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
681
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
682 if (ret) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
683 GSList *tmp = ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
684 while (tmp) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
685 g_free(tmp->data);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
686 tmp = g_slist_remove(tmp, tmp->data);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
687 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
688 ret = NULL;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
689 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
690
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
691 while (TRUE) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
692 if (lastgood >= len)
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
693 return ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
694
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
695 if (len - lastgood < limit) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
696 ret = g_slist_append(ret, g_strdup(&message[lastgood]));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
697 return ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
698 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
699
1100
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
700 curgood = curpos = 0;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
701 intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
702 while (curpos <= limit) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
703 if (isspace(message[curpos + lastgood]) && !intag)
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
704 curgood = curpos;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
705 if (message[curpos + lastgood] == '<')
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
706 intag = TRUE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
707 if (message[curpos + lastgood] == '>')
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
708 intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
709 curpos++;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
710 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
711
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
712 if (curgood) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
713 ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
714 if (isspace(message[curgood + lastgood]))
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
715 lastgood += curgood + 1;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
716 else
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
717 lastgood += curgood;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
718 } else {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
719 /* whoops, guess we have to fudge it here */
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
720 ret = g_slist_append(ret, g_strndup(&message[lastgood], limit));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
721 lastgood += limit;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
722 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
723 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
724 }
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
725
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
726 const gchar *gaim_home_dir()
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
727 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
728 if(g_get_home_dir())
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
729 return g_get_home_dir();
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
730 else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
731 #ifndef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
732 return NULL;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
733 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
734 /* Win9x and WinME don't have a home dir */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
735 return "C:";
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
736 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
737
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
738 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
739
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
740 /* returns a string of the form ~/.gaim, where ~ is replaced by the user's home
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
741 * dir. Note that there is no trailing slash after .gaim. */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
742 gchar *gaim_user_dir()
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
743 {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
744 const gchar *hd = gaim_home_dir();
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
745 if(hd) {
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
746 strcpy( (char*)&home_dir, hd );
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
747 strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
748 return (gchar*)&home_dir;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
749 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
750 else {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
751 return NULL;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
752 }
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
753 }
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
754
1292
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
755 /*
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
756 * rcg10312000 This could be more robust, but it works for my current
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
757 * goal: to remove those annoying <BR> tags. :)
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
758 * dtf12162000 made the loop more readable. i am a neat freak. ;) */
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
759 void strncpy_nohtml(gchar *dest, const gchar *src, size_t destsize)
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
760 {
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
761 gchar *ptr;
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
762 g_snprintf(dest, destsize, "%s", src);
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
763
1815
f15d449b3167 [gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1805
diff changeset
764 while ((ptr = strstr(dest, "<BR>")) != NULL) {
1292
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
765 /* replace <BR> with a newline. */
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
766 *ptr = '\n';
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
767 memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1);
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
768 }
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
769 }
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
770
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
771 void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize)
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
772 {
1202
d5146df6d2ab [gaim-migrate @ 1212]
Rob Flynn <gaim@robflynn.com>
parents: 1197
diff changeset
773 gchar *end = dest + destsize;
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
774
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
775 while (dest < end) {
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
776 if (*src == '\n' && dest < end - 5) {
1202
d5146df6d2ab [gaim-migrate @ 1212]
Rob Flynn <gaim@robflynn.com>
parents: 1197
diff changeset
777 strcpy(dest, "<BR>");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
778 src++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
779 dest += 4;
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
780 } else {
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
781 *dest++ = *src;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
782 if (*src == '\0')
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
783 return;
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
784 else
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
785 src++;
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
786 }
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
787 }
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
788 }
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
789
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
790
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
791 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
792 * Like strncpy_withhtml (above), but malloc()'s the necessary space
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
793 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
794 * The caller is responsible for freeing the space pointed to by the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
795 * return value.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
796 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
797
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
798 gchar *strdup_withhtml(const gchar *src)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
799 {
3279
86fdd015f40e [gaim-migrate @ 3297]
Sean Egan <seanegan@gmail.com>
parents: 3233
diff changeset
800 gchar *sp, *dest;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
801 gulong destsize;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
802
4771
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
803 if(!src)
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
804 return NULL;
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
805
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
806 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
807 * All we need do is multiply the number of newlines by 3 (the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
808 * additional length of "<BR>" over "\n"), account for the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
809 * terminator, malloc the space and call strncpy_withhtml.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
810 */
3279
86fdd015f40e [gaim-migrate @ 3297]
Sean Egan <seanegan@gmail.com>
parents: 3233
diff changeset
811 for(destsize = 0, sp = (gchar *)src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize)
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
812 ;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
813 destsize *= 3;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
814 destsize += strlen(src) + 1;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
815 dest = g_malloc(destsize);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
816 strncpy_withhtml(dest, src, destsize);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
817
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
818 return(dest);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
819 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
820
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
821 void away_on_login(char *mesg)
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
822 {
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
823 GSList *awy = away_messages;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
824 struct away_message *a, *message = NULL;
4695
4bdd9a5fd026 [gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents: 4687
diff changeset
825 struct gaim_gtk_buddy_list *gtkblist;
4bdd9a5fd026 [gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents: 4687
diff changeset
826
4bdd9a5fd026 [gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents: 4687
diff changeset
827 gtkblist = GAIM_GTK_BLIST(gaim_get_blist());
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
828
4687
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4676
diff changeset
829 if (!gtkblist->window) {
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
830 return;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
831 }
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
832
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
833 if (mesg == NULL) {
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
834 /* Use default message */
2379
cacaf7ace3a5 [gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
835 do_away_message(NULL, default_away);
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
836 } else {
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
837 /* Use argument */
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
838 while (awy) {
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
839 a = (struct away_message *)awy->data;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
840 if (strcmp(a->name, mesg) == 0) {
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
841 message = a;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
842 break;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
843 }
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
844 awy = awy->next;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
845 }
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
846 if (message == NULL)
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
847 message = default_away;
2379
cacaf7ace3a5 [gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
848 do_away_message(NULL, message);
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
849 }
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
850 return;
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
851 }
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1560
diff changeset
852
2603
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
853 void strip_linefeed(gchar *text)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
854 {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
855 int i, j;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
856 gchar *text2 = g_malloc(strlen(text) + 1);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
857
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
858 for (i = 0, j = 0; text[i]; i++)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
859 if (text[i] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
860 text2[j++] = text[i];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
861 text2[j] = '\0';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
862
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
863 strcpy(text, text2);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
864 g_free(text2);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
865 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
866
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
867 char *add_cr(char *text)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
868 {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
869 char *ret = NULL;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
870 int count = 0, i, j;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
871
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
872 if (text[0] == '\n')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
873 count++;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
874 for (i = 1; i < strlen(text); i++)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
875 if (text[i] == '\n' && text[i - 1] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
876 count++;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
877
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
878 if (count == 0)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
879 return g_strdup(text);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
880
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
881 ret = g_malloc0(strlen(text) + count + 1);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
882
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
883 i = 0; j = 0;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
884 if (text[i] == '\n')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
885 ret[j++] = '\r';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
886 ret[j++] = text[i++];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
887 for (; i < strlen(text); i++) {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
888 if (text[i] == '\n' && text[i - 1] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
889 ret[j++] = '\r';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
890 ret[j++] = text[i];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
891 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
892
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
893 debug_printf("got: %s, leaving with %s\n", text, ret);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
894
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
895 return ret;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
896 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
897
1805
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
898 time_t get_time(int year, int month, int day, int hour, int min, int sec)
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
899 {
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
900 struct tm tm;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
901
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
902 tm.tm_year = year - 1900;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
903 tm.tm_mon = month - 1;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
904 tm.tm_mday = day;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
905 tm.tm_hour = hour;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
906 tm.tm_min = min;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
907 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
908 return mktime(&tm);
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
909 }
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
910
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
911 /*
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
912 * Like mkstemp() but returns a file pointer, uses a pre-set template,
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
913 * uses the semantics of tempnam() for the directory to use and allocates
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
914 * the space for the filepath.
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
915 *
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
916 * Caller is responsible for closing the file and removing it when done,
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
917 * as well as freeing the space pointed-to by "path" with g_free().
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
918 *
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
919 * Returns NULL on failure and cleans up after itself if so.
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
920 */
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
921 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"};
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
922
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
923 FILE *gaim_mkstemp(gchar **fpath)
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
924 {
3466
7a3f16a375a5 [gaim-migrate @ 3516]
Sean Egan <seanegan@gmail.com>
parents: 3457
diff changeset
925 const gchar *tmpdir;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
926 #ifndef _WIN32
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
927 int fd;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
928 #endif
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
929 FILE *fp = NULL;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
930
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
931 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
932 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
933 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
934 char* result = _mktemp( *fpath );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
935 if( result == NULL )
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
936 debug_printf("gaim_mkstemp: Problem creating the template\n");
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
937 else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
938 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
939 if( (fp = fopen( result, "w+" )) == NULL ) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
940 debug_printf("Error: Couldn't fopen() in gaim_mkstemp():\n%s\n", result);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
941 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
942 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
943 #else
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
944 if((fd = mkstemp(*fpath)) == -1) {
3232
cf460a8c859c [gaim-migrate @ 3249]
Jim Seymour <jseymour>
parents: 3230
diff changeset
945 debug_printf("Error: Couldn't make \"%s\", error: %d\n", *fpath, errno);
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
946 } else {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
947 if((fp = fdopen(fd, "r+")) == NULL) {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
948 close(fd);
3232
cf460a8c859c [gaim-migrate @ 3249]
Jim Seymour <jseymour>
parents: 3230
diff changeset
949 debug_printf("Error: Couldn't fdopen(), error: %d\n", errno);
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
950 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
951 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
952 #endif
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
953 if(!fp) {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
954 g_free(*fpath);
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
955 *fpath = NULL;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
956 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
957 }
3233
96e215745dc0 [gaim-migrate @ 3250]
Jim Seymour <jseymour>
parents: 3232
diff changeset
958 } else {
96e215745dc0 [gaim-migrate @ 3250]
Jim Seymour <jseymour>
parents: 3232
diff changeset
959 debug_printf("Error: g_get_tmp_dir() failed in gaim_mkstemp()!\n");
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
960 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
961
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
962 return fp;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
963 }
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
964
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
965 /* AIM URI's ARE FUN :-D */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
966 const char *handle_uri(char *uri) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
967 GString *str;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
968 GSList *conn = connections;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
969 struct gaim_connection *gc = NULL;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
970
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
971 debug_printf("Handling URI: %s\n", uri);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
972
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
973 /* Well, we'd better check to make sure we have at least one
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
974 AIM account connected. */
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
975 while (conn) {
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
976 gc = conn->data;
4349
0c68d402f59f [gaim-migrate @ 4614]
Nathan Walp <nwalp@pidgin.im>
parents: 4309
diff changeset
977 if (gc->protocol == PROTO_OSCAR && isalpha(gc->username[0])) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
978 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
979 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
980 conn = conn->next;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
981 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
982
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
983 if (gc == NULL)
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
984 return _("Not connected to AIM");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
985
3479
84df15473af6 [gaim-migrate @ 3533]
Sean Egan <seanegan@gmail.com>
parents: 3478
diff changeset
986 /* aim:goim?screenname=screenname&message=message */
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
987 if (!g_ascii_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
988 char *who, *what;
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4349
diff changeset
989 struct gaim_conversation *c;
3479
84df15473af6 [gaim-migrate @ 3533]
Sean Egan <seanegan@gmail.com>
parents: 3478
diff changeset
990 uri = uri + strlen("aim:goim?");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
991
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
992 if (!(who = strstr(uri, "screenname="))) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
993 return _("No screenname given.");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
994 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
995 /* spaces are encoded as +'s */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
996 who = who + strlen("screenname=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
997 str = g_string_new(NULL);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
998 while (*who && (*who != '&')) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
999 g_string_append_c(str, *who == '+' ? ' ' : *who);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1000 who++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1001 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1002 who = g_strdup(str->str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1003 g_string_free(str, TRUE);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1004
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1005 what = strstr(uri, "message=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1006 if (what) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1007 what = what + strlen("message=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1008 str = g_string_new(NULL);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1009 while (*what && (*what != '&' || !g_ascii_strncasecmp(what, "&amp;", 5))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1010 g_string_append_c(str, *what == '+' ? ' ' : *what);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1011 what++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1012 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1013 what = g_strdup(str->str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1014 g_string_free(str, TRUE);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1015 }
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
1016
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
1017 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, who);
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1018 g_free(who);
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4349
diff changeset
1019
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1020 if (what) {
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4349
diff changeset
1021 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(c);
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4349
diff changeset
1022
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents: 4349
diff changeset
1023 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1);
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1024 g_free(what);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1025 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1026 } else if (!g_ascii_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1027 char *who, *group;
3479
84df15473af6 [gaim-migrate @ 3533]
Sean Egan <seanegan@gmail.com>
parents: 3478
diff changeset
1028 uri = uri + strlen("aim:addbuddy?");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1029 /* spaces are encoded as +'s */
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4476
diff changeset
1030
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1031 if (!(who = strstr(uri, "screenname="))) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
1032 return _("No screenname given.");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1033 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1034 who = who + strlen("screenname=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1035 str = g_string_new(NULL);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1036 while (*who && (*who != '&')) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1037 g_string_append_c(str, *who == '+' ? ' ' : *who);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1038 who++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1039 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1040 who = g_strdup(str->str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1041 g_string_free(str, TRUE);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1042
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1043 group = strstr(uri, "group=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1044 if (group) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1045 group = group + strlen("group=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1046 str = g_string_new(NULL);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1047 while (*group && (*group != '&' || !g_ascii_strncasecmp(group, "&amp;", 5))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1048 g_string_append_c(str, *group == '+' ? ' ' : *group);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1049 group++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1050 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1051 group = g_strdup(str->str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1052 g_string_free(str, TRUE);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1053 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1054 debug_printf("who: %s\n", who);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1055 show_add_buddy(gc, who, group, NULL);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1056 g_free(who);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1057 if (group)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1058 g_free(group);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1059 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1060 char *room;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1061 GList *chat=NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1062 int exch = 5;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1063
3479
84df15473af6 [gaim-migrate @ 3533]
Sean Egan <seanegan@gmail.com>
parents: 3478
diff changeset
1064 uri = uri + strlen("aim:gochat?");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1065 /* spaces are encoded as +'s */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1066
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1067 if (!(room = strstr(uri, "roomname="))) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
1068 return _("No roomname given.");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1069 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1070 room = room + strlen("roomname=");
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1071 str = g_string_new(NULL);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1072 while (*room && (*room != '&')) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1073 g_string_append_c(str, *room == '+' ? ' ' : *room);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1074 room++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1075 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1076 room = g_strdup(str->str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1077 g_string_free(str, TRUE);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1078 chat = g_list_append(NULL, room);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1079 chat = g_list_append(chat, &exch);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1080 serv_join_chat(gc, chat);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1081 g_free(room);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1082 g_list_free(chat);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1083 } else {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
1084 return _("Invalid AIM URI");
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1085 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1086
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1087
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1088 return NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
1089 }
3649
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1090
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1091 GtkWidget *gaim_pixmap(char *subdir, char *iconfile) {
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1092 char *filename;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1093 GtkWidget *image;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1094
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1095 if (subdir != NULL)
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1096 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1097 else
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1098 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1099
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1100 debug_printf("Loading: %s\n", filename);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1101
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1102 image = gtk_image_new_from_file(filename);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1103
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1104 g_free(filename);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1105
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1106 return image;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1107 }
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1108
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1109 GdkPixbuf *gaim_pixbuf(char *subdir, char *iconfile) {
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1110 char *filename;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1111 GdkPixbuf *pixbuf;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1112 GError *err = NULL;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1113
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1114 if (subdir != NULL)
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1115 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1116 else
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1117 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1118
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1119 debug_printf("Loading: %s\n", filename);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1120
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1121 pixbuf = gdk_pixbuf_new_from_file(filename, &err);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1122 if (!pixbuf) {
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1123 /* FIXME: Maybe we should handle this error */
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1124 g_error_free(err);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1125 }
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1126
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1127 g_free(filename);
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1128
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1129 return pixbuf;
f09193608fd3 [gaim-migrate @ 3773]
Rob Flynn <gaim@robflynn.com>
parents: 3642
diff changeset
1130 }
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1131
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1132 GtkWidget *gaim_new_item_from_stock(GtkWidget *menu, const char *str, const char *icon, GtkSignalFunc sf, gpointer data, guint accel_key, guint accel_mods, char *mod)
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1133 {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1134 GtkWidget *menuitem;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1135 /*
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1136 GtkWidget *hbox;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1137 GtkWidget *label;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1138 */
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1139 GtkWidget *image;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1140
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1141 if (icon == NULL)
4309
5978e3d53f29 [gaim-migrate @ 4563]
Luke Schierer <lschiere@pidgin.im>
parents: 4282
diff changeset
1142 menuitem = gtk_menu_item_new_with_mnemonic(str);
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1143 else
4309
5978e3d53f29 [gaim-migrate @ 4563]
Luke Schierer <lschiere@pidgin.im>
parents: 4282
diff changeset
1144 menuitem = gtk_image_menu_item_new_with_mnemonic(str);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1145
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1146 if (menu)
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1147 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1148
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1149 if (sf)
4162
d3c8d2b40494 [gaim-migrate @ 4391]
Christian Hammond <chipx86@chipx86.com>
parents: 4160
diff changeset
1150 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1151
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1152 if (icon != NULL) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1153 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1154 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1155 }
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1156 /* FIXME: this isn't right
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1157 if (mod) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1158 label = gtk_label_new(mod);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1159 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1160 gtk_widget_show(label);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1161 }
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1162 */
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1163 /*
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1164 if (accel_key) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1165 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key,
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1166 accel_mods, GTK_ACCEL_LOCKED);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1167 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1168 */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1169
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1170 gtk_widget_show_all(menuitem);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1171
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1172 return menuitem;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1173 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1174
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1175 GtkWidget *gaim_new_item_from_pixbuf(GtkWidget *menu, const char *str, char *iconname, GtkSignalFunc sf, gpointer data, guint accel_key, guint accel_mods, char *mod)
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1176 {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1177 GtkWidget *menuitem;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1178 /*
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1179 GtkWidget *hbox;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1180 GtkWidget *label;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1181 */
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1182 GtkWidget *image;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1183
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1184 if (iconname == NULL)
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1185 menuitem = gtk_menu_item_new_with_mnemonic(_(str));
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1186 else
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1187 menuitem = gtk_image_menu_item_new_with_mnemonic(_(str));
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1188
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1189 if (menu)
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1190 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1191
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1192 if (sf)
4162
d3c8d2b40494 [gaim-migrate @ 4391]
Christian Hammond <chipx86@chipx86.com>
parents: 4160
diff changeset
1193 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1194
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1195 if (iconname != NULL) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1196 char *filename;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1197
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1198 filename = g_build_filename (DATADIR, "pixmaps", "gaim", "menus", iconname, NULL);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1199 debug_printf("Loading: %s\n", filename);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1200 image = gtk_image_new_from_file(filename);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1201 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1202 g_free(filename);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1203 }
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1204 /* FIXME: this isn't right either
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1205 if (mod) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1206 label = gtk_label_new(mod);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1207 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1208 gtk_widget_show(label);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1209 }
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
1210 */
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1211 /*
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1212 if (accel_key) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1213 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key,
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1214 accel_mods, GTK_ACCEL_LOCKED);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1215 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1216 */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1217
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1218 gtk_widget_show_all(menuitem);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1219
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1220 return menuitem;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1221 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1222
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1223
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1224 GtkWidget *gaim_new_item_with_pixmap(GtkWidget *menu, const char *str, char **xpm, GtkSignalFunc sf, gpointer data, guint accel_key, guint accel_mods, char *mod)
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1225 {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1226 GtkWidget *menuitem;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1227 GtkWidget *hbox;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1228 GtkWidget *label;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1229 GtkWidget *pixmap;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1230 GdkPixmap *pm;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1231 GdkBitmap *mask;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1232
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1233 menuitem = gtk_menu_item_new();
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1234 if (menu)
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1235 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1236 if (sf)
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1237 /* passing 1 is necessary so if we sign off closing the account editor doesn't exit */
4162
d3c8d2b40494 [gaim-migrate @ 4391]
Christian Hammond <chipx86@chipx86.com>
parents: 4160
diff changeset
1238 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1239 gtk_widget_show(menuitem);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1240
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1241 /* Create our container */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1242 hbox = gtk_hbox_new(FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1243 gtk_container_add(GTK_CONTAINER(menuitem), hbox);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1244 gtk_widget_show(hbox);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1245
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1246 /* Create our pixmap and pack it */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1247 gtk_widget_realize(menu->parent);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1248 pm = gdk_pixmap_create_from_xpm_d(menu->parent->window, &mask, NULL, xpm);
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1249 pixmap = gtk_image_new_from_pixmap(pm, mask);
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1250 gtk_widget_show(pixmap);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1251 g_object_unref(G_OBJECT(pm));
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1252 g_object_unref(G_OBJECT(mask));
3668
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1253 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1254
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1255 /* Create our label and pack it */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1256 label = gtk_label_new(str);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1257 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1258 gtk_widget_show(label);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1259
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1260 if (mod) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1261 label = gtk_label_new(mod);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1262 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1263 gtk_widget_show(label);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1264 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1265 /*
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1266 if (accel_key) {
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1267 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key,
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1268 accel_mods, GTK_ACCEL_LOCKED);
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1269 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1270 */
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1271 return menuitem;
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1272 }
5b82f99d028d [gaim-migrate @ 3798]
Rob Flynn <gaim@robflynn.com>
parents: 3649
diff changeset
1273
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1274 GtkWidget *gaim_new_item(GtkWidget *menu, const char *str)
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1275 {
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1276 GtkWidget *menuitem;
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1277 GtkWidget *label;
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1278
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1279 menuitem = gtk_menu_item_new();
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1280 if (menu)
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
1281 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1282 gtk_widget_show(menuitem);
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1283
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1284 label = gtk_label_new(str);
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1285 gtk_label_set_pattern(GTK_LABEL(label), "_");
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1286 gtk_container_add(GTK_CONTAINER(menuitem), label);
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1287 gtk_widget_show(label);
3699
b401bd1701b4 [gaim-migrate @ 3830]
Rob Flynn <gaim@robflynn.com>
parents: 3698
diff changeset
1288 /* FIXME: Go back and fix this
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1289 gtk_widget_add_accelerator(menuitem, "activate", accel, str[0],
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1290 GDK_MOD1_MASK, GTK_ACCEL_LOCKED);
3699
b401bd1701b4 [gaim-migrate @ 3830]
Rob Flynn <gaim@robflynn.com>
parents: 3698
diff changeset
1291 */
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1292 return menuitem;
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1293 }
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1294
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1295 char *gaim_try_conv_to_utf8(const char *str)
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1296 {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1297 int converted;
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1298 char *utf8;
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1299
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1300 if (str == NULL) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1301 return NULL;
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1302 }
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1303
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1304 if (g_utf8_validate(str, -1, NULL)) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1305 return g_strdup(str);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1306 }
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1307
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1308 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1309 if (utf8 && converted == strlen (str)) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1310 return(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1311 } else if (utf8) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1312 g_free(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1313 }
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1314
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1315 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1316 if (utf8 && converted == strlen (str)) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1317 return(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1318 } else if (utf8) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1319 g_free(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1320 }
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
1321
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1322 return(NULL);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
1323 }
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1324
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1325 char *gaim_getip_from_fd(int fd)
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1326 {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1327 struct sockaddr addr;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1328 socklen_t namelen = sizeof(addr);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1329
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1330 if (getsockname(fd, &addr, &namelen))
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1331 return NULL;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1332
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1333 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr));
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
1334 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1335
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1336 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b) {
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1337 gchar *a_norm = g_utf8_casefold(a, -1);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1338 gchar *b_norm = g_utf8_casefold(b, -1);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1339 gint ret = g_utf8_collate(a_norm, b_norm);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1340 g_free(a_norm);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1341 g_free(b_norm);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1342 return ret;
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
1343 }