Changeset c88999c


Ignore:
Timestamp:
2005-12-27T15:20:35Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a252c1a
Parents:
e62762b
Message:

Forgot to actually move those functions in previous commit. And *argh*, don't commit things done for debugging!

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

    re62762b rc88999c  
    199199                return FALSE;
    200200        }
    201        
    202         return TRUE;
    203201       
    204202        /* Very naughty, go read the RFCs! >:) */
     
    348346        return( 1 );
    349347}
    350 
    351 /* Decode%20a%20file%20name                                             */
    352 void http_decode( char *s )
    353 {
    354         char *t;
    355         int i, j, k;
    356        
    357         t = g_new( char, strlen( s ) + 1 );
    358        
    359         for( i = j = 0; s[i]; i ++, j ++ )
    360         {
    361                 if( s[i] == '%' )
    362                 {
    363                         if( sscanf( s + i + 1, "%2x", &k ) )
    364                         {
    365                                 t[j] = k;
    366                                 i += 2;
    367                         }
    368                         else
    369                         {
    370                                 *t = 0;
    371                                 break;
    372                         }
    373                 }
    374                 else
    375                 {
    376                         t[j] = s[i];
    377                 }
    378         }
    379         t[j] = 0;
    380        
    381         strcpy( s, t );
    382         g_free( t );
    383 }
    384 
    385 /* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */
    386 /* This fuction is safe, but make sure you call it safely as well! */
    387 void http_encode( char *s )
    388 {
    389         char *t;
    390         int i, j;
    391        
    392         t = g_strdup( s );
    393        
    394         for( i = j = 0; t[i]; i ++, j ++ )
    395         {
    396                 if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' )
    397                 {
    398                         sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] );
    399                         j += 2;
    400                 }
    401                 else
    402                 {
    403                         s[j] = t[i];
    404                 }
    405         }
    406         s[j] = 0;
    407        
    408         g_free( t );
    409 }
    410 
    411 /* Strip newlines from a string. Modifies the string passed to it. */
    412 char *strip_newlines( char *source )
    413 {
    414         int i; 
    415 
    416         for( i = 0; source[i] != '\0'; i ++ )
    417                 if( source[i] == '\n' || source[i] == '\r' )
    418                         source[i] = 32;
    419        
    420         return source;
    421 }
  • util.c

    re62762b rc88999c  
    66
    77/*
    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.
    1110 *
    1211 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
    1312 *                          (and possibly other members of the Gaim team)
    14  * Copyright 2002-2004 Wilmer van der Gaast <lintux@lintux.cx>
     13 * Copyright 2002-2005 Wilmer van der Gaast <wilmer@gaast.net>
    1514 */
    1615
     
    3231*/
    3332
    34 /* Parts from util.c from gaim needed by nogaim */
    3533#define BITLBEE_CORE
    3634#include "nogaim.h"
     
    412410                g_string_sprintfa( str, "%s%s: %s", newline, name, value );
    413411}
     412
     413/* Decode%20a%20file%20name                                             */
     414void 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! */
     449void 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. */
     474char *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.