Mercurial > pidgin
annotate src/util.c @ 423:0d4e80bdb96b
[gaim-migrate @ 433]
No more --enable-oscar option. From now on, it's a toggle in the preferences.
PLEASE DO NOT USE OSCAR, even though it's very easy to.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Wed, 21 Jun 2000 19:33:58 +0000 |
| parents | 7ea55575cc01 |
| children | 4bf9c74b9e4d |
| 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 |
|
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
278
diff
changeset
|
23 #include "../config.h" |
|
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
278
diff
changeset
|
24 #endif |
| 1 | 25 #include <unistd.h> |
| 26 #include <errno.h> | |
| 27 #include <stdio.h> | |
| 28 #include <stdlib.h> | |
| 29 #include <sys/time.h> | |
| 30 #include <sys/types.h> | |
| 31 #include <sys/stat.h> | |
| 32 #include <string.h> | |
| 33 #include <sys/wait.h> | |
| 34 #include <gtk/gtk.h> | |
|
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
209
diff
changeset
|
35 #include <ctype.h> |
| 1 | 36 #include <pixmaps/aimicon.xpm> |
| 37 #include "gaim.h" | |
| 38 | |
| 39 static GdkPixmap *icon_pm = NULL; | |
| 40 static GdkBitmap *icon_bm = NULL; | |
| 41 static int state; | |
| 42 | |
| 70 | 43 char *full_date() { |
| 44 char * date; | |
| 45 time_t tme; | |
| 46 | |
| 47 time(&tme); | |
| 48 date = ctime(&tme); | |
| 49 date[strlen(date)-1] = '\0'; | |
| 50 return date; | |
| 51 } | |
| 52 | |
| 1 | 53 gint badchar(char c) |
| 54 { | |
| 55 if (c == ' ') | |
| 56 return 1; | |
| 57 if (c == ',') | |
| 58 return 1; | |
| 59 if (c == ')') | |
| 60 return 1; | |
| 61 if (c == '(') | |
| 62 return 1; | |
| 63 if (c == 0) | |
| 64 return 1; | |
| 65 if (c == '\n') | |
| 66 return 1; | |
|
413
7ea55575cc01
[gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
373
diff
changeset
|
67 if (c == '<') |
|
7ea55575cc01
[gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
373
diff
changeset
|
68 return 1; |
| 1 | 69 return 0; |
| 70 | |
| 71 | |
| 72 } | |
| 73 | |
| 74 | |
| 75 char *sec_to_text(int sec) | |
| 76 { | |
| 77 int hrs, min; | |
| 78 char minutes[64]; | |
| 79 char hours[64]; | |
| 80 char sep[16]; | |
| 81 char *ret = g_malloc(256); | |
| 82 | |
| 83 hrs = sec / 3600; | |
| 84 min = sec % 3600; | |
| 85 | |
| 86 min = min / 60; | |
| 87 sec = min % 60; | |
| 88 | |
| 89 if (min) { | |
| 90 if (min == 1) | |
| 91 g_snprintf(minutes, sizeof(minutes), "%d minute.", min); | |
| 92 else | |
| 93 g_snprintf(minutes, sizeof(minutes), "%d minutes.", min); | |
| 94 sprintf(sep, ", "); | |
| 95 } else { | |
| 96 if (!hrs) | |
| 97 g_snprintf(minutes, sizeof(minutes), "%d minutes.", min); | |
| 98 else { | |
| 99 minutes[0] = '.'; | |
| 100 minutes[1] = '\0'; | |
| 101 } | |
| 102 sep[0] = '\0'; | |
| 103 } | |
| 104 | |
| 105 if (hrs) { | |
| 106 if (hrs == 1) | |
| 107 g_snprintf(hours, sizeof(hours), "%d hour%s", hrs, sep); | |
| 108 else | |
| 109 g_snprintf(hours, sizeof(hours), "%d hours%s", hrs, sep); | |
| 110 } else | |
| 111 hours[0] = '\0'; | |
| 112 | |
| 113 | |
| 114 g_snprintf(ret, 256, "%s%s", hours, minutes); | |
| 115 | |
| 116 return ret; | |
| 117 } | |
| 118 | |
| 119 gint linkify_text(char *text) | |
| 120 { | |
| 121 char *c, *t; | |
| 122 char cpy[BUF_LONG]; | |
| 123 char url_buf[512]; | |
| 124 int cnt=0; | |
| 125 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
| 126 | |
| 127 strncpy(cpy, text, strlen(text)); | |
| 128 cpy[strlen(text)] = 0; | |
| 129 c = cpy; | |
| 130 while(*c) { | |
| 131 if (!strncasecmp(c, "<A", 2)) { | |
| 132 while(1) { | |
| 133 if (!strncasecmp(c, "/A>", 3)) { | |
| 134 break; | |
| 135 } | |
| 136 text[cnt++] = *c; | |
| 137 c++; | |
| 138 if (!(*c)) | |
| 139 break; | |
| 140 } | |
| 141 } else if (!strncasecmp(c, "http://", 7)) { | |
| 142 t = c; | |
| 143 while(1) { | |
| 144 if (badchar(*t)) { | |
| 145 if (*(t-1) == '.') | |
| 146 t--; | |
| 147 strncpy(url_buf, c, t-c); | |
| 148 url_buf[t-c] = 0; | |
| 149 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
| 150 cnt--; | |
| 151 c = t; | |
| 152 break; | |
| 153 } | |
| 154 if (!t) | |
| 155 break; | |
| 156 t++; | |
| 157 | |
| 158 } | |
| 159 } else if (!strncasecmp(c, "www.", 4)) { | |
| 160 if (strncasecmp(c, "www..", 5)) { | |
| 161 t = c; | |
| 162 while(1) { | |
| 163 if (badchar(*t)) { | |
| 164 if (t-c == 4) { | |
| 165 break; | |
| 166 } | |
| 167 if (*(t-1) == '.') | |
| 168 t--; | |
| 169 strncpy(url_buf, c, t-c); | |
| 170 url_buf[t-c] = 0; | |
| 171 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"http://%s\">%s</A>", url_buf, url_buf); | |
| 172 cnt--; | |
| 173 c = t; | |
| 174 break; | |
| 175 } | |
| 176 if (!t) | |
| 177 break; | |
| 178 t++; | |
| 179 } | |
| 180 } | |
| 181 } else if (!strncasecmp(c, "ftp://", 6)) { | |
| 182 t = c; | |
| 183 while(1) { | |
| 184 if (badchar(*t)) { | |
| 185 if (*(t-1) == '.') | |
| 186 t--; | |
| 187 strncpy(url_buf, c, t-c); | |
| 188 url_buf[t-c] = 0; | |
| 189 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
| 190 cnt--; | |
| 191 c = t; | |
| 192 break; | |
| 193 } | |
| 194 if (!t) | |
| 195 break; | |
| 196 t++; | |
| 197 | |
| 198 } | |
| 199 } else if (!strncasecmp(c, "ftp.", 4)) { | |
| 200 t = c; | |
| 201 while(1) { | |
| 202 if (badchar(*t)) { | |
| 203 if (t-c == 4) { | |
| 204 break; | |
| 205 } | |
| 206 if (*(t-1) == '.') | |
| 207 t--; | |
| 208 strncpy(url_buf, c, t-c); | |
| 209 url_buf[t-c] = 0; | |
| 210 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"ftp://%s\">%s</A>", url_buf, url_buf); | |
| 211 cnt--; | |
| 212 c = t; | |
| 213 break; | |
| 214 } | |
| 215 if (!t) | |
| 216 break; | |
| 217 t++; | |
| 218 } | |
| 219 } else if (!strncasecmp(c, "mailto:", 7)) { | |
| 220 t = c; | |
| 221 while(1) { | |
| 222 if (badchar(*t)) { | |
| 223 if (*(t-1) == '.') | |
| 224 t--; | |
| 225 strncpy(url_buf, c, t-c); | |
| 226 url_buf[t-c] = 0; | |
| 227 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
| 228 cnt--; | |
| 229 c = t; | |
| 230 break; | |
| 231 } | |
| 232 if (!t) | |
| 233 break; | |
| 234 t++; | |
| 235 | |
| 236 } | |
| 237 } else if (!strncasecmp(c, "@", 1)) { | |
| 238 char *tmp; | |
| 239 int flag; | |
| 240 int len=0; | |
| 241 url_buf[0] = 0; | |
| 242 | |
| 243 if (*(c-1) == ' ' || *(c+1) == ' ') | |
| 244 flag = 0; | |
| 245 else | |
| 246 flag = 1; | |
| 247 | |
| 248 t = c; | |
| 249 while(flag) { | |
| 250 if (badchar(*t)) { | |
| 251 cnt -= (len - 1); | |
| 252 break; | |
| 253 } else { | |
| 254 len++; | |
| 255 tmp = g_malloc(len + 1); | |
| 256 tmp[len] = 0; | |
| 257 tmp[0] = *t; | |
| 258 strncpy(tmp + 1, url_buf, len - 1); | |
| 259 strcpy(url_buf, tmp); | |
| 260 url_buf[len] = 0; | |
| 261 g_free(tmp); | |
| 262 t--; | |
| 263 if (t < cpy) { | |
| 264 cnt = 0; | |
| 265 break; | |
| 266 } | |
| 267 } | |
| 268 } | |
| 269 | |
| 270 | |
| 271 t = c + 1; | |
| 272 | |
| 273 while(flag) { | |
| 274 if (badchar(*t)) { | |
| 275 if (*(t-1) == '.') | |
| 276 t--; | |
| 277 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"mailto:%s\">%s</A>", url_buf, url_buf); | |
| 278 text[cnt]=0; | |
| 279 | |
| 280 | |
| 281 cnt--; | |
| 282 c = t; | |
| 283 | |
| 284 break; | |
| 285 } else { | |
| 286 strncat(url_buf, t, 1); | |
| 287 len++; | |
| 288 url_buf[len] = 0; | |
| 289 } | |
| 290 | |
| 291 t++; | |
| 292 | |
| 293 } | |
| 294 | |
| 295 | |
| 296 } | |
| 297 | |
| 298 if (*c == 0) | |
| 299 break; | |
| 300 | |
| 301 text[cnt++] = *c; | |
| 302 c++; | |
| 303 | |
| 304 } | |
| 305 text[cnt]=0; | |
| 306 return cnt; | |
| 307 } | |
| 308 | |
| 309 | |
|
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
310 FILE *open_log_file (char *name) |
| 1 | 311 { |
| 79 | 312 char *buf; |
| 313 char *buf2; | |
| 1 | 314 char log_all_file[256]; |
| 315 struct log_conversation *l; | |
| 316 struct stat st; | |
| 317 int flag = 0; | |
| 318 FILE *fd; | |
| 319 int res; | |
| 320 | |
| 321 if (!(general_options & OPT_GEN_LOG_ALL)) { | |
| 322 | |
|
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
323 l = find_log_info(name); |
| 1 | 324 if (!l) |
| 325 return NULL; | |
| 326 | |
| 327 if (stat(l->filename, &st) < 0) | |
| 328 flag = 1; | |
| 329 | |
| 330 fd = fopen(l->filename, "a"); | |
| 331 | |
| 332 if (flag) { /* is a new file */ | |
| 333 fprintf(fd, "<HTML><HEAD><TITLE>" ); | |
|
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
334 fprintf(fd, "IM Sessions with %s", name ); |
| 1 | 335 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n" ); |
| 336 } | |
| 337 | |
| 338 return fd; | |
| 339 } | |
| 340 | |
| 79 | 341 buf = g_malloc(BUF_LONG); |
| 342 buf2 = g_malloc(BUF_LONG); | |
| 343 | |
| 1 | 344 /* Dont log yourself */ |
| 345 g_snprintf(log_all_file, 256, "%s/.gaim", getenv("HOME")); | |
| 346 | |
| 347 stat(log_all_file, &st); | |
| 348 if (!S_ISDIR(st.st_mode)) | |
| 349 unlink(log_all_file); | |
| 350 | |
| 351 fd = fopen(log_all_file, "r"); | |
| 352 | |
| 353 if (!fd) { | |
| 354 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 355 if (res < 0) { | |
| 356 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", log_all_file); | |
| 357 do_error_dialog(buf, "Error!"); | |
| 358 g_free(buf); | |
| 359 g_free(buf2); | |
| 360 return NULL; | |
| 361 } | |
| 362 } else | |
| 363 fclose(fd); | |
| 364 | |
| 365 g_snprintf(log_all_file, 256, "%s/.gaim/%s", getenv("HOME"), current_user->username); | |
| 366 | |
| 367 if (stat(log_all_file, &st) < 0) | |
| 368 flag = 1; | |
| 369 if (!S_ISDIR(st.st_mode)) | |
| 370 unlink(log_all_file); | |
| 371 | |
| 372 fd = fopen(log_all_file, "r"); | |
| 373 if (!fd) { | |
| 374 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 375 if (res < 0) { | |
| 376 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", log_all_file); | |
| 377 do_error_dialog(buf, "Error!"); | |
| 378 g_free(buf); | |
| 379 g_free(buf2); | |
| 380 return NULL; | |
| 381 } | |
| 382 } else | |
| 383 fclose(fd); | |
| 384 | |
| 385 | |
|
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
386 g_snprintf(log_all_file, 256, "%s/.gaim/%s/%s.log", getenv("HOME"), current_user->username, normalize(name)); |
| 1 | 387 |
| 388 if (stat(log_all_file, &st) < 0) | |
| 389 flag = 1; | |
| 390 | |
| 391 sprintf(debug_buff,"Logging to: \"%s\"\n", log_all_file); | |
| 392 debug_print(debug_buff); | |
| 393 | |
| 394 fd = fopen(log_all_file, "a"); | |
| 395 | |
| 396 if (flag) { /* is a new file */ | |
| 397 fprintf(fd, "<HTML><HEAD><TITLE>" ); | |
|
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
398 fprintf(fd, "IM Sessions with %s", name ); |
| 1 | 399 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n" ); |
| 400 } | |
| 25 | 401 |
| 402 g_free(buf); | |
| 403 g_free(buf2); | |
| 1 | 404 return fd; |
| 405 } | |
| 406 | |
| 407 | |
|
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
408 /* we only need this for TOC, because messages must be escaped */ |
| 1 | 409 int escape_message(char *msg) |
| 410 { | |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
411 if (!USE_OSCAR) { |
| 1 | 412 char *c, *cpy; |
| 413 int cnt=0; | |
| 414 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
| 415 if (strlen(msg) > BUF_LEN) { | |
| 416 sprintf(debug_buff, "Warning: truncating message to 2048 bytes\n"); | |
| 417 debug_print(debug_buff); | |
| 418 msg[2047]='\0'; | |
| 419 } | |
| 420 | |
| 421 cpy = g_strdup(msg); | |
| 422 c = cpy; | |
| 423 while(*c) { | |
| 424 switch(*c) { | |
| 425 case '$': | |
| 426 case '[': | |
| 427 case ']': | |
| 428 case '(': | |
| 429 case ')': | |
| 430 case '#': | |
| 431 msg[cnt++]='\\'; | |
| 432 /* Fall through */ | |
| 433 default: | |
| 434 msg[cnt++]=*c; | |
| 435 } | |
| 436 c++; | |
| 437 } | |
| 438 msg[cnt]='\0'; | |
| 439 g_free(cpy); | |
| 440 return cnt; | |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
441 } else { |
|
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
442 return strlen(msg); |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
443 } |
| 1 | 444 } |
| 445 | |
|
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
446 /* we don't need this for oscar either */ |
| 1 | 447 int escape_text(char *msg) |
| 448 { | |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
449 if (!USE_OSCAR) { |
| 1 | 450 char *c, *cpy; |
| 451 int cnt=0; | |
| 79 | 452 /* Assumes you have a buffer able to cary at least BUF_LEN * 4 bytes */ |
| 1 | 453 if (strlen(msg) > BUF_LEN) { |
| 454 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
| 455 msg[2047]='\0'; | |
| 456 } | |
| 457 | |
| 458 cpy = g_strdup(msg); | |
| 459 c = cpy; | |
| 460 while(*c) { | |
| 461 switch(*c) { | |
| 462 case '\n': | |
| 463 msg[cnt++] = '<'; | |
| 464 msg[cnt++] = 'B'; | |
| 465 msg[cnt++] = 'R'; | |
| 466 msg[cnt++] = '>'; | |
| 467 break; | |
| 468 case '{': | |
| 469 case '}': | |
| 470 case '\\': | |
| 471 case '"': | |
| 472 msg[cnt++]='\\'; | |
| 473 /* Fall through */ | |
| 474 default: | |
| 475 msg[cnt++]=*c; | |
| 476 } | |
| 477 c++; | |
| 478 } | |
| 479 msg[cnt]='\0'; | |
| 480 g_free(cpy); | |
| 481 return cnt; | |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
482 } else { |
|
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
483 return strlen(msg); |
|
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
484 } |
| 1 | 485 } |
| 486 | |
| 487 char * escape_text2(char *msg) | |
| 488 { | |
| 489 char *c, *cpy; | |
| 490 char *woo; | |
| 491 int cnt=0; | |
| 492 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
| 493 if (strlen(msg) > BUF_LEN) { | |
| 494 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
| 495 msg[2047]='\0'; | |
| 496 } | |
| 497 | |
| 79 | 498 woo = malloc(strlen(msg) * 2); |
| 1 | 499 cpy = g_strdup(msg); |
| 500 c = cpy; | |
| 501 while(*c) { | |
| 502 switch(*c) { | |
| 503 case '\n': | |
| 504 woo[cnt++] = '<'; | |
| 505 woo[cnt++] = 'B'; | |
| 506 woo[cnt++] = 'R'; | |
| 507 woo[cnt++] = '>'; | |
| 508 break; | |
| 509 case '{': | |
| 510 case '}': | |
| 511 case '\\': | |
| 512 case '"': | |
| 513 woo[cnt++]='\\'; | |
| 514 /* Fall through */ | |
| 515 default: | |
| 516 woo[cnt++]=*c; | |
| 517 } | |
| 518 c++; | |
| 519 } | |
| 520 woo[cnt]='\0'; | |
| 26 | 521 |
| 522 g_free (cpy); | |
| 1 | 523 return woo; |
| 524 } | |
| 525 | |
| 526 | |
| 527 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
| 528 "0123456789+/"; | |
| 529 | |
| 530 | |
| 531 char *tobase64(char *text) | |
| 532 { | |
| 533 char *out = NULL; | |
| 534 char *c; | |
| 535 unsigned int tmp = 0; | |
| 536 int len = 0, n = 0; | |
| 537 | |
| 538 c = text; | |
| 539 | |
| 540 while(c) { | |
| 541 tmp = tmp << 8; | |
| 542 tmp += *c; | |
| 543 n++; | |
| 544 | |
| 545 if (n == 3) { | |
| 546 out = g_realloc(out, len+4); | |
| 547 out[len] = alphabet[(tmp >> 18) & 0x3f]; | |
| 548 out[len+1] = alphabet[(tmp >> 12) & 0x3f]; | |
| 549 out[len+2] = alphabet[(tmp >> 6) & 0x3f]; | |
| 550 out[len+3] = alphabet[tmp & 0x3f]; | |
| 551 len += 4; | |
| 552 tmp = 0; | |
| 553 n = 0; | |
| 554 } | |
| 555 c++; | |
| 556 } | |
| 557 switch(n) { | |
| 558 | |
| 559 case 2: | |
| 560 out = g_realloc(out, len+5); | |
| 561 out[len] = alphabet[(tmp >> 12) & 0x3f]; | |
| 562 out[len+1] = alphabet[(tmp >> 6) & 0x3f]; | |
| 563 out[len+2] = alphabet[tmp & 0x3f]; | |
| 564 out[len+3] = '='; | |
| 565 out[len+4] = 0; | |
| 566 break; | |
| 567 case 1: | |
| 568 out = g_realloc(out, len+4); | |
| 569 out[len] = alphabet[(tmp >> 6) & 0x3f]; | |
| 570 out[len+1] = alphabet[tmp & 0x3f]; | |
| 571 out[len+2] = '='; | |
| 572 out[len+3] = 0; | |
| 573 break; | |
| 574 case 0: | |
| 575 out = g_realloc(out, len+2); | |
| 576 out[len] = '='; | |
| 577 out[len+1] = 0; | |
| 578 break; | |
| 579 } | |
| 580 return out; | |
| 581 } | |
| 582 | |
| 583 | |
| 584 char *frombase64(char *text) | |
| 585 { | |
| 586 char *out = NULL; | |
| 587 char tmp = 0; | |
| 588 char *c; | |
| 589 gint32 tmp2 = 0; | |
| 590 int len = 0, n = 0; | |
| 591 | |
| 592 c = text; | |
| 593 | |
| 594 while(*c) { | |
| 595 if (*c >= 'A' && *c <= 'Z') { | |
| 596 tmp = *c - 'A'; | |
| 597 } else if (*c >= 'a' && *c <= 'z') { | |
| 598 tmp = 26 + (*c - 'a'); | |
| 599 } else if (*c >= '0' && *c <= 57) { | |
| 600 tmp = 52 + (*c - '0'); | |
| 601 } else if (*c == '+') { | |
| 602 tmp = 62; | |
| 603 } else if (*c == '/') { | |
| 604 tmp = 63; | |
| 605 } else if (*c == '=') { | |
| 606 if (n == 3) { | |
| 607 out = g_realloc(out, len + 2); | |
| 608 out[len] = (char)(tmp2 >> 10) & 0xff; | |
| 609 len++; | |
| 610 out[len] = (char)(tmp2 >> 2) & 0xff; | |
| 611 len++; | |
| 612 } else if (n == 2) { | |
| 613 out = g_realloc(out, len + 1); | |
| 614 out[len] = (char)(tmp2 >> 4) & 0xff; | |
| 615 len++; | |
| 616 } | |
| 617 break; | |
| 618 } | |
| 619 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); | |
| 620 n++; | |
| 621 if (n == 4) { | |
| 622 out = g_realloc(out, len + 3); | |
| 623 out[len] = (char)((tmp2 >> 16) & 0xff); | |
| 624 len++; | |
| 625 out[len] = (char)((tmp2 >> 8) & 0xff); | |
| 626 len++; | |
| 627 out[len] = (char)(tmp2 & 0xff); | |
| 628 len++; | |
| 629 tmp2 = 0; | |
| 630 n = 0; | |
| 631 } | |
| 632 c++; | |
| 633 } | |
| 634 | |
|
194
d7690984c0f1
[gaim-migrate @ 204]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
635 out = g_realloc(out, len+1); |
| 1 | 636 out[len] = 0; |
| 637 | |
| 638 return out; | |
| 639 } | |
| 640 | |
| 641 | |
| 642 char *normalize(const char *s) | |
| 643 { | |
| 644 static char buf[BUF_LEN]; | |
| 645 char *t, *u; | |
| 646 int x=0; | |
| 647 | |
| 79 | 648 g_return_val_if_fail ((s != NULL), NULL); |
| 26 | 649 |
| 650 u = t = g_strdup(s); | |
| 1 | 651 |
| 652 strcpy(t, s); | |
| 653 g_strdown(t); | |
| 654 | |
| 26 | 655 while(*t && (x < BUF_LEN - 1)) { |
| 1 | 656 if (*t != ' ') { |
| 657 buf[x] = *t; | |
| 658 x++; | |
| 659 } | |
| 660 t++; | |
| 661 } | |
| 662 buf[x]='\0'; | |
| 663 g_free(u); | |
| 664 return buf; | |
| 665 } | |
| 666 | |
| 667 int query_state() | |
| 668 { | |
| 669 return state; | |
| 670 } | |
| 671 | |
| 672 void set_state(int i) | |
| 673 { | |
| 674 state = i; | |
| 675 } | |
| 676 | |
| 677 char *date() | |
| 678 { | |
| 679 static char date[80]; | |
| 680 time_t tme; | |
| 681 time(&tme); | |
| 682 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme)); | |
| 683 return date; | |
| 684 } | |
| 685 | |
| 686 | |
| 687 gint clean_pid(void *dummy) | |
| 688 { | |
| 689 int status; | |
| 690 pid_t pid; | |
| 691 | |
| 692 pid = waitpid(-1, &status, WNOHANG); | |
| 693 | |
| 694 if (pid == 0) | |
| 695 return TRUE; | |
| 696 | |
| 697 return FALSE; | |
| 698 } | |
| 699 | |
| 700 void aol_icon(GdkWindow *w) | |
| 701 { | |
| 702 #ifndef _WIN32 | |
| 703 if (icon_pm == NULL) { | |
| 704 icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm, | |
| 705 NULL, (gchar **)aimicon_xpm); | |
| 706 } | |
| 707 gdk_window_set_icon(w, NULL, icon_pm, icon_bm); | |
| 10 | 708 if (mainwindow) gdk_window_set_group(w, mainwindow->window); |
| 1 | 709 #endif |
| 710 } | |
| 711 | |
| 712 struct aim_user *find_user(const char *name) | |
| 713 { | |
| 714 char *who = g_strdup(normalize(name)); | |
| 715 GList *usr = aim_users; | |
| 716 struct aim_user *u; | |
| 717 | |
| 718 while(usr) { | |
| 719 u = (struct aim_user *)usr->data; | |
| 720 if (!strcmp(normalize(u->username), who)) { | |
| 721 g_free(who); | |
| 722 return u; | |
| 723 } | |
| 724 usr = usr->next; | |
| 725 } | |
| 726 g_free(who); | |
| 727 return NULL; | |
| 728 } | |
| 180 | 729 |
| 730 void check_gaim_versions() | |
| 731 { | |
| 732 char *cur_ver; | |
| 733 char *tmp; | |
| 734 | |
| 735 tmp = (char *)malloc(BUF_LONG); | |
| 736 | |
| 737 cur_ver = (char *)grab_url("http://www.marko.net/gaim/latest-gaim"); | |
| 738 | |
| 739 if (!strncasecmp(cur_ver, "g00", 3)) | |
| 740 { | |
|
278
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
741 g_free(cur_ver); |
|
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
742 g_free(tmp); |
| 180 | 743 return; |
| 744 } | |
| 745 | |
| 746 g_snprintf(tmp, BUF_LONG, "%s", strstr(cur_ver, "plain")+9); | |
| 747 g_strchomp(tmp); | |
| 748 | |
|
278
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
749 if (strcmp(tmp, latest_ver)) |
| 180 | 750 { |
| 751 g_snprintf(cur_ver, BUF_LONG, "GAIM v%s is now available.\n\nDownload it at http://www.marko.net/gaim\n", tmp); | |
| 752 | |
| 753 do_error_dialog(cur_ver, "GAIM - New Version!"); | |
| 754 strcpy(latest_ver, tmp); | |
| 755 save_prefs(); | |
| 756 } | |
| 757 | |
| 758 free(tmp); | |
| 759 free(cur_ver); | |
| 760 } | |
| 761 | |
| 762 | |
| 206 | 763 /* |
| 764 | |
| 765 This function was taken from EveryBuddy and was written by | |
| 766 Torrey Searle. tsearle@valhalla.marko.net | |
| 767 | |
| 768 http://www.everybuddy.com | |
| 769 | |
| 770 */ | |
| 771 | |
| 209 | 772 void spell_checker(GtkWidget * text) |
| 206 | 773 { |
| 774 int start = 0; | |
| 775 int end = 0; | |
| 776 static GdkColor * color = NULL; | |
| 777 int ignore = 0; | |
| 778 int point = gtk_editable_get_position(GTK_EDITABLE(text)); | |
| 779 | |
| 780 GString * string; | |
| 781 | |
| 782 if( color == NULL ) | |
| 783 { | |
| 784 GdkColormap * gc = gtk_widget_get_colormap( text ); | |
| 785 color = g_new0(GdkColor, 1); | |
| 786 color->red = 255 * 256; | |
| 787 gdk_colormap_alloc_color(gc, color, FALSE, TRUE); | |
| 788 } | |
| 789 | |
| 790 | |
| 791 | |
| 792 end = point-1; | |
| 793 for( start = end-1; start >= 0; start-- ) | |
| 794 { | |
| 795 if((isspace(GTK_TEXT_INDEX(GTK_TEXT(text), start)) || start == 0) | |
| 796 && !ignore) | |
| 797 { | |
| 798 char * word; | |
| 799 FILE * file; | |
| 800 char buff[1024]; | |
| 801 word = gtk_editable_get_chars( GTK_EDITABLE(text), start, end ); | |
| 802 g_snprintf(buff, 1024, "echo \"%s\" | ispell -l", word ); | |
| 803 file = popen(buff, "r"); | |
| 804 | |
| 805 buff[0] = 0; | |
| 806 fgets(buff, 255, file); | |
| 807 | |
| 808 if(strlen(buff) > 0 ) | |
| 809 { | |
| 810 string = g_string_new(word); | |
| 811 gtk_text_set_point(GTK_TEXT(text), end); | |
| 812 gtk_text_backward_delete(GTK_TEXT(text), end-start); | |
| 813 gtk_text_insert( GTK_TEXT(text), NULL, color, NULL, | |
| 814 string->str, string->len ); | |
| 815 g_string_free( string, TRUE ); | |
| 816 } | |
| 817 else | |
| 818 { | |
| 819 string = g_string_new(word); | |
| 820 gtk_text_set_point(GTK_TEXT(text), end); | |
| 821 gtk_text_backward_delete(GTK_TEXT(text), end-start); | |
| 822 gtk_text_insert( GTK_TEXT(text), NULL, &(text->style->fg[0]), NULL, | |
| 823 string->str, string->len ); | |
| 824 g_string_free( string, TRUE ); | |
| 825 } | |
| 826 pclose( file); | |
| 827 break; | |
| 828 } | |
| 829 else if(!isalpha(GTK_TEXT_INDEX(GTK_TEXT(text), start))) | |
| 830 { | |
| 831 ignore = 1; | |
| 832 } | |
| 833 } | |
| 834 gtk_text_set_point(GTK_TEXT(text), point); | |
| 835 | |
| 836 } | |
| 837 |
