Mercurial > pidgin.yaz
annotate src/util.c @ 4774:e870e313be96
[gaim-migrate @ 5093]
No, seriously. Gaim is one bad ass chick.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 14 Mar 2003 16:18:51 +0000 |
parents | 912bacf989d7 |
children | 677d3cb193a1 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
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 | 25 |
26 #ifndef _WIN32 | |
1 | 27 #include <unistd.h> |
3630 | 28 #include <sys/time.h> |
29 #include <sys/wait.h> | |
30 #else | |
31 #include <direct.h> | |
32 #include <io.h> | |
33 #endif | |
34 | |
1 | 35 #include <errno.h> |
36 #include <stdio.h> | |
37 #include <stdlib.h> | |
38 #include <sys/types.h> | |
39 #include <sys/stat.h> | |
40 #include <string.h> | |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
209
diff
changeset
|
41 #include <ctype.h> |
3478 | 42 #ifdef HAVE_ICONV |
3361 | 43 #include <iconv.h> |
3478 | 44 #endif |
1376
730a1a19b4cc
[gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1293
diff
changeset
|
45 #include <math.h> |
1 | 46 #include "gaim.h" |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
47 #include "prpl.h" |
4687 | 48 #include "gtklist.h" |
1 | 49 |
4672 | 50 #include <sys/socket.h> |
51 #include <arpa/inet.h> | |
52 | |
3630 | 53 #ifdef _WIN32 |
54 #include "win32dep.h" | |
55 #endif | |
56 | |
57 #ifndef MAXPATHLEN | |
58 #define MAXPATHLEN 1024 | |
59 #endif | |
60 | |
61 static char home_dir[MAXPATHLEN]; | |
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 | 66 time_t tme; |
67 | |
68 time(&tme); | |
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 | 71 return date; |
72 } | |
73 | |
4160 | 74 G_GNUC_CONST static gint badchar(char c) |
1 | 75 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
76 switch (c) { |
970 | 77 case ' ': |
78 case ',': | |
79 case '(': | |
80 case ')': | |
81 case '\0': | |
976
2586b2a3725e
[gaim-migrate @ 986]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
970
diff
changeset
|
82 case '\n': |
970 | 83 case '<': |
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 | 87 default: |
88 return 0; | |
89 } | |
1 | 90 } |
91 | |
92 | |
1376
730a1a19b4cc
[gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1293
diff
changeset
|
93 gchar *sec_to_text(guint sec) |
1 | 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 | 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 | 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 | 136 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
137 return ret; |
1 | 138 } |
139 | |
140 gint linkify_text(char *text) | |
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 | 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) { |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
152 if (!g_strncasecmp(c, "<A", 2)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
153 while (1) { |
2596
35c23df11d16
[gaim-migrate @ 2609]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2397
diff
changeset
|
154 if (!g_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 } |
4160 | 162 } else if ((*c=='h') && (!g_strncasecmp(c, "http://", 7) || (!g_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 | 166 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
167 if (*(t) == ',' && (*(t + 1) != ' ')) { |
925 | 168 t++; |
169 continue; | |
170 } | |
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 | 184 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
185 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
186 } else if (!g_strncasecmp(c, "www.", 4)) { |
4160 | 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 | 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 | 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 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
215 } else if (!g_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 | 231 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
232 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
233 } else if (!g_strncasecmp(c, "ftp.", 4)) { |
4160 | 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 | 255 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
256 } else if (!g_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 | 272 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
273 } |
4160 | 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 | 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 | 280 |
4160 | 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 | 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 | 307 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
308 t = c + 1; |
1 | 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 | 321 |
322 | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
323 c = t; |
1 | 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 | 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 | 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 | 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 | 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 | 346 } |
347 | |
348 | |
4160 | 349 const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/"; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
350 |
3147 | 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 | 353 { |
354 char *out = NULL; | |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
355 const char *c; |
1 | 356 unsigned int tmp = 0; |
357 int len = 0, n = 0; | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
358 |
1 | 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 | 362 tmp = tmp << 8; |
363 tmp += *c; | |
364 n++; | |
365 | |
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 | 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 | 372 len += 4; |
373 tmp = 0; | |
374 n = 0; | |
375 } | |
376 c++; | |
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 | 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 | 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 | 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 | 401 break; |
402 } | |
403 return out; | |
404 } | |
405 | |
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 | 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 | 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 | 467 } |
468 | |
469 | |
470 char *normalize(const char *s) | |
471 { | |
472 static char buf[BUF_LEN]; | |
4282 | 473 int i, j; |
1 | 474 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
475 g_return_val_if_fail((s != NULL), NULL); |
26 | 476 |
4282 | 477 strncpy(buf, s, BUF_LEN); |
478 for (i=0, j=0; buf[j]; i++, j++) { | |
479 while (buf[j] == ' ') | |
480 j++; | |
481 buf[i] = buf[j]; | |
482 } | |
483 buf[i] = '\0'; | |
484 g_strdown(buf); | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
485 |
1 | 486 return buf; |
487 } | |
488 | |
489 char *date() | |
490 { | |
491 static char date[80]; | |
492 time_t tme; | |
493 time(&tme); | |
494 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme)); | |
495 return date; | |
496 } | |
497 | |
3806 | 498 void clean_pid(void) |
499 { | |
500 #ifndef _WIN32 | |
501 int status; | |
502 pid_t pid; | |
503 | |
3890 | 504 do { |
505 pid = waitpid(-1, &status, WNOHANG); | |
3891 | 506 } while (pid != 0 && pid != (pid_t)-1); |
3890 | 507 if(pid == (pid_t)-1 && errno != ECHILD) { |
3806 | 508 char errmsg[BUFSIZ]; |
509 sprintf(errmsg, "Warning: waitpid() returned %d", pid); | |
510 perror(errmsg); | |
511 } | |
512 #endif | |
513 } | |
514 | |
4491 | 515 struct gaim_account *gaim_account_find(const char *name, int protocol) |
1 | 516 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
517 char *who = g_strdup(normalize(name)); |
4491 | 518 GSList *accts = gaim_accounts; |
519 struct gaim_account *account; | |
1 | 520 |
4491 | 521 while (accts) { |
522 account = (struct gaim_account *)accts->data; | |
523 if (!strcmp(normalize(account->username), who)) { | |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
524 if (protocol != -1) { |
4491 | 525 if (account->protocol == protocol) { |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
526 g_free(who); |
4491 | 527 return account; |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
528 } |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
529 } else { |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
530 g_free(who); |
4491 | 531 return account; |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
532 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
533 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
534 } |
4491 | 535 accts = accts->next; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
536 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
537 g_free(who); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
538 return NULL; |
1 | 539 } |
180 | 540 |
206 | 541 |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
542 /* 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
|
543 or time */ |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
544 char *away_subs(char *msg, char *name) |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
545 { |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
546 char *c; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
547 static char cpy[BUF_LONG]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
548 int cnt = 0; |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
549 time_t t = time(0); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
550 struct tm *tme = localtime(&t); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
551 char tmp[20]; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
552 |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
553 cpy[0] = '\0'; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
554 c = msg; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
555 while (*c) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
556 switch (*c) { |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
557 case '%': |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
558 if (*(c + 1)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
559 switch (*(c + 1)) { |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
560 case 'n': |
1976 | 561 /* append name */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
562 strcpy(cpy + cnt, name); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
563 cnt += strlen(name); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
564 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
565 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
566 case 'd': |
1976 | 567 /* append date */ |
2161
757e10018950
[gaim-migrate @ 2171]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2155
diff
changeset
|
568 strftime(tmp, 20, "%m/%d/%Y", tme); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
569 strcpy(cpy + cnt, tmp); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
570 cnt += strlen(tmp); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
571 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
572 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
573 case 't': |
1976 | 574 /* append time */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
575 strftime(tmp, 20, "%r", tme); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
576 strcpy(cpy + cnt, tmp); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
577 cnt += strlen(tmp); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
578 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
579 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
580 default: |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
581 cpy[cnt++] = *c; |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
582 } |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
583 } |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
584 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
585 default: |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
586 cpy[cnt++] = *c; |
592
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 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
589 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
590 cpy[cnt] = '\0'; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
591 return (cpy); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
592 } |
603
9b0717b4a490
[gaim-migrate @ 613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
592
diff
changeset
|
593 |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
594 char *stylize(gchar *text, int length) |
764 | 595 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
596 gchar *buf; |
2016
9a2e3902658c
[gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1985
diff
changeset
|
597 char *tmp = g_malloc(length); |
764 | 598 |
599 buf = g_malloc(length); | |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
600 g_snprintf(buf, length, "%s", text); |
764 | 601 |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
602 if (font_options & OPT_FONT_BOLD) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
603 g_snprintf(tmp, length, "<B>%s</B>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
604 strcpy(buf, tmp); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
605 } |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
606 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
607 if (font_options & OPT_FONT_ITALIC) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
608 g_snprintf(tmp, length, "<I>%s</I>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
609 strcpy(buf, tmp); |
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 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
612 if (font_options & OPT_FONT_UNDERLINE) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
613 g_snprintf(tmp, length, "<U>%s</U>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
614 strcpy(buf, tmp); |
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 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
617 if (font_options & OPT_FONT_STRIKE) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
618 g_snprintf(tmp, length, "<S>%s</S>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
619 strcpy(buf, tmp); |
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 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
622 if (font_options & OPT_FONT_FACE) { |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
623 g_snprintf(tmp, length, "<FONT FACE=\"%s\">%s</FONT>", fontface, buf); |
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
624 strcpy(buf, tmp); |
764 | 625 } |
626 | |
1441
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
627 if (font_options & OPT_FONT_SIZE) { |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
628 g_snprintf(tmp, length, "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf); |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
629 strcpy(buf, tmp); |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
630 } |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
631 |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
632 if (font_options & OPT_FONT_FGCOL) { |
4171 | 633 g_snprintf(tmp, length, "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", fgcolor.red/256, |
634 fgcolor.green/256, fgcolor.blue/256, buf); | |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
635 strcpy(buf, tmp); |
764 | 636 } |
637 | |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
638 if (font_options & OPT_FONT_BGCOL) { |
4171 | 639 g_snprintf(tmp, length, "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", bgcolor.red/256, |
640 bgcolor.green/256, bgcolor.blue/256, buf); | |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
641 strcpy(buf, tmp); |
764 | 642 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
643 |
2016
9a2e3902658c
[gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1985
diff
changeset
|
644 g_free(tmp); |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
645 return buf; |
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
646 } |
915
378c862a2381
[gaim-migrate @ 925]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
856
diff
changeset
|
647 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
648 void show_usage(int mode, char *name) |
1009
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
649 { |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
650 switch (mode) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
651 case 0: /* full help text */ |
3474 | 652 printf("Gaim %s\n" |
653 "Usage: %s [OPTION]...\n\n" | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
654 " -a, --acct display account editor window\n" |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
655 " -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
|
656 " name of away message to use)\n" |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
657 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
3726 | 658 " account(s) to use, seperated by commas)\n" |
3530 | 659 " -n, --loginwin don't automatically login; show login window\n" |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
660 " -u, --user=NAME use account NAME\n" |
1560
72235e3fcff6
[gaim-migrate @ 1570]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1525
diff
changeset
|
661 " -f, --file=FILE use FILE as config\n" |
2823
cd23279122ed
[gaim-migrate @ 2836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2662
diff
changeset
|
662 " -d, --debug print debugging messages to stdout\n" |
3474 | 663 " -v, --version display the current version and exit\n" |
664 " -h, --help display this help and exit\n", VERSION, name); | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
665 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
666 case 1: /* short message */ |
3474 | 667 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
|
668 break; |
1009
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
669 } |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
670 } |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
671 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
672 GSList *message_split(char *message, int limit) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
673 { |
1100
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
674 static GSList *ret = NULL; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
675 int lastgood = 0, curgood = 0, curpos = 0, len = strlen(message); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
676 gboolean intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
677 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
678 if (ret) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
679 GSList *tmp = ret; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
680 while (tmp) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
681 g_free(tmp->data); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
682 tmp = g_slist_remove(tmp, tmp->data); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
683 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
684 ret = NULL; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
685 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
686 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
687 while (TRUE) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
688 if (lastgood >= len) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
689 return ret; |
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 if (len - lastgood < limit) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
692 ret = g_slist_append(ret, g_strdup(&message[lastgood])); |
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 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
695 |
1100
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
696 curgood = curpos = 0; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
697 intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
698 while (curpos <= limit) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
699 if (isspace(message[curpos + lastgood]) && !intag) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
700 curgood = curpos; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
701 if (message[curpos + lastgood] == '<') |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
702 intag = TRUE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
703 if (message[curpos + lastgood] == '>') |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
704 intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
705 curpos++; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
706 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
707 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
708 if (curgood) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
709 ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood)); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
710 if (isspace(message[curgood + lastgood])) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
711 lastgood += curgood + 1; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
712 else |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
713 lastgood += curgood; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
714 } else { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
715 /* whoops, guess we have to fudge it here */ |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
716 ret = g_slist_append(ret, g_strndup(&message[lastgood], limit)); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
717 lastgood += limit; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
718 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
719 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
720 } |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
721 |
3867 | 722 const gchar *gaim_home_dir() |
3630 | 723 { |
724 if(g_get_home_dir()) | |
725 return g_get_home_dir(); | |
726 else | |
727 #ifndef _WIN32 | |
728 return NULL; | |
729 #else | |
730 /* Win9x and WinME don't have a home dir */ | |
731 return "C:"; | |
732 #endif | |
733 | |
734 } | |
735 | |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
736 /* returns a string of the form ~/.gaim, where ~ is replaced by the user's home |
3630 | 737 * dir. Note that there is no trailing slash after .gaim. */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
738 gchar *gaim_user_dir() |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
739 { |
4160 | 740 const gchar *hd = gaim_home_dir(); |
741 if(hd) { | |
742 strcpy( (char*)&home_dir, hd ); | |
3630 | 743 strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" ); |
744 return (gchar*)&home_dir; | |
745 } | |
746 else { | |
747 return NULL; | |
748 } | |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
749 } |
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
750 |
1292 | 751 /* |
752 * rcg10312000 This could be more robust, but it works for my current | |
753 * goal: to remove those annoying <BR> tags. :) | |
754 * dtf12162000 made the loop more readable. i am a neat freak. ;) */ | |
755 void strncpy_nohtml(gchar *dest, const gchar *src, size_t destsize) | |
756 { | |
757 gchar *ptr; | |
758 g_snprintf(dest, destsize, "%s", src); | |
759 | |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1805
diff
changeset
|
760 while ((ptr = strstr(dest, "<BR>")) != NULL) { |
1292 | 761 /* replace <BR> with a newline. */ |
762 *ptr = '\n'; | |
763 memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1); | |
764 } | |
765 } | |
766 | |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
767 void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize) |
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
768 { |
1202 | 769 gchar *end = dest + destsize; |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
770 |
1293 | 771 while (dest < end) { |
772 if (*src == '\n' && dest < end - 5) { | |
1202 | 773 strcpy(dest, "<BR>"); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
774 src++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
775 dest += 4; |
1293 | 776 } else { |
777 *dest++ = *src; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
778 if (*src == '\0') |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
779 return; |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
780 else |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
781 src++; |
1293 | 782 } |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
783 } |
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
784 } |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
785 |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
786 |
2956 | 787 /* |
788 * Like strncpy_withhtml (above), but malloc()'s the necessary space | |
789 * | |
790 * The caller is responsible for freeing the space pointed to by the | |
791 * return value. | |
792 */ | |
793 | |
794 gchar *strdup_withhtml(const gchar *src) | |
795 { | |
3279 | 796 gchar *sp, *dest; |
2956 | 797 gulong destsize; |
798 | |
4771 | 799 if(!src) |
800 return NULL; | |
801 | |
2956 | 802 /* |
803 * All we need do is multiply the number of newlines by 3 (the | |
804 * additional length of "<BR>" over "\n"), account for the | |
805 * terminator, malloc the space and call strncpy_withhtml. | |
806 */ | |
3279 | 807 for(destsize = 0, sp = (gchar *)src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize) |
2956 | 808 ; |
809 destsize *= 3; | |
810 destsize += strlen(src) + 1; | |
811 dest = g_malloc(destsize); | |
812 strncpy_withhtml(dest, src, destsize); | |
813 | |
814 return(dest); | |
815 } | |
816 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
817 void away_on_login(char *mesg) |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
818 { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
819 GSList *awy = away_messages; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
820 struct away_message *a, *message = NULL; |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
821 struct gaim_gtk_buddy_list *gtkblist; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
822 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4687
diff
changeset
|
823 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
824 |
4687 | 825 if (!gtkblist->window) { |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
826 return; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
827 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
828 |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
829 if (mesg == NULL) { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
830 /* Use default message */ |
2379
cacaf7ace3a5
[gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
831 do_away_message(NULL, default_away); |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
832 } else { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
833 /* Use argument */ |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
834 while (awy) { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
835 a = (struct away_message *)awy->data; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
836 if (strcmp(a->name, mesg) == 0) { |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
837 message = a; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
838 break; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
839 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
840 awy = awy->next; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
841 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
842 if (message == NULL) |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
843 message = default_away; |
2379
cacaf7ace3a5
[gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
844 do_away_message(NULL, message); |
1254
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 return; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
847 } |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
848 |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
849 void strip_linefeed(gchar *text) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
850 { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
851 int i, j; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
852 gchar *text2 = g_malloc(strlen(text) + 1); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
853 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
854 for (i = 0, j = 0; text[i]; i++) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
855 if (text[i] != '\r') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
856 text2[j++] = text[i]; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
857 text2[j] = '\0'; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
858 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
859 strcpy(text, text2); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
860 g_free(text2); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
861 } |
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 char *add_cr(char *text) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
864 { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
865 char *ret = NULL; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
866 int count = 0, i, j; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
867 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
868 if (text[0] == '\n') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
869 count++; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
870 for (i = 1; i < strlen(text); i++) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
871 if (text[i] == '\n' && text[i - 1] != '\r') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
872 count++; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
873 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
874 if (count == 0) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
875 return g_strdup(text); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
876 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
877 ret = g_malloc0(strlen(text) + count + 1); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
878 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
879 i = 0; j = 0; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
880 if (text[i] == '\n') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
881 ret[j++] = '\r'; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
882 ret[j++] = text[i++]; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
883 for (; i < strlen(text); i++) { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
884 if (text[i] == '\n' && text[i - 1] != '\r') |
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 } |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
888 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
889 debug_printf("got: %s, leaving with %s\n", text, ret); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
890 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
891 return ret; |
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 |
1805
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
894 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
|
895 { |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
896 struct tm tm; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
897 |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
898 tm.tm_year = year - 1900; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
899 tm.tm_mon = month - 1; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
900 tm.tm_mday = day; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
901 tm.tm_hour = hour; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
902 tm.tm_min = min; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
903 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
904 return mktime(&tm); |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
905 } |
3230 | 906 |
907 /* | |
908 * Like mkstemp() but returns a file pointer, uses a pre-set template, | |
909 * uses the semantics of tempnam() for the directory to use and allocates | |
910 * the space for the filepath. | |
911 * | |
912 * Caller is responsible for closing the file and removing it when done, | |
913 * as well as freeing the space pointed-to by "path" with g_free(). | |
914 * | |
915 * Returns NULL on failure and cleans up after itself if so. | |
916 */ | |
917 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; | |
918 | |
919 FILE *gaim_mkstemp(gchar **fpath) | |
920 { | |
3466 | 921 const gchar *tmpdir; |
3630 | 922 #ifndef _WIN32 |
3230 | 923 int fd; |
3630 | 924 #endif |
3230 | 925 FILE *fp = NULL; |
926 | |
3630 | 927 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { |
928 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) { | |
929 #ifdef _WIN32 | |
930 char* result = _mktemp( *fpath ); | |
931 if( result == NULL ) | |
932 debug_printf("gaim_mkstemp: Problem creating the template\n"); | |
933 else | |
934 { | |
935 if( (fp = fopen( result, "w+" )) == NULL ) { | |
4160 | 936 debug_printf("Error: Couldn't fopen() in gaim_mkstemp():\n%s\n", result); |
3630 | 937 } |
938 } | |
939 #else | |
3230 | 940 if((fd = mkstemp(*fpath)) == -1) { |
3232 | 941 debug_printf("Error: Couldn't make \"%s\", error: %d\n", *fpath, errno); |
3230 | 942 } else { |
943 if((fp = fdopen(fd, "r+")) == NULL) { | |
944 close(fd); | |
3232 | 945 debug_printf("Error: Couldn't fdopen(), error: %d\n", errno); |
3230 | 946 } |
947 } | |
3630 | 948 #endif |
3230 | 949 if(!fp) { |
950 g_free(*fpath); | |
951 *fpath = NULL; | |
952 } | |
953 } | |
3233 | 954 } else { |
955 debug_printf("Error: g_get_tmp_dir() failed in gaim_mkstemp()!\n"); | |
3230 | 956 } |
957 | |
958 return fp; | |
959 } | |
3478 | 960 |
961 /* AIM URI's ARE FUN :-D */ | |
962 const char *handle_uri(char *uri) { | |
963 GString *str; | |
964 GSList *conn = connections; | |
3867 | 965 struct gaim_connection *gc = NULL; |
3478 | 966 |
967 debug_printf("Handling URI: %s\n", uri); | |
968 | |
969 /* Well, we'd better check to make sure we have at least one | |
970 AIM account connected. */ | |
3867 | 971 while (conn) { |
972 gc = conn->data; | |
4349 | 973 if (gc->protocol == PROTO_OSCAR && isalpha(gc->username[0])) { |
3478 | 974 break; |
975 } | |
976 conn = conn->next; | |
977 } | |
978 | |
979 if (gc == NULL) | |
4160 | 980 return _("Not connected to AIM"); |
3478 | 981 |
3479 | 982 /* aim:goim?screenname=screenname&message=message */ |
983 if (!g_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { | |
3478 | 984 char *who, *what; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
985 struct gaim_conversation *c; |
3479 | 986 uri = uri + strlen("aim:goim?"); |
3478 | 987 |
988 if (!(who = strstr(uri, "screenname="))) { | |
4160 | 989 return _("No screenname given."); |
3478 | 990 } |
991 /* spaces are encoded as +'s */ | |
992 who = who + strlen("screenname="); | |
993 str = g_string_new(NULL); | |
994 while (*who && (*who != '&')) { | |
995 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
996 who++; | |
997 } | |
998 who = g_strdup(str->str); | |
999 g_string_free(str, TRUE); | |
1000 | |
1001 what = strstr(uri, "message="); | |
1002 if (what) { | |
1003 what = what + strlen("message="); | |
1004 str = g_string_new(NULL); | |
1005 while (*what && (*what != '&' || !g_strncasecmp(what, "&", 5))) { | |
1006 g_string_append_c(str, *what == '+' ? ' ' : *what); | |
1007 what++; | |
1008 } | |
1009 what = g_strdup(str->str); | |
1010 g_string_free(str, TRUE); | |
1011 } | |
4491 | 1012 |
1013 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, who); | |
3478 | 1014 g_free(who); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
1015 |
3478 | 1016 if (what) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
1017 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
1018 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
1019 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); |
3478 | 1020 g_free(what); |
1021 } | |
3479 | 1022 } else if (!g_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { |
3478 | 1023 char *who, *group; |
3479 | 1024 uri = uri + strlen("aim:addbuddy?"); |
3478 | 1025 /* spaces are encoded as +'s */ |
4491 | 1026 |
3478 | 1027 if (!(who = strstr(uri, "screenname="))) { |
4160 | 1028 return _("No screenname given."); |
3478 | 1029 } |
1030 who = who + strlen("screenname="); | |
1031 str = g_string_new(NULL); | |
1032 while (*who && (*who != '&')) { | |
1033 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
1034 who++; | |
1035 } | |
1036 who = g_strdup(str->str); | |
1037 g_string_free(str, TRUE); | |
1038 | |
1039 group = strstr(uri, "group="); | |
1040 if (group) { | |
1041 group = group + strlen("group="); | |
1042 str = g_string_new(NULL); | |
1043 while (*group && (*group != '&' || !g_strncasecmp(group, "&", 5))) { | |
1044 g_string_append_c(str, *group == '+' ? ' ' : *group); | |
1045 group++; | |
1046 } | |
1047 group = g_strdup(str->str); | |
1048 g_string_free(str, TRUE); | |
1049 } | |
1050 debug_printf("who: %s\n", who); | |
1051 show_add_buddy(gc, who, group, NULL); | |
1052 g_free(who); | |
1053 if (group) | |
1054 g_free(group); | |
3479 | 1055 } else if (!g_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { |
3478 | 1056 char *room; |
1057 GList *chat=NULL; | |
1058 int exch = 5; | |
1059 | |
3479 | 1060 uri = uri + strlen("aim:gochat?"); |
3478 | 1061 /* spaces are encoded as +'s */ |
1062 | |
1063 if (!(room = strstr(uri, "roomname="))) { | |
4160 | 1064 return _("No roomname given."); |
3478 | 1065 } |
1066 room = room + strlen("roomname="); | |
1067 str = g_string_new(NULL); | |
1068 while (*room && (*room != '&')) { | |
1069 g_string_append_c(str, *room == '+' ? ' ' : *room); | |
1070 room++; | |
1071 } | |
1072 room = g_strdup(str->str); | |
1073 g_string_free(str, TRUE); | |
1074 chat = g_list_append(NULL, room); | |
1075 chat = g_list_append(chat, &exch); | |
1076 serv_join_chat(gc, chat); | |
1077 g_free(room); | |
1078 g_list_free(chat); | |
1079 } else { | |
4160 | 1080 return _("Invalid AIM URI"); |
3478 | 1081 } |
1082 | |
1083 | |
1084 return NULL; | |
1085 } | |
3649 | 1086 |
1087 GtkWidget *gaim_pixmap(char *subdir, char *iconfile) { | |
1088 char *filename; | |
1089 GtkWidget *image; | |
1090 | |
1091 if (subdir != NULL) | |
1092 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL); | |
1093 else | |
1094 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL); | |
1095 | |
1096 debug_printf("Loading: %s\n", filename); | |
1097 | |
1098 image = gtk_image_new_from_file(filename); | |
1099 | |
1100 g_free(filename); | |
1101 | |
1102 return image; | |
1103 } | |
1104 | |
1105 GdkPixbuf *gaim_pixbuf(char *subdir, char *iconfile) { | |
1106 char *filename; | |
1107 GdkPixbuf *pixbuf; | |
1108 GError *err = NULL; | |
1109 | |
1110 if (subdir != NULL) | |
1111 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL); | |
1112 else | |
1113 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL); | |
1114 | |
1115 debug_printf("Loading: %s\n", filename); | |
1116 | |
1117 pixbuf = gdk_pixbuf_new_from_file(filename, &err); | |
1118 if (!pixbuf) { | |
1119 /* FIXME: Maybe we should handle this error */ | |
1120 g_error_free(err); | |
1121 } | |
1122 | |
1123 g_free(filename); | |
1124 | |
1125 return pixbuf; | |
1126 } | |
3668 | 1127 |
1128 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) | |
1129 { | |
1130 GtkWidget *menuitem; | |
3867 | 1131 /* |
3668 | 1132 GtkWidget *hbox; |
1133 GtkWidget *label; | |
3867 | 1134 */ |
3668 | 1135 GtkWidget *image; |
1136 | |
1137 if (icon == NULL) | |
4309 | 1138 menuitem = gtk_menu_item_new_with_mnemonic(str); |
4635 | 1139 else |
4309 | 1140 menuitem = gtk_image_menu_item_new_with_mnemonic(str); |
3668 | 1141 |
1142 if (menu) | |
4635 | 1143 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
3668 | 1144 |
1145 if (sf) | |
4162
d3c8d2b40494
[gaim-migrate @ 4391]
Christian Hammond <chipx86@chipx86.com>
parents:
4160
diff
changeset
|
1146 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); |
3668 | 1147 |
1148 if (icon != NULL) { | |
1149 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU); | |
1150 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
1151 } | |
3867 | 1152 /* FIXME: this isn't right |
3668 | 1153 if (mod) { |
1154 label = gtk_label_new(mod); | |
1155 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1156 gtk_widget_show(label); | |
1157 } | |
3867 | 1158 */ |
3668 | 1159 /* |
1160 if (accel_key) { | |
1161 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1162 accel_mods, GTK_ACCEL_LOCKED); | |
1163 } | |
1164 */ | |
1165 | |
1166 gtk_widget_show_all(menuitem); | |
1167 | |
1168 return menuitem; | |
1169 } | |
1170 | |
1171 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) | |
1172 { | |
1173 GtkWidget *menuitem; | |
3867 | 1174 /* |
3668 | 1175 GtkWidget *hbox; |
1176 GtkWidget *label; | |
3867 | 1177 */ |
3668 | 1178 GtkWidget *image; |
1179 | |
1180 if (iconname == NULL) | |
1181 menuitem = gtk_menu_item_new_with_mnemonic(_(str)); | |
1182 else | |
1183 menuitem = gtk_image_menu_item_new_with_mnemonic(_(str)); | |
1184 | |
1185 if (menu) | |
4635 | 1186 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
3668 | 1187 |
1188 if (sf) | |
4162
d3c8d2b40494
[gaim-migrate @ 4391]
Christian Hammond <chipx86@chipx86.com>
parents:
4160
diff
changeset
|
1189 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); |
3668 | 1190 |
1191 if (iconname != NULL) { | |
1192 char *filename; | |
1193 | |
1194 filename = g_build_filename (DATADIR, "pixmaps", "gaim", "menus", iconname, NULL); | |
1195 debug_printf("Loading: %s\n", filename); | |
1196 image = gtk_image_new_from_file(filename); | |
1197 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
1198 g_free(filename); | |
1199 } | |
3867 | 1200 /* FIXME: this isn't right either |
3668 | 1201 if (mod) { |
1202 label = gtk_label_new(mod); | |
1203 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1204 gtk_widget_show(label); | |
1205 } | |
3867 | 1206 */ |
3668 | 1207 /* |
1208 if (accel_key) { | |
1209 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1210 accel_mods, GTK_ACCEL_LOCKED); | |
1211 } | |
1212 */ | |
1213 | |
1214 gtk_widget_show_all(menuitem); | |
1215 | |
1216 return menuitem; | |
1217 } | |
1218 | |
1219 | |
1220 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) | |
1221 { | |
1222 GtkWidget *menuitem; | |
1223 GtkWidget *hbox; | |
1224 GtkWidget *label; | |
1225 GtkWidget *pixmap; | |
1226 GdkPixmap *pm; | |
1227 GdkBitmap *mask; | |
1228 | |
1229 menuitem = gtk_menu_item_new(); | |
1230 if (menu) | |
4635 | 1231 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
3668 | 1232 if (sf) |
1233 /* 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
|
1234 g_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); |
3668 | 1235 gtk_widget_show(menuitem); |
1236 | |
1237 /* Create our container */ | |
1238 hbox = gtk_hbox_new(FALSE, 2); | |
1239 gtk_container_add(GTK_CONTAINER(menuitem), hbox); | |
1240 gtk_widget_show(hbox); | |
1241 | |
1242 /* Create our pixmap and pack it */ | |
1243 gtk_widget_realize(menu->parent); | |
1244 pm = gdk_pixmap_create_from_xpm_d(menu->parent->window, &mask, NULL, xpm); | |
4635 | 1245 pixmap = gtk_image_new_from_pixmap(pm, mask); |
3668 | 1246 gtk_widget_show(pixmap); |
1247 gdk_pixmap_unref(pm); | |
1248 gdk_bitmap_unref(mask); | |
1249 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 2); | |
1250 | |
1251 /* Create our label and pack it */ | |
1252 label = gtk_label_new(str); | |
1253 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1254 gtk_widget_show(label); | |
1255 | |
1256 if (mod) { | |
1257 label = gtk_label_new(mod); | |
1258 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1259 gtk_widget_show(label); | |
1260 } | |
1261 /* | |
1262 if (accel_key) { | |
1263 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1264 accel_mods, GTK_ACCEL_LOCKED); | |
1265 } | |
1266 */ | |
1267 return menuitem; | |
1268 } | |
1269 | |
3698 | 1270 GtkWidget *gaim_new_item(GtkWidget *menu, const char *str) |
1271 { | |
1272 GtkWidget *menuitem; | |
1273 GtkWidget *label; | |
1274 | |
1275 menuitem = gtk_menu_item_new(); | |
1276 if (menu) | |
4635 | 1277 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
3698 | 1278 gtk_widget_show(menuitem); |
1279 | |
1280 label = gtk_label_new(str); | |
1281 gtk_label_set_pattern(GTK_LABEL(label), "_"); | |
1282 gtk_container_add(GTK_CONTAINER(menuitem), label); | |
1283 gtk_widget_show(label); | |
3699 | 1284 /* FIXME: Go back and fix this |
3698 | 1285 gtk_widget_add_accelerator(menuitem, "activate", accel, str[0], |
1286 GDK_MOD1_MASK, GTK_ACCEL_LOCKED); | |
3699 | 1287 */ |
3698 | 1288 return menuitem; |
1289 } | |
1290 | |
4458 | 1291 char *gaim_try_conv_to_utf8(const char *str) |
1292 { | |
1293 int converted; | |
1294 char *utf8; | |
3698 | 1295 |
4458 | 1296 if (str == NULL) { |
1297 return NULL; | |
1298 } | |
1299 | |
1300 if (g_utf8_validate(str, -1, NULL)) { | |
1301 return g_strdup(str); | |
1302 } | |
3698 | 1303 |
4458 | 1304 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL); |
1305 if (utf8 && converted == strlen (str)) { | |
1306 return(utf8); | |
1307 } else if (utf8) { | |
1308 g_free(utf8); | |
1309 } | |
3698 | 1310 |
4458 | 1311 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL); |
1312 if (utf8 && converted == strlen (str)) { | |
1313 return(utf8); | |
1314 } else if (utf8) { | |
1315 g_free(utf8); | |
1316 } | |
3698 | 1317 |
4458 | 1318 return(NULL); |
1319 } | |
4650 | 1320 |
1321 char *gaim_getip_from_fd(int fd) | |
1322 { | |
1323 struct sockaddr addr; | |
1324 socklen_t namelen = sizeof(addr); | |
1325 | |
1326 if (getsockname(fd, &addr, &namelen)) | |
1327 return NULL; | |
1328 | |
1329 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); | |
1330 } |