Mercurial > libavformat.hg
comparison http.c @ 1180:92fdb5e2a2d7 libavformat
simplify b64_encode()
maybe this should be moved to libavutil ...
| author | michael |
|---|---|
| date | Tue, 18 Jul 2006 18:51:35 +0000 |
| parents | edbe5c3717f9 |
| children | c2f51d81c72e |
comparison
equal
deleted
inserted
replaced
| 1179:6b79be0860e3 | 1180:92fdb5e2a2d7 |
|---|---|
| 283 http_close, | 283 http_close, |
| 284 }; | 284 }; |
| 285 | 285 |
| 286 /***************************************************************************** | 286 /***************************************************************************** |
| 287 * b64_encode: stolen from VLC's http.c | 287 * b64_encode: stolen from VLC's http.c |
| 288 * simplified by michael | |
| 288 *****************************************************************************/ | 289 *****************************************************************************/ |
| 289 | 290 |
| 290 static char *b64_encode( const unsigned char *src ) | 291 static char *b64_encode( const unsigned char *src ) |
| 291 { | 292 { |
| 292 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | 293 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 298 if(len < UINT_MAX/4){ | 299 if(len < UINT_MAX/4){ |
| 299 ret=dst= av_malloc( len * 4 / 3 + 12 ); | 300 ret=dst= av_malloc( len * 4 / 3 + 12 ); |
| 300 }else | 301 }else |
| 301 return NULL; | 302 return NULL; |
| 302 | 303 |
| 303 for( ;; ) | 304 while(*src){ |
| 304 { | 305 i_bits = (i_bits << 8) + *src++; |
| 305 if( *src ) | 306 i_shift += 8; |
| 306 { | 307 |
| 307 i_bits = ( i_bits << 8 )|( *src++ ); | 308 do{ |
| 308 i_shift += 8; | 309 *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; |
| 309 } | |
| 310 else if( i_shift > 0 ) | |
| 311 { | |
| 312 i_bits <<= 6 - i_shift; | |
| 313 i_shift = 6; | |
| 314 } | |
| 315 else | |
| 316 { | |
| 317 *dst++ = '='; | |
| 318 break; | |
| 319 } | |
| 320 | |
| 321 while( i_shift >= 6 ) | |
| 322 { | |
| 323 i_shift -= 6; | 310 i_shift -= 6; |
| 324 *dst++ = b64[(i_bits >> i_shift)&0x3f]; | 311 }while( i_shift > 6 || (*src == 0 && i_shift>0)); |
| 325 } | 312 } |
| 326 } | 313 *dst++ = '='; |
| 327 | 314 *dst = '\0'; |
| 328 *dst++ = '\0'; | |
| 329 | 315 |
| 330 return ret; | 316 return ret; |
| 331 } | 317 } |
| 332 | 318 |
