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