Changeset 3473
- Timestamp:
- Oct 20, 2007, 3:17:36 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/metainfo.c
r3430 r3473 56 56 benc_val_t * files, benc_val_t * length ); 57 57 58 /*** 59 **** 60 ***/ 61 62 #define WANTBYTES( want, got ) \ 63 if( (want) > (got) ) { return; } else { (got) -= (want); } 64 static void 65 strlcat_utf8( void * dest, const void * src, size_t len, char skip ) 66 { 67 char * s = dest; 68 const char * append = src; 69 const char * p; 70 71 /* don't overwrite the nul at the end */ 72 len--; 73 74 /* Go to the end of the destination string */ 75 while( s[0] ) 76 { 77 s++; 78 len--; 79 } 80 81 /* Now start appending, converting on the fly if necessary */ 82 for( p = append; p[0]; ) 83 { 84 /* skip over the requested character */ 85 if( skip == p[0] ) 86 { 87 p++; 88 continue; 89 } 90 91 if( !( p[0] & 0x80 ) ) 92 { 93 /* ASCII character */ 94 WANTBYTES( 1, len ); 95 *(s++) = *(p++); 96 continue; 97 } 98 99 if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 ) 100 { 101 /* 2-bytes UTF-8 character */ 102 WANTBYTES( 2, len ); 103 *(s++) = *(p++); *(s++) = *(p++); 104 continue; 105 } 106 107 if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 && 108 ( p[2] & 0xC0 ) == 0x80 ) 109 { 110 /* 3-bytes UTF-8 character */ 111 WANTBYTES( 3, len ); 112 *(s++) = *(p++); *(s++) = *(p++); 113 *(s++) = *(p++); 114 continue; 115 } 116 117 if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 && 118 ( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 ) 119 { 120 /* 4-bytes UTF-8 character */ 121 WANTBYTES( 4, len ); 122 *(s++) = *(p++); *(s++) = *(p++); 123 *(s++) = *(p++); *(s++) = *(p++); 124 continue; 125 } 126 127 /* ISO 8859-1 -> UTF-8 conversion */ 128 WANTBYTES( 2, len ); 129 *(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 ); 130 *(s++) = 0x80 | ( *(p++) & 0x3F ); 131 } 132 } 133 58 134 /*********************************************************************** 59 135 * tr_metainfoParse -
trunk/libtransmission/peer-msgs.c
r3469 r3473 1064 1064 assert( msglen == 0 ); 1065 1065 dbgmsg( msgs, "Got a BT_HAVE_NONE" ); 1066 memset( msgs->info->have->bits, 1, msgs->info->have->len);1066 tr_bitfieldClear( msgs->info->have ); 1067 1067 updatePeerProgress( msgs ); 1068 1068 break; -
trunk/libtransmission/utils.c
r3457 r3473 296 296 ***/ 297 297 298 299 #if 0300 void*301 tr_memmem( const void* haystack, size_t hl,302 const void* needle, size_t nl)303 {304 const char *walk, *end;305 306 if( !nl )307 return (void*) haystack;308 309 if( hl < nl )310 return NULL;311 312 for (walk=(const char*)haystack, end=walk+hl-nl; walk!=end; ++walk)313 if( !memcmp( walk, needle, nl ) )314 return (void*) walk;315 316 return NULL;317 }318 #else319 298 void * tr_memmem ( const void *vbig, size_t big_len, 320 299 const void *vlittle, size_t little_len ) … … 346 325 return NULL; 347 326 } 348 #endif349 327 350 328 /** … … 353 331 354 332 int 355 tr_compareUint 8 ( uint8_t a, uint8_t b )333 tr_compareUint16( uint16_t a, uint16_t b ) 356 334 { 357 335 if( a < b ) return -1; … … 361 339 362 340 int 363 tr_compareUint 16( uint16_t a, uint16_t b )341 tr_compareUint32( uint32_t a, uint32_t b ) 364 342 { 365 343 if( a < b ) return -1; … … 368 346 } 369 347 370 int371 tr_compareUint32( uint32_t a, uint32_t b )372 {373 if( a < b ) return -1;374 if( a > b ) return 1;375 return 0;376 }377 378 int379 tr_compareUint64( uint64_t a, uint64_t b )380 {381 if( a < b ) return -1;382 if( a > b ) return 1;383 return 0;384 }385 386 348 /** 387 349 *** 388 350 **/ 389 390 struct timeval391 timevalSec ( int seconds )392 {393 struct timeval ret;394 ret.tv_sec = seconds;395 ret.tv_usec = 0;396 return ret;397 }398 351 399 352 struct timeval … … 869 822 870 823 tr_bitfield* 871 tr_bitfieldNegate( tr_bitfield * b )872 {873 uint8_t *it;874 const uint8_t *end;875 876 for( it=b->bits, end=it+b->len; it!=end; ++it )877 *it = ~*it;878 879 return b;880 }881 882 tr_bitfield*883 824 tr_bitfieldAnd( tr_bitfield * a, const tr_bitfield * b ) 884 825 { … … 950 891 #endif 951 892 } 952 953 #define WANTBYTES( want, got ) \954 if( (want) > (got) ) { return; } else { (got) -= (want); }955 void956 strlcat_utf8( void * dest, const void * src, size_t len, char skip )957 {958 char * s = dest;959 const char * append = src;960 const char * p;961 962 /* don't overwrite the nul at the end */963 len--;964 965 /* Go to the end of the destination string */966 while( s[0] )967 {968 s++;969 len--;970 }971 972 /* Now start appending, converting on the fly if necessary */973 for( p = append; p[0]; )974 {975 /* skip over the requested character */976 if( skip == p[0] )977 {978 p++;979 continue;980 }981 982 if( !( p[0] & 0x80 ) )983 {984 /* ASCII character */985 WANTBYTES( 1, len );986 *(s++) = *(p++);987 continue;988 }989 990 if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 )991 {992 /* 2-bytes UTF-8 character */993 WANTBYTES( 2, len );994 *(s++) = *(p++); *(s++) = *(p++);995 continue;996 }997 998 if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 &&999 ( p[2] & 0xC0 ) == 0x80 )1000 {1001 /* 3-bytes UTF-8 character */1002 WANTBYTES( 3, len );1003 *(s++) = *(p++); *(s++) = *(p++);1004 *(s++) = *(p++);1005 continue;1006 }1007 1008 if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 &&1009 ( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 )1010 {1011 /* 4-bytes UTF-8 character */1012 WANTBYTES( 4, len );1013 *(s++) = *(p++); *(s++) = *(p++);1014 *(s++) = *(p++); *(s++) = *(p++);1015 continue;1016 }1017 1018 /* ISO 8859-1 -> UTF-8 conversion */1019 WANTBYTES( 2, len );1020 *(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 );1021 *(s++) = 0x80 | ( *(p++) & 0x3F );1022 }1023 }1024 1025 size_t1026 bufsize_utf8( const void * vstr, int * changed )1027 {1028 const char * str = vstr;1029 size_t ii, grow;1030 1031 if( NULL != changed )1032 *changed = 0;1033 1034 ii = 0;1035 grow = 1;1036 while( '\0' != str[ii] )1037 {1038 if( !( str[ii] & 0x80 ) )1039 /* ASCII character */1040 ii++;1041 else if( ( str[ii] & 0xE0 ) == 0xC0 && ( str[ii+1] & 0xC0 ) == 0x80 )1042 /* 2-bytes UTF-8 character */1043 ii += 2;1044 else if( ( str[ii] & 0xF0 ) == 0xE0 && ( str[ii+1] & 0xC0 ) == 0x80 &&1045 ( str[ii+2] & 0xC0 ) == 0x80 )1046 /* 3-bytes UTF-8 character */1047 ii += 3;1048 else if( ( str[ii] & 0xF8 ) == 0xF0 && ( str[ii+1] & 0xC0 ) == 0x80 &&1049 ( str[ii+2] & 0xC0 ) == 0x80 && ( str[ii+3] & 0xC0 ) == 0x80 )1050 /* 4-bytes UTF-8 character */1051 ii += 4;1052 else1053 {1054 /* ISO 8859-1 -> UTF-8 conversion */1055 ii++;1056 grow++;1057 if( NULL != changed )1058 *changed = 1;1059 }1060 }1061 1062 return ii + grow;1063 } -
trunk/libtransmission/utils.h
r3457 r3473 84 84 const char * first_element, ... ); 85 85 86 struct timeval timevalSec( int seconds );87 86 struct timeval timevalMsec( uint64_t milliseconds ); 88 87 … … 97 96 /* wait the specified number of milliseconds */ 98 97 void tr_wait( uint64_t delay_milliseconds ); 99 100 /***********************************************************************101 * strlcat_utf8102 ***********************************************************************103 * According to the official specification, all strings in the torrent104 * file are supposed to be UTF-8 encoded. However, there are105 * non-compliant torrents around... If we encounter an invalid UTF-8106 * character, we assume it is ISO 8859-1 and convert it to UTF-8.107 **********************************************************************/108 void strlcat_utf8( void *, const void *, size_t, char );109 size_t bufsize_utf8( const void *, int * );110 98 111 99 /*** … … 156 144 void * userData ); 157 145 158 int tr_compareUint8 ( uint8_t a, uint8_t b );159 146 int tr_compareUint16( uint16_t a, uint16_t b ); 160 147 int tr_compareUint32( uint32_t a, uint32_t b ); 161 int tr_compareUint64( uint64_t a, uint64_t b );162 148 163 149 /*** … … 188 174 size_t tr_bitfieldCountTrueBits( const tr_bitfield* ); 189 175 190 tr_bitfield* tr_bitfieldNegate( tr_bitfield* );191 176 tr_bitfield* tr_bitfieldAnd( tr_bitfield*, const tr_bitfield* ); 192 177
Note: See TracChangeset
for help on using the changeset viewer.