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