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