- Timestamp:
- 2005-12-27T15:20:35Z (18 years ago)
- Branches:
- master
- Children:
- a252c1a
- Parents:
- e62762b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
re62762b rc88999c 6 6 7 7 /* 8 * nogaim 9 * 10 * Gaim without gaim - for BitlBee 8 * Various utility functions. Some are copied from Gaim to support the 9 * IM-modules, most are from BitlBee. 11 10 * 12 11 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> 13 12 * (and possibly other members of the Gaim team) 14 * Copyright 2002-200 4 Wilmer van der Gaast <lintux@lintux.cx>13 * Copyright 2002-2005 Wilmer van der Gaast <wilmer@gaast.net> 15 14 */ 16 15 … … 32 31 */ 33 32 34 /* Parts from util.c from gaim needed by nogaim */35 33 #define BITLBEE_CORE 36 34 #include "nogaim.h" … … 412 410 g_string_sprintfa( str, "%s%s: %s", newline, name, value ); 413 411 } 412 413 /* Decode%20a%20file%20name */ 414 void http_decode( char *s ) 415 { 416 char *t; 417 int i, j, k; 418 419 t = g_new( char, strlen( s ) + 1 ); 420 421 for( i = j = 0; s[i]; i ++, j ++ ) 422 { 423 if( s[i] == '%' ) 424 { 425 if( sscanf( s + i + 1, "%2x", &k ) ) 426 { 427 t[j] = k; 428 i += 2; 429 } 430 else 431 { 432 *t = 0; 433 break; 434 } 435 } 436 else 437 { 438 t[j] = s[i]; 439 } 440 } 441 t[j] = 0; 442 443 strcpy( s, t ); 444 g_free( t ); 445 } 446 447 /* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */ 448 /* This fuction is safe, but make sure you call it safely as well! */ 449 void http_encode( char *s ) 450 { 451 char *t; 452 int i, j; 453 454 t = g_strdup( s ); 455 456 for( i = j = 0; t[i]; i ++, j ++ ) 457 { 458 if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' ) 459 { 460 sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] ); 461 j += 2; 462 } 463 else 464 { 465 s[j] = t[i]; 466 } 467 } 468 s[j] = 0; 469 470 g_free( t ); 471 } 472 473 /* Strip newlines from a string. Modifies the string passed to it. */ 474 char *strip_newlines( char *source ) 475 { 476 int i; 477 478 for( i = 0; source[i] != '\0'; i ++ ) 479 if( source[i] == '\n' || source[i] == '\r' ) 480 source[i] = ' '; 481 482 return source; 483 }
Note: See TracChangeset
for help on using the changeset viewer.