Mercurial > pidgin
annotate src/util.c @ 3943:a33d6d189591
[gaim-migrate @ 4119]
win32 issue
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 11 Nov 2002 15:22:56 +0000 |
parents | a611ec77d1d2 |
children | fcc6db86f5c7 |
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" |
1 | 48 |
3630 | 49 #ifdef _WIN32 |
50 #include "win32dep.h" | |
51 #endif | |
52 | |
53 #ifndef MAXPATHLEN | |
54 #define MAXPATHLEN 1024 | |
55 #endif | |
56 | |
57 static char home_dir[MAXPATHLEN]; | |
58 | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
59 char *full_date() |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
60 { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
61 char *date; |
70 | 62 time_t tme; |
63 | |
64 time(&tme); | |
65 date = ctime(&tme); | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
66 date[strlen(date) - 1] = '\0'; |
70 | 67 return date; |
68 } | |
69 | |
1 | 70 gint badchar(char c) |
71 { | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
72 switch (c) { |
970 | 73 case ' ': |
74 case ',': | |
75 case '(': | |
76 case ')': | |
77 case '\0': | |
976
2586b2a3725e
[gaim-migrate @ 986]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
970
diff
changeset
|
78 case '\n': |
970 | 79 case '<': |
80 case '>': | |
1706
e6671b80a1f2
[gaim-migrate @ 1716]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1622
diff
changeset
|
81 case '"': |
413
7ea55575cc01
[gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
373
diff
changeset
|
82 return 1; |
970 | 83 default: |
84 return 0; | |
85 } | |
1 | 86 } |
87 | |
88 | |
1376
730a1a19b4cc
[gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1293
diff
changeset
|
89 gchar *sec_to_text(guint sec) |
1 | 90 { |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
91 int daze, hrs, min; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
92 char *ret = g_malloc(256); |
1 | 93 |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
94 daze = sec / (60 * 60 * 24); |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
95 hrs = (sec % (60 * 60 * 24)) / (60 * 60); |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
96 min = (sec % (60 * 60)) / 60; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
97 sec = min % 60; |
1 | 98 |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
99 if (daze) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
100 if (hrs || min) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
101 if (hrs) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
102 if (min) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
103 g_snprintf(ret, 256, |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
104 "%d day%s, %d hour%s, %d minute%s.", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
105 daze, daze == 1 ? "" : "s", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
106 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
107 } else { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
108 g_snprintf(ret, 256, |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
109 "%d day%s, %d hour%s.", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
110 daze, daze == 1 ? "" : "s", hrs, hrs == 1 ? "" : "s"); |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
111 } |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
112 } else { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
113 g_snprintf(ret, 256, |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
114 "%d day%s, %d minute%s.", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
115 daze, daze == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
116 } |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
117 } else |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
118 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
|
119 } else { |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
120 if (hrs) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
121 if (min) { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
122 g_snprintf(ret, 256, |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
123 "%d hour%s, %d minute%s.", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
124 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
125 } else { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
126 g_snprintf(ret, 256, "%d hour%s.", hrs, hrs == 1 ? "" : "s"); |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
127 } |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
128 } else { |
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
129 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
|
130 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
131 } |
1 | 132 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
133 return ret; |
1 | 134 } |
135 | |
136 gint linkify_text(char *text) | |
137 { | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
138 char *c, *t; |
1622
1acef460964a
[gaim-migrate @ 1632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1609
diff
changeset
|
139 char *cpy = g_malloc(strlen(text) * 3 + 1); |
1acef460964a
[gaim-migrate @ 1632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1609
diff
changeset
|
140 char url_buf[BUF_LEN * 4]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
141 int cnt = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
142 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ |
1 | 143 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
144 strncpy(cpy, text, strlen(text)); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
145 cpy[strlen(text)] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
146 c = cpy; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
147 while (*c) { |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
148 if (!g_strncasecmp(c, "<A", 2)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
149 while (1) { |
2596
35c23df11d16
[gaim-migrate @ 2609]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2397
diff
changeset
|
150 if (!g_strncasecmp(c, "/A>", 3)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
151 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
152 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
153 text[cnt++] = *c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
154 c++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
155 if (!(*c)) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
156 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
157 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
158 } else if ((!g_strncasecmp(c, "http://", 7) || (!g_strncasecmp(c, "https://", 8)))) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
159 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
160 while (1) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
161 if (badchar(*t)) { |
925 | 162 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
163 if (*(t) == ',' && (*(t + 1) != ' ')) { |
925 | 164 t++; |
165 continue; | |
166 } | |
167 | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
168 if (*(t - 1) == '.') |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
169 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
170 strncpy(url_buf, c, t - c); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
171 url_buf[t - c] = 0; |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
172 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>", |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
173 url_buf, url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
174 c = t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
175 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
176 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
177 if (!t) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
178 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
179 t++; |
1 | 180 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
181 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
182 } else if (!g_strncasecmp(c, "www.", 4)) { |
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
183 if (g_strncasecmp(c, "www..", 5)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
184 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
185 while (1) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
186 if (badchar(*t)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
187 if (t - c == 4) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
188 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
189 } |
925 | 190 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
191 if (*(t) == ',' && (*(t + 1) != ' ')) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
192 t++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
193 continue; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
194 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
195 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
196 if (*(t - 1) == '.') |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
197 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
198 strncpy(url_buf, c, t - c); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
199 url_buf[t - c] = 0; |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
200 cnt += g_snprintf(&text[cnt], 1024, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
201 "<A HREF=\"http://%s\">%s</A>", url_buf, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
202 url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
203 c = t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
204 break; |
925 | 205 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
206 if (!t) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
207 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
208 t++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
209 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
210 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
211 } else if (!g_strncasecmp(c, "ftp://", 6)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
212 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
213 while (1) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
214 if (badchar(*t)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
215 if (*(t - 1) == '.') |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
216 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
217 strncpy(url_buf, c, t - c); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
218 url_buf[t - c] = 0; |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
219 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>", |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
220 url_buf, url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
221 c = t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
222 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
223 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
224 if (!t) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
225 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
226 t++; |
1 | 227 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
228 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
229 } else if (!g_strncasecmp(c, "ftp.", 4)) { |
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
230 if (g_strncasecmp(c, "ftp..", 5)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
231 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
232 while (1) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
233 if (badchar(*t)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
234 if (t - c == 4) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
235 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
236 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
237 if (*(t - 1) == '.') |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
238 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
239 strncpy(url_buf, c, t - c); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
240 url_buf[t - c] = 0; |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
241 cnt += g_snprintf(&text[cnt], 1024, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
242 "<A HREF=\"ftp://%s\">%s</A>", url_buf, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
243 url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
244 c = t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
245 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
246 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
247 if (!t) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
248 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
249 t++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
250 } |
924 | 251 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
252 } else if (!g_strncasecmp(c, "mailto:", 7)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
253 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
254 while (1) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
255 if (badchar(*t)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
256 if (*(t - 1) == '.') |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
257 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
258 strncpy(url_buf, c, t - c); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
259 url_buf[t - c] = 0; |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
260 cnt += g_snprintf(&text[cnt], 1024, "<A HREF=\"%s\">%s</A>", |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
261 url_buf, url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
262 c = t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
263 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
264 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
265 if (!t) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
266 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
267 t++; |
1 | 268 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
269 } |
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2043
diff
changeset
|
270 } else if (c != cpy && !g_strncasecmp(c, "@", 1)) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
271 char *tmp; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
272 int flag; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
273 int len = 0; |
3330
af52fdf06166
[gaim-migrate @ 3348]
Christian Hammond <chipx86@chipx86.com>
parents:
3279
diff
changeset
|
274 char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\0"; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
275 url_buf[0] = 0; |
1 | 276 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
277 if (*(c - 1) == ' ' || *(c + 1) == ' ' || rindex(illegal_chars, *(c + 1)) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
278 || *(c + 1) == 13 || *(c + 1) == 10) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
279 flag = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
280 else |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
281 flag = 1; |
1 | 282 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
283 t = c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
284 while (flag) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
285 if (badchar(*t)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
286 cnt -= (len - 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
287 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
288 } else { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
289 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
290 tmp = g_malloc(len + 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
291 tmp[len] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
292 tmp[0] = *t; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
293 strncpy(tmp + 1, url_buf, len - 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
294 strcpy(url_buf, tmp); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
295 url_buf[len] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
296 g_free(tmp); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
297 t--; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
298 if (t < cpy) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
299 cnt = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
300 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
301 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
302 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
303 } |
1 | 304 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
305 t = c + 1; |
1 | 306 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
307 while (flag) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
308 if (badchar(*t)) { |
3331
8f69ff64f0bf
[gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents:
3330
diff
changeset
|
309 char *d; |
8f69ff64f0bf
[gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents:
3330
diff
changeset
|
310 |
8f69ff64f0bf
[gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents:
3330
diff
changeset
|
311 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--) |
8f69ff64f0bf
[gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents:
3330
diff
changeset
|
312 *d = '\0'; |
3330
af52fdf06166
[gaim-migrate @ 3348]
Christian Hammond <chipx86@chipx86.com>
parents:
3279
diff
changeset
|
313 |
2614
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
314 cnt += g_snprintf(&text[cnt], 1024, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
315 "<A HREF=\"mailto:%s\">%s</A>", url_buf, |
3e2f455cb924
[gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
316 url_buf); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
317 text[cnt] = 0; |
1 | 318 |
319 | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
320 c = t; |
1 | 321 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
322 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
323 } else { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
324 strncat(url_buf, t, 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
325 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
326 url_buf[len] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
327 } |
1 | 328 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
329 t++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
330 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
331 } |
1 | 332 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
333 if (*c == 0) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
334 break; |
1 | 335 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
336 text[cnt++] = *c; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
337 c++; |
1 | 338 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
339 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
340 text[cnt] = 0; |
845
647b110f7a1a
[gaim-migrate @ 855]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
831
diff
changeset
|
341 g_free(cpy); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
342 return cnt; |
1 | 343 } |
344 | |
345 | |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
346 FILE *open_gaim_log_file(char *name, int *flag) |
1 | 347 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
348 char *buf; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
349 char *buf2; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
350 char log_all_file[256]; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
351 struct stat st; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
352 FILE *fd; |
3630 | 353 #ifndef _WIN32 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
354 int res; |
3630 | 355 #endif |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
356 gchar *gaim_dir; |
1 | 357 |
79 | 358 buf = g_malloc(BUF_LONG); |
359 buf2 = g_malloc(BUF_LONG); | |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
360 gaim_dir = gaim_user_dir(); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
361 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
362 /* Dont log yourself */ |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
363 strncpy(log_all_file, gaim_dir, 256); |
1 | 364 |
3630 | 365 #ifndef _WIN32 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
366 stat(log_all_file, &st); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
367 if (!S_ISDIR(st.st_mode)) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
368 unlink(log_all_file); |
1 | 369 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
370 fd = fopen(log_all_file, "r"); |
1 | 371 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
372 if (!fd) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
373 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
374 if (res < 0) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
375 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
376 log_all_file); |
3427 | 377 do_error_dialog(buf, NULL, GAIM_ERROR); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
378 g_free(buf); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
379 g_free(buf2); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
380 return NULL; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
381 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
382 } else |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
383 fclose(fd); |
1 | 384 |
3630 | 385 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); |
1 | 386 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
387 if (stat(log_all_file, &st) < 0) |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
388 *flag = 1; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
389 if (!S_ISDIR(st.st_mode)) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
390 unlink(log_all_file); |
1 | 391 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
392 fd = fopen(log_all_file, "r"); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
393 if (!fd) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
394 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
395 if (res < 0) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
396 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
397 log_all_file); |
3427 | 398 do_error_dialog(buf, NULL, GAIM_ERROR); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
399 g_free(buf); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
400 g_free(buf2); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
401 return NULL; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
402 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
403 } else |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
404 fclose(fd); |
3630 | 405 #else /* _WIN32 */ |
406 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); | |
1 | 407 |
3630 | 408 if( _mkdir(log_all_file) < 0 && errno != EEXIST ) { |
409 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", log_all_file); | |
410 do_error_dialog(buf, NULL, GAIM_ERROR); | |
411 g_free(buf); | |
412 g_free(buf2); | |
413 return NULL; | |
414 } | |
415 #endif | |
1 | 416 |
3630 | 417 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", gaim_dir, name); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
418 if (stat(log_all_file, &st) < 0) |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
419 *flag = 1; |
1 | 420 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
421 debug_printf("Logging to: \"%s\"\n", log_all_file); |
1 | 422 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
423 fd = fopen(log_all_file, "a"); |
1 | 424 |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
425 g_free(buf); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
426 g_free(buf2); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
427 return fd; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
428 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
429 |
3457 | 430 FILE *open_log_file(char *name, int is_chat) |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
431 { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
432 struct stat st; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
433 char realname[256]; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
434 struct log_conversation *l; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
435 FILE *fd; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
436 int flag = 0; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
437 |
3457 | 438 if (((is_chat == 2) && !(logging_options & OPT_LOG_INDIVIDUAL)) |
439 || ((is_chat == 1) && !(logging_options & OPT_LOG_CHATS)) | |
440 || ((is_chat == 0) && !(logging_options & OPT_LOG_CONVOS))) { | |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
441 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
442 l = find_log_info(name); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
443 if (!l) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
444 return NULL; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
445 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
446 if (stat(l->filename, &st) < 0) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
447 flag = 1; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
448 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
449 fd = fopen(l->filename, "a"); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
450 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
451 if (flag) { /* is a new file */ |
1856 | 452 if (logging_options & OPT_LOG_STRIP_HTML) { |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
453 fprintf(fd, "IM Sessions with %s\n", name); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
454 } else { |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
455 fprintf(fd, "<HTML><HEAD><TITLE>"); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
456 fprintf(fd, "IM Sessions with %s", name); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
457 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); |
1856 | 458 } |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
459 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
460 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
461 return fd; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
462 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
463 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
464 g_snprintf(realname, sizeof(realname), "%s.log", normalize(name)); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
465 fd = open_gaim_log_file(realname, &flag); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
466 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
467 if (fd && flag) { /* is a new file */ |
1856 | 468 if (logging_options & OPT_LOG_STRIP_HTML) { |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
469 fprintf(fd, "IM Sessions with %s\n", name); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
470 } else { |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
471 fprintf(fd, "<HTML><HEAD><TITLE>"); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
472 fprintf(fd, "IM Sessions with %s", name); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
473 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); |
1856 | 474 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
475 } |
25 | 476 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
477 return fd; |
1 | 478 } |
479 | |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
480 FILE *open_system_log_file(char *name) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
481 { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
482 int x; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
483 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
484 if (name) |
3457 | 485 return open_log_file(name, 2); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
486 else |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
487 return open_gaim_log_file("system", &x); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
488 } |
1 | 489 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
490 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/"; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
491 |
3147 | 492 /* XXX Find bug */ |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
493 char *tobase64(const char *text) |
1 | 494 { |
495 char *out = NULL; | |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
496 const char *c; |
1 | 497 unsigned int tmp = 0; |
498 int len = 0, n = 0; | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
499 |
1 | 500 c = text; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
501 |
1829
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
502 while (*c) { |
1 | 503 tmp = tmp << 8; |
504 tmp += *c; | |
505 n++; | |
506 | |
507 if (n == 3) { | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
508 out = g_realloc(out, len + 4); |
1 | 509 out[len] = alphabet[(tmp >> 18) & 0x3f]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
510 out[len + 1] = alphabet[(tmp >> 12) & 0x3f]; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
511 out[len + 2] = alphabet[(tmp >> 6) & 0x3f]; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
512 out[len + 3] = alphabet[tmp & 0x3f]; |
1 | 513 len += 4; |
514 tmp = 0; | |
515 n = 0; | |
516 } | |
517 c++; | |
518 } | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
519 switch (n) { |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
520 |
1 | 521 case 2: |
1829
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
522 tmp <<= 8; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
523 out = g_realloc(out, len + 5); |
1829
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
524 out[len] = alphabet[(tmp >> 18) & 0x3f]; |
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
525 out[len + 1] = alphabet[(tmp >> 12) & 0x3f]; |
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
526 out[len + 2] = alphabet[(tmp >> 6) & 0x3f]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
527 out[len + 3] = '='; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
528 out[len + 4] = 0; |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
529 break; |
1 | 530 case 1: |
1829
bdfb37ae28b4
[gaim-migrate @ 1839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1826
diff
changeset
|
531 tmp <<= 16; |
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
532 out = g_realloc(out, len + 5); |
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
533 out[len] = alphabet[(tmp >> 18) & 0x3f]; |
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
534 out[len + 1] = alphabet[(tmp >> 12) & 0x3f]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
535 out[len + 2] = '='; |
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
536 out[len + 3] = '='; |
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
537 out[len + 4] = 0; |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
538 break; |
1 | 539 case 0: |
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
540 out = g_realloc(out, len + 1); |
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1829
diff
changeset
|
541 out[len] = 0; |
1 | 542 break; |
543 } | |
544 return out; | |
545 } | |
546 | |
547 | |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
548 void frombase64(const char *text, char **data, int *size) |
1 | 549 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
550 char *out = NULL; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
551 char tmp = 0; |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
552 const char *c; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
553 gint32 tmp2 = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
554 int len = 0, n = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
555 |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
556 if (!text || !data) |
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
557 return; |
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
558 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
559 c = text; |
1 | 560 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
561 while (*c) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
562 if (*c >= 'A' && *c <= 'Z') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
563 tmp = *c - 'A'; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
564 } else if (*c >= 'a' && *c <= 'z') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
565 tmp = 26 + (*c - 'a'); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
566 } else if (*c >= '0' && *c <= 57) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
567 tmp = 52 + (*c - '0'); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
568 } else if (*c == '+') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
569 tmp = 62; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
570 } else if (*c == '/') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
571 tmp = 63; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
572 } else if (*c == '=') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
573 if (n == 3) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
574 out = g_realloc(out, len + 2); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
575 out[len] = (char)(tmp2 >> 10) & 0xff; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
576 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
577 out[len] = (char)(tmp2 >> 2) & 0xff; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
578 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
579 } else if (n == 2) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
580 out = g_realloc(out, len + 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
581 out[len] = (char)(tmp2 >> 4) & 0xff; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
582 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
583 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
584 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
585 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
586 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
587 n++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
588 if (n == 4) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
589 out = g_realloc(out, len + 3); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
590 out[len] = (char)((tmp2 >> 16) & 0xff); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
591 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
592 out[len] = (char)((tmp2 >> 8) & 0xff); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
593 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
594 out[len] = (char)(tmp2 & 0xff); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
595 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
596 tmp2 = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
597 n = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
598 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
599 c++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
600 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
601 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
602 out = g_realloc(out, len + 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
603 out[len] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
604 |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
605 *data = out; |
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
606 if (size) |
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
607 *size = len; |
1 | 608 } |
609 | |
610 | |
611 char *normalize(const char *s) | |
612 { | |
613 static char buf[BUF_LEN]; | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
614 char *t, *u; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
615 int x = 0; |
1 | 616 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
617 g_return_val_if_fail((s != NULL), NULL); |
26 | 618 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
619 u = t = g_strdup(s); |
1 | 620 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
621 strcpy(t, s); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
622 g_strdown(t); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
623 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
624 while (*t && (x < BUF_LEN - 1)) { |
1 | 625 if (*t != ' ') { |
626 buf[x] = *t; | |
627 x++; | |
628 } | |
629 t++; | |
630 } | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
631 buf[x] = '\0'; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
632 g_free(u); |
1 | 633 return buf; |
634 } | |
635 | |
636 char *date() | |
637 { | |
638 static char date[80]; | |
639 time_t tme; | |
640 time(&tme); | |
641 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme)); | |
642 return date; | |
643 } | |
644 | |
3806 | 645 void clean_pid(void) |
646 { | |
647 #ifndef _WIN32 | |
648 int status; | |
649 pid_t pid; | |
650 | |
3890 | 651 do { |
652 pid = waitpid(-1, &status, WNOHANG); | |
3891 | 653 } while (pid != 0 && pid != (pid_t)-1); |
3890 | 654 if(pid == (pid_t)-1 && errno != ECHILD) { |
3806 | 655 char errmsg[BUFSIZ]; |
656 sprintf(errmsg, "Warning: waitpid() returned %d", pid); | |
657 perror(errmsg); | |
658 } | |
659 #endif | |
660 } | |
661 | |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
662 struct aim_user *find_user(const char *name, int protocol) |
1 | 663 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
664 char *who = g_strdup(normalize(name)); |
2397
520257562955
[gaim-migrate @ 2410]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
665 GSList *usr = aim_users; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
666 struct aim_user *u; |
1 | 667 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
668 while (usr) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
669 u = (struct aim_user *)usr->data; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
670 if (!strcmp(normalize(u->username), who)) { |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
671 if (protocol != -1) { |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
672 if (u->protocol == protocol) { |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
673 g_free(who); |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
674 return u; |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
675 } |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
676 } else { |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
677 g_free(who); |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
678 return u; |
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1009
diff
changeset
|
679 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
680 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
681 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
682 usr = usr->next; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
683 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
684 g_free(who); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
685 return NULL; |
1 | 686 } |
180 | 687 |
206 | 688 |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
689 /* 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
|
690 or time */ |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
691 char *away_subs(char *msg, char *name) |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
692 { |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
693 char *c; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
694 static char cpy[BUF_LONG]; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
695 int cnt = 0; |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
696 time_t t = time(0); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
697 struct tm *tme = localtime(&t); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
698 char tmp[20]; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
699 |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
700 cpy[0] = '\0'; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
701 c = msg; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
702 while (*c) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
703 switch (*c) { |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
704 case '%': |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
705 if (*(c + 1)) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
706 switch (*(c + 1)) { |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
707 case 'n': |
1976 | 708 /* append name */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
709 strcpy(cpy + cnt, name); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
710 cnt += strlen(name); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
711 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
712 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
713 case 'd': |
1976 | 714 /* append date */ |
2161
757e10018950
[gaim-migrate @ 2171]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2155
diff
changeset
|
715 strftime(tmp, 20, "%m/%d/%Y", tme); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
716 strcpy(cpy + cnt, tmp); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
717 cnt += strlen(tmp); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
718 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
719 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
720 case 't': |
1976 | 721 /* append time */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
722 strftime(tmp, 20, "%r", tme); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
723 strcpy(cpy + cnt, tmp); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
724 cnt += strlen(tmp); |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
725 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
726 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
727 default: |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
728 cpy[cnt++] = *c; |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
729 } |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
730 } |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
731 break; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
732 default: |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
733 cpy[cnt++] = *c; |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
734 } |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
735 c++; |
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
736 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
737 cpy[cnt] = '\0'; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
738 return (cpy); |
592
7c75d69a1129
[gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
470
diff
changeset
|
739 } |
603
9b0717b4a490
[gaim-migrate @ 613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
592
diff
changeset
|
740 |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
741 char *stylize(gchar *text, int length) |
764 | 742 { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
743 gchar *buf; |
2016
9a2e3902658c
[gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1985
diff
changeset
|
744 char *tmp = g_malloc(length); |
764 | 745 |
746 buf = g_malloc(length); | |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
747 g_snprintf(buf, length, "%s", text); |
764 | 748 |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
749 if (font_options & OPT_FONT_BOLD) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
750 g_snprintf(tmp, length, "<B>%s</B>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
751 strcpy(buf, tmp); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
752 } |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
753 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
754 if (font_options & OPT_FONT_ITALIC) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
755 g_snprintf(tmp, length, "<I>%s</I>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
756 strcpy(buf, tmp); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
757 } |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
758 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
759 if (font_options & OPT_FONT_UNDERLINE) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
760 g_snprintf(tmp, length, "<U>%s</U>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
761 strcpy(buf, tmp); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
762 } |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
763 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
764 if (font_options & OPT_FONT_STRIKE) { |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
765 g_snprintf(tmp, length, "<S>%s</S>", buf); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
766 strcpy(buf, tmp); |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
767 } |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
768 |
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
769 if (font_options & OPT_FONT_FACE) { |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
770 g_snprintf(tmp, length, "<FONT FACE=\"%s\">%s</FONT>", fontface, buf); |
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
771 strcpy(buf, tmp); |
764 | 772 } |
773 | |
1441
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
774 if (font_options & OPT_FONT_SIZE) { |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
775 g_snprintf(tmp, length, "<FONT SIZE=\"%d\">%s</FONT>", fontsize, buf); |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
776 strcpy(buf, tmp); |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
777 } |
5c67b8794991
[gaim-migrate @ 1451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
778 |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
779 if (font_options & OPT_FONT_FGCOL) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
780 g_snprintf(tmp, length, "<FONT COLOR=\"#%02X%02X%02X\">%s</FONT>", fgcolor.red, |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
781 fgcolor.green, fgcolor.blue, buf); |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
782 strcpy(buf, tmp); |
764 | 783 } |
784 | |
831
97f1ae636ed7
[gaim-migrate @ 841]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
804
diff
changeset
|
785 if (font_options & OPT_FONT_BGCOL) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
786 g_snprintf(tmp, length, "<BODY BGCOLOR=\"#%02X%02X%02X\">%s</BODY>", bgcolor.red, |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
787 bgcolor.green, bgcolor.blue, buf); |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
788 strcpy(buf, tmp); |
764 | 789 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
790 |
2016
9a2e3902658c
[gaim-migrate @ 2026]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1985
diff
changeset
|
791 g_free(tmp); |
765
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
792 return buf; |
bf31bf916f53
[gaim-migrate @ 775]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
764
diff
changeset
|
793 } |
915
378c862a2381
[gaim-migrate @ 925]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
856
diff
changeset
|
794 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
795 void show_usage(int mode, char *name) |
1009
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
796 { |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
797 switch (mode) { |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
798 case 0: /* full help text */ |
3474 | 799 printf("Gaim %s\n" |
800 "Usage: %s [OPTION]...\n\n" | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
801 " -a, --acct display account editor window\n" |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
802 " -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
|
803 " name of away message to use)\n" |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
804 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" |
3726 | 805 " account(s) to use, seperated by commas)\n" |
3530 | 806 " -n, --loginwin don't automatically login; show login window\n" |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
807 " -u, --user=NAME use account NAME\n" |
1560
72235e3fcff6
[gaim-migrate @ 1570]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1525
diff
changeset
|
808 " -f, --file=FILE use FILE as config\n" |
2823
cd23279122ed
[gaim-migrate @ 2836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2662
diff
changeset
|
809 " -d, --debug print debugging messages to stdout\n" |
3474 | 810 " -v, --version display the current version and exit\n" |
811 " -h, --help display this help and exit\n", VERSION, name); | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
812 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
813 case 1: /* short message */ |
3474 | 814 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
|
815 break; |
1009
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
816 } |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
817 } |
d496fe2614a6
[gaim-migrate @ 1019]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
976
diff
changeset
|
818 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
819 GSList *message_split(char *message, int limit) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
820 { |
1100
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
821 static GSList *ret = NULL; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
822 int lastgood = 0, curgood = 0, curpos = 0, len = strlen(message); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
823 gboolean intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
824 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
825 if (ret) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
826 GSList *tmp = ret; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
827 while (tmp) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
828 g_free(tmp->data); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
829 tmp = g_slist_remove(tmp, tmp->data); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
830 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
831 ret = NULL; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
832 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
833 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
834 while (TRUE) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
835 if (lastgood >= len) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
836 return ret; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
837 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
838 if (len - lastgood < limit) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
839 ret = g_slist_append(ret, g_strdup(&message[lastgood])); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
840 return ret; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
841 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
842 |
1100
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
843 curgood = curpos = 0; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
844 intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
845 while (curpos <= limit) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
846 if (isspace(message[curpos + lastgood]) && !intag) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
847 curgood = curpos; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
848 if (message[curpos + lastgood] == '<') |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
849 intag = TRUE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
850 if (message[curpos + lastgood] == '>') |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
851 intag = FALSE; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
852 curpos++; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
853 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
854 |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
855 if (curgood) { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
856 ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood)); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
857 if (isspace(message[curgood + lastgood])) |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
858 lastgood += curgood + 1; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
859 else |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
860 lastgood += curgood; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
861 } else { |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
862 /* whoops, guess we have to fudge it here */ |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
863 ret = g_slist_append(ret, g_strndup(&message[lastgood], limit)); |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
864 lastgood += limit; |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
865 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
866 } |
f168625b63fe
[gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
867 } |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
868 |
3867 | 869 const gchar *gaim_home_dir() |
3630 | 870 { |
871 if(g_get_home_dir()) | |
872 return g_get_home_dir(); | |
873 else | |
874 #ifndef _WIN32 | |
875 return NULL; | |
876 #else | |
877 /* Win9x and WinME don't have a home dir */ | |
878 return "C:"; | |
879 #endif | |
880 | |
881 } | |
882 | |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
883 /* returns a string of the form ~/.gaim, where ~ is replaced by the user's home |
3630 | 884 * dir. Note that there is no trailing slash after .gaim. */ |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
885 gchar *gaim_user_dir() |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
886 { |
3630 | 887 if(gaim_home_dir()) { |
888 strcpy( (char*)&home_dir, gaim_home_dir() ); | |
889 strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" ); | |
890 return (gchar*)&home_dir; | |
891 } | |
892 else { | |
893 return NULL; | |
894 } | |
1238
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
895 } |
78c4f497db2b
[gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1202
diff
changeset
|
896 |
1292 | 897 /* |
898 * rcg10312000 This could be more robust, but it works for my current | |
899 * goal: to remove those annoying <BR> tags. :) | |
900 * dtf12162000 made the loop more readable. i am a neat freak. ;) */ | |
901 void strncpy_nohtml(gchar *dest, const gchar *src, size_t destsize) | |
902 { | |
903 gchar *ptr; | |
904 g_snprintf(dest, destsize, "%s", src); | |
905 | |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1805
diff
changeset
|
906 while ((ptr = strstr(dest, "<BR>")) != NULL) { |
1292 | 907 /* replace <BR> with a newline. */ |
908 *ptr = '\n'; | |
909 memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1); | |
910 } | |
911 } | |
912 | |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
913 void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize) |
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
914 { |
1202 | 915 gchar *end = dest + destsize; |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
916 |
1293 | 917 while (dest < end) { |
918 if (*src == '\n' && dest < end - 5) { | |
1202 | 919 strcpy(dest, "<BR>"); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
920 src++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
921 dest += 4; |
1293 | 922 } else { |
923 *dest++ = *src; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
924 if (*src == '\0') |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
925 return; |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
926 else |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
927 src++; |
1293 | 928 } |
1191
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
929 } |
4fd0d35826fe
[gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
930 } |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
931 |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
932 |
2956 | 933 /* |
934 * Like strncpy_withhtml (above), but malloc()'s the necessary space | |
935 * | |
936 * The caller is responsible for freeing the space pointed to by the | |
937 * return value. | |
938 */ | |
939 | |
940 gchar *strdup_withhtml(const gchar *src) | |
941 { | |
3279 | 942 gchar *sp, *dest; |
2956 | 943 gulong destsize; |
944 | |
945 /* | |
946 * All we need do is multiply the number of newlines by 3 (the | |
947 * additional length of "<BR>" over "\n"), account for the | |
948 * terminator, malloc the space and call strncpy_withhtml. | |
949 */ | |
3279 | 950 for(destsize = 0, sp = (gchar *)src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize) |
2956 | 951 ; |
952 destsize *= 3; | |
953 destsize += strlen(src) + 1; | |
954 dest = g_malloc(destsize); | |
955 strncpy_withhtml(dest, src, destsize); | |
956 | |
957 return(dest); | |
958 } | |
959 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
960 void away_on_login(char *mesg) |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
961 { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
962 GSList *awy = away_messages; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
963 struct away_message *a, *message = NULL; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
964 |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
965 if (!blist) { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
966 return; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
967 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
968 |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
969 if (mesg == NULL) { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
970 /* Use default message */ |
2379
cacaf7ace3a5
[gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
971 do_away_message(NULL, default_away); |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
972 } else { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
973 /* Use argument */ |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
974 while (awy) { |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
975 a = (struct away_message *)awy->data; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
976 if (strcmp(a->name, mesg) == 0) { |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
977 message = a; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
978 break; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
979 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
980 awy = awy->next; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
981 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
982 if (message == NULL) |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
983 message = default_away; |
2379
cacaf7ace3a5
[gaim-migrate @ 2392]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
984 do_away_message(NULL, message); |
1254
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
985 } |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
986 return; |
9da444224f0e
[gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1252
diff
changeset
|
987 } |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
988 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
989 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
990 { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
991 FILE *fd; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
992 char text[256], html[256]; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
993 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
994 if ((logging_options & why) != why) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
995 return; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
996 |
1609
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
997 if (logging_options & OPT_LOG_INDIVIDUAL) { |
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
998 if (why & OPT_LOG_MY_SIGNON) |
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
999 fd = open_system_log_file(gc ? gc->username : NULL); |
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
1000 else |
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
1001 fd = open_system_log_file(who->name); |
b4473be6fcc5
[gaim-migrate @ 1619]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1575
diff
changeset
|
1002 } else |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1003 fd = open_system_log_file(NULL); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1004 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1005 if (!fd) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1006 return; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1007 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1008 if (why & OPT_LOG_MY_SIGNON) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1009 switch (what) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1010 case log_signon: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1011 g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s", |
3572 | 1012 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1013 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1014 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1015 case log_signoff: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1016 g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s", |
3572 | 1017 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1018 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1019 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1020 case log_away: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1021 g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s", |
3572 | 1022 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1023 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1024 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1025 case log_back: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1026 g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s", |
3572 | 1027 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1028 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1029 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1030 case log_idle: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1031 g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s", |
3572 | 1032 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1033 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1034 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1035 case log_unidle: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1036 g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s", |
3572 | 1037 gc->username, gc->prpl->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1038 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1039 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1040 case log_quit: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1041 g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date()); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1042 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1043 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1044 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1045 } else if (strcmp(who->name, who->show)) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1046 switch (what) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1047 case log_signon: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1048 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s", |
3572 | 1049 gc->username, gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1050 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1051 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1052 case log_signoff: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1053 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s", |
3572 | 1054 gc->username, gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1055 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1056 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1057 case log_away: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1058 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s", |
3572 | 1059 gc->username, gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1060 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1061 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1062 case log_back: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1063 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s", |
3572 | 1064 gc->username, gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1065 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1066 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1067 case log_idle: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1068 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s", |
3572 | 1069 gc->username, gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1070 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1071 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1072 case log_unidle: |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
1073 g_snprintf(text, sizeof(text), |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
1074 "%s (%s) reported that %s (%s) returned from idle @ %s", gc->username, |
3572 | 1075 gc->prpl->name, who->show, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1076 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1077 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1078 default: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1079 fclose(fd); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1080 return; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1081 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1082 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1083 } else { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1084 switch (what) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1085 case log_signon: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1086 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s", |
3572 | 1087 gc->username, gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1088 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1089 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1090 case log_signoff: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1091 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s", |
3572 | 1092 gc->username, gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1093 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1094 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1095 case log_away: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1096 g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s", |
3572 | 1097 gc->username, gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1098 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1099 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1100 case log_back: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1101 g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s", |
3572 | 1102 gc->username, gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1103 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1104 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1105 case log_idle: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1106 g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s", |
3572 | 1107 gc->username, gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1108 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1109 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1110 case log_unidle: |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
1111 g_snprintf(text, sizeof(text), |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2371
diff
changeset
|
1112 "%s (%s) reported that %s returned from idle @ %s", gc->username, |
3572 | 1113 gc->prpl->name, who->name, full_date()); |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1114 g_snprintf(html, sizeof(html), "%s", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1115 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1116 default: |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1117 fclose(fd); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1118 return; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1119 break; |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1120 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1121 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1122 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1123 if (logging_options & OPT_LOG_STRIP_HTML) { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1124 fprintf(fd, "---- %s ----\n", text); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1125 } else { |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1126 if (logging_options & OPT_LOG_INDIVIDUAL) |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1127 fprintf(fd, "<HR>%s<BR><HR><BR>\n", html); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1128 else |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1129 fprintf(fd, "%s<BR>\n", html); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1130 } |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1131 |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1132 fclose(fd); |
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
1133 } |
1805
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1134 |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1135 void strip_linefeed(gchar *text) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1136 { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1137 int i, j; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1138 gchar *text2 = g_malloc(strlen(text) + 1); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1139 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1140 for (i = 0, j = 0; text[i]; i++) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1141 if (text[i] != '\r') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1142 text2[j++] = text[i]; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1143 text2[j] = '\0'; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1144 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1145 strcpy(text, text2); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1146 g_free(text2); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1147 } |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1148 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1149 char *add_cr(char *text) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1150 { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1151 char *ret = NULL; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1152 int count = 0, i, j; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1153 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1154 if (text[0] == '\n') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1155 count++; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1156 for (i = 1; i < strlen(text); i++) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1157 if (text[i] == '\n' && text[i - 1] != '\r') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1158 count++; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1159 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1160 if (count == 0) |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1161 return g_strdup(text); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1162 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1163 ret = g_malloc0(strlen(text) + count + 1); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1164 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1165 i = 0; j = 0; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1166 if (text[i] == '\n') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1167 ret[j++] = '\r'; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1168 ret[j++] = text[i++]; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1169 for (; i < strlen(text); i++) { |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1170 if (text[i] == '\n' && text[i - 1] != '\r') |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1171 ret[j++] = '\r'; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1172 ret[j++] = text[i]; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1173 } |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1174 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1175 debug_printf("got: %s, leaving with %s\n", text, ret); |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1176 |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1177 return ret; |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1178 } |
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
1179 |
1805
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1180 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
|
1181 { |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1182 struct tm tm; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1183 |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1184 tm.tm_year = year - 1900; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1185 tm.tm_mon = month - 1; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1186 tm.tm_mday = day; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1187 tm.tm_hour = hour; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1188 tm.tm_min = min; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1189 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1190 return mktime(&tm); |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
1191 } |
3230 | 1192 |
1193 /* | |
1194 * Like mkstemp() but returns a file pointer, uses a pre-set template, | |
1195 * uses the semantics of tempnam() for the directory to use and allocates | |
1196 * the space for the filepath. | |
1197 * | |
1198 * Caller is responsible for closing the file and removing it when done, | |
1199 * as well as freeing the space pointed-to by "path" with g_free(). | |
1200 * | |
1201 * Returns NULL on failure and cleans up after itself if so. | |
1202 */ | |
1203 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; | |
1204 | |
1205 FILE *gaim_mkstemp(gchar **fpath) | |
1206 { | |
3466 | 1207 const gchar *tmpdir; |
3630 | 1208 #ifndef _WIN32 |
3230 | 1209 int fd; |
3630 | 1210 #endif |
3230 | 1211 FILE *fp = NULL; |
1212 | |
3630 | 1213 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { |
1214 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) { | |
1215 #ifdef _WIN32 | |
1216 char* result = _mktemp( *fpath ); | |
1217 if( result == NULL ) | |
1218 debug_printf("gaim_mkstemp: Problem creating the template\n"); | |
1219 else | |
1220 { | |
1221 if( (fp = fopen( result, "w+" )) == NULL ) { | |
1222 debug_printf("Error: Couldn't fopen()in gaim_mkstemp():\n%s\n", result); | |
1223 } | |
1224 } | |
1225 #else | |
3230 | 1226 if((fd = mkstemp(*fpath)) == -1) { |
3232 | 1227 debug_printf("Error: Couldn't make \"%s\", error: %d\n", *fpath, errno); |
3230 | 1228 } else { |
1229 if((fp = fdopen(fd, "r+")) == NULL) { | |
1230 close(fd); | |
3232 | 1231 debug_printf("Error: Couldn't fdopen(), error: %d\n", errno); |
3230 | 1232 } |
1233 } | |
3630 | 1234 #endif |
3230 | 1235 if(!fp) { |
1236 g_free(*fpath); | |
1237 *fpath = NULL; | |
1238 } | |
1239 } | |
3233 | 1240 } else { |
1241 debug_printf("Error: g_get_tmp_dir() failed in gaim_mkstemp()!\n"); | |
3230 | 1242 } |
1243 | |
1244 return fp; | |
1245 } | |
3478 | 1246 |
1247 /* AIM URI's ARE FUN :-D */ | |
1248 const char *handle_uri(char *uri) { | |
1249 GString *str; | |
1250 GSList *conn = connections; | |
3867 | 1251 struct gaim_connection *gc = NULL; |
3478 | 1252 |
1253 debug_printf("Handling URI: %s\n", uri); | |
1254 | |
1255 /* Well, we'd better check to make sure we have at least one | |
1256 AIM account connected. */ | |
3867 | 1257 while (conn) { |
1258 gc = conn->data; | |
3478 | 1259 if (gc->protocol == PROTO_TOC) { |
1260 break; | |
1261 } | |
1262 conn = conn->next; | |
1263 } | |
1264 | |
1265 if (gc == NULL) | |
1266 return "Not connected to AIM"; | |
1267 | |
3479 | 1268 /* aim:goim?screenname=screenname&message=message */ |
1269 if (!g_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { | |
3478 | 1270 char *who, *what; |
1271 struct conversation *c; | |
3479 | 1272 uri = uri + strlen("aim:goim?"); |
3478 | 1273 |
1274 if (!(who = strstr(uri, "screenname="))) { | |
1275 return "No screenname given."; | |
1276 } | |
1277 /* spaces are encoded as +'s */ | |
1278 who = who + strlen("screenname="); | |
1279 str = g_string_new(NULL); | |
1280 while (*who && (*who != '&')) { | |
1281 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
1282 who++; | |
1283 } | |
1284 who = g_strdup(str->str); | |
1285 g_string_free(str, TRUE); | |
1286 | |
1287 what = strstr(uri, "message="); | |
1288 if (what) { | |
1289 what = what + strlen("message="); | |
1290 str = g_string_new(NULL); | |
1291 while (*what && (*what != '&' || !g_strncasecmp(what, "&", 5))) { | |
1292 g_string_append_c(str, *what == '+' ? ' ' : *what); | |
1293 what++; | |
1294 } | |
1295 what = g_strdup(str->str); | |
1296 g_string_free(str, TRUE); | |
1297 } | |
1298 | |
1299 c = new_conversation(who); | |
3530 | 1300 set_convo_gc(c, gc); |
3478 | 1301 g_free(who); |
1302 if (what) { | |
3790 | 1303 gtk_text_buffer_insert_at_cursor(c->entry_buffer, what, -1); |
3478 | 1304 g_free(what); |
1305 } | |
3479 | 1306 } else if (!g_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { |
3478 | 1307 char *who, *group; |
3479 | 1308 uri = uri + strlen("aim:addbuddy?"); |
3478 | 1309 /* spaces are encoded as +'s */ |
1310 | |
1311 if (!(who = strstr(uri, "screenname="))) { | |
1312 return "No screenname given."; | |
1313 } | |
1314 who = who + strlen("screenname="); | |
1315 str = g_string_new(NULL); | |
1316 while (*who && (*who != '&')) { | |
1317 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
1318 who++; | |
1319 } | |
1320 who = g_strdup(str->str); | |
1321 g_string_free(str, TRUE); | |
1322 | |
1323 group = strstr(uri, "group="); | |
1324 if (group) { | |
1325 group = group + strlen("group="); | |
1326 str = g_string_new(NULL); | |
1327 while (*group && (*group != '&' || !g_strncasecmp(group, "&", 5))) { | |
1328 g_string_append_c(str, *group == '+' ? ' ' : *group); | |
1329 group++; | |
1330 } | |
1331 group = g_strdup(str->str); | |
1332 g_string_free(str, TRUE); | |
1333 } | |
1334 debug_printf("who: %s\n", who); | |
1335 show_add_buddy(gc, who, group, NULL); | |
1336 g_free(who); | |
1337 if (group) | |
1338 g_free(group); | |
3479 | 1339 } else if (!g_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { |
3478 | 1340 char *room; |
1341 GList *chat=NULL; | |
1342 int exch = 5; | |
1343 | |
3479 | 1344 uri = uri + strlen("aim:gochat?"); |
3478 | 1345 /* spaces are encoded as +'s */ |
1346 | |
1347 if (!(room = strstr(uri, "roomname="))) { | |
1348 return "No roomname given."; | |
1349 } | |
1350 room = room + strlen("roomname="); | |
1351 str = g_string_new(NULL); | |
1352 while (*room && (*room != '&')) { | |
1353 g_string_append_c(str, *room == '+' ? ' ' : *room); | |
1354 room++; | |
1355 } | |
1356 room = g_strdup(str->str); | |
1357 g_string_free(str, TRUE); | |
1358 chat = g_list_append(NULL, room); | |
1359 chat = g_list_append(chat, &exch); | |
1360 serv_join_chat(gc, chat); | |
1361 g_free(room); | |
1362 g_list_free(chat); | |
1363 } else { | |
1364 return "Invalid AIM URI"; | |
1365 } | |
1366 | |
1367 | |
1368 return NULL; | |
1369 } | |
3649 | 1370 |
1371 GtkWidget *gaim_pixmap(char *subdir, char *iconfile) { | |
1372 char *filename; | |
1373 GtkWidget *image; | |
1374 | |
1375 if (subdir != NULL) | |
1376 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL); | |
1377 else | |
1378 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL); | |
1379 | |
1380 debug_printf("Loading: %s\n", filename); | |
1381 | |
1382 image = gtk_image_new_from_file(filename); | |
1383 | |
1384 g_free(filename); | |
1385 | |
1386 return image; | |
1387 } | |
1388 | |
1389 GdkPixbuf *gaim_pixbuf(char *subdir, char *iconfile) { | |
1390 char *filename; | |
1391 GdkPixbuf *pixbuf; | |
1392 GError *err = NULL; | |
1393 | |
1394 if (subdir != NULL) | |
1395 filename = g_build_filename (DATADIR, "pixmaps", "gaim", subdir, iconfile, NULL); | |
1396 else | |
1397 filename = g_build_filename (DATADIR, "pixmaps", "gaim", iconfile, NULL); | |
1398 | |
1399 debug_printf("Loading: %s\n", filename); | |
1400 | |
1401 pixbuf = gdk_pixbuf_new_from_file(filename, &err); | |
1402 if (!pixbuf) { | |
1403 /* FIXME: Maybe we should handle this error */ | |
1404 g_error_free(err); | |
1405 } | |
1406 | |
1407 g_free(filename); | |
1408 | |
1409 return pixbuf; | |
1410 } | |
3668 | 1411 |
1412 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) | |
1413 { | |
1414 GtkWidget *menuitem; | |
3867 | 1415 /* |
3668 | 1416 GtkWidget *hbox; |
1417 GtkWidget *label; | |
3867 | 1418 */ |
3668 | 1419 GtkWidget *image; |
1420 | |
1421 if (icon == NULL) | |
1422 menuitem = gtk_menu_item_new_with_mnemonic(_(str)); | |
1423 else | |
1424 menuitem = gtk_image_menu_item_new_with_mnemonic(_(str)); | |
1425 | |
1426 if (menu) | |
1427 gtk_menu_append(GTK_MENU(menu), menuitem); | |
1428 | |
1429 if (sf) | |
1430 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); | |
1431 | |
1432 if (icon != NULL) { | |
1433 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU); | |
1434 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
1435 } | |
3867 | 1436 /* FIXME: this isn't right |
3668 | 1437 if (mod) { |
1438 label = gtk_label_new(mod); | |
1439 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1440 gtk_widget_show(label); | |
1441 } | |
3867 | 1442 */ |
3668 | 1443 /* |
1444 if (accel_key) { | |
1445 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1446 accel_mods, GTK_ACCEL_LOCKED); | |
1447 } | |
1448 */ | |
1449 | |
1450 gtk_widget_show_all(menuitem); | |
1451 | |
1452 return menuitem; | |
1453 } | |
1454 | |
1455 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) | |
1456 { | |
1457 GtkWidget *menuitem; | |
3867 | 1458 /* |
3668 | 1459 GtkWidget *hbox; |
1460 GtkWidget *label; | |
3867 | 1461 */ |
3668 | 1462 GtkWidget *image; |
1463 | |
1464 if (iconname == NULL) | |
1465 menuitem = gtk_menu_item_new_with_mnemonic(_(str)); | |
1466 else | |
1467 menuitem = gtk_image_menu_item_new_with_mnemonic(_(str)); | |
1468 | |
1469 if (menu) | |
1470 gtk_menu_append(GTK_MENU(menu), menuitem); | |
1471 | |
1472 if (sf) | |
1473 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); | |
1474 | |
1475 if (iconname != NULL) { | |
1476 char *filename; | |
1477 | |
1478 filename = g_build_filename (DATADIR, "pixmaps", "gaim", "menus", iconname, NULL); | |
1479 debug_printf("Loading: %s\n", filename); | |
1480 image = gtk_image_new_from_file(filename); | |
1481 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
1482 g_free(filename); | |
1483 } | |
3867 | 1484 /* FIXME: this isn't right either |
3668 | 1485 if (mod) { |
1486 label = gtk_label_new(mod); | |
1487 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1488 gtk_widget_show(label); | |
1489 } | |
3867 | 1490 */ |
3668 | 1491 /* |
1492 if (accel_key) { | |
1493 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1494 accel_mods, GTK_ACCEL_LOCKED); | |
1495 } | |
1496 */ | |
1497 | |
1498 gtk_widget_show_all(menuitem); | |
1499 | |
1500 return menuitem; | |
1501 } | |
1502 | |
1503 | |
1504 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) | |
1505 { | |
1506 GtkWidget *menuitem; | |
1507 GtkWidget *hbox; | |
1508 GtkWidget *label; | |
1509 GtkWidget *pixmap; | |
1510 GdkPixmap *pm; | |
1511 GdkBitmap *mask; | |
1512 | |
1513 menuitem = gtk_menu_item_new(); | |
1514 if (menu) | |
1515 gtk_menu_append(GTK_MENU(menu), menuitem); | |
1516 if (sf) | |
1517 /* passing 1 is necessary so if we sign off closing the account editor doesn't exit */ | |
1518 gtk_signal_connect(GTK_OBJECT(menuitem), "activate", sf, data); | |
1519 gtk_widget_show(menuitem); | |
1520 | |
1521 /* Create our container */ | |
1522 hbox = gtk_hbox_new(FALSE, 2); | |
1523 gtk_container_add(GTK_CONTAINER(menuitem), hbox); | |
1524 gtk_widget_show(hbox); | |
1525 | |
1526 /* Create our pixmap and pack it */ | |
1527 gtk_widget_realize(menu->parent); | |
1528 pm = gdk_pixmap_create_from_xpm_d(menu->parent->window, &mask, NULL, xpm); | |
1529 pixmap = gtk_pixmap_new(pm, mask); | |
1530 gtk_widget_show(pixmap); | |
1531 gdk_pixmap_unref(pm); | |
1532 gdk_bitmap_unref(mask); | |
1533 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 2); | |
1534 | |
1535 /* Create our label and pack it */ | |
1536 label = gtk_label_new(str); | |
1537 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1538 gtk_widget_show(label); | |
1539 | |
1540 if (mod) { | |
1541 label = gtk_label_new(mod); | |
1542 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2); | |
1543 gtk_widget_show(label); | |
1544 } | |
1545 /* | |
1546 if (accel_key) { | |
1547 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key, | |
1548 accel_mods, GTK_ACCEL_LOCKED); | |
1549 } | |
1550 */ | |
1551 return menuitem; | |
1552 } | |
1553 | |
3698 | 1554 GtkWidget *gaim_new_item(GtkWidget *menu, const char *str) |
1555 { | |
1556 GtkWidget *menuitem; | |
1557 GtkWidget *label; | |
1558 | |
1559 menuitem = gtk_menu_item_new(); | |
1560 if (menu) | |
1561 gtk_menu_append(GTK_MENU(menu), menuitem); | |
1562 gtk_widget_show(menuitem); | |
1563 | |
1564 label = gtk_label_new(str); | |
1565 gtk_label_set_pattern(GTK_LABEL(label), "_"); | |
1566 gtk_container_add(GTK_CONTAINER(menuitem), label); | |
1567 gtk_widget_show(label); | |
3699 | 1568 /* FIXME: Go back and fix this |
3698 | 1569 gtk_widget_add_accelerator(menuitem, "activate", accel, str[0], |
1570 GDK_MOD1_MASK, GTK_ACCEL_LOCKED); | |
3699 | 1571 */ |
3698 | 1572 return menuitem; |
1573 } | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 |