comparison http.c @ 1432:4f4bebc36aad libavformat

switch to common base64 routines in lavf Patch by Ryan Martell % rdm4 A martellventures P com % Original thread: Date: Oct 29, 2006 2:45 AM Subject: Re: [Ffmpeg-devel] [PATCH] Base64 code
author gpoirier
date Sun, 29 Oct 2006 11:53:07 +0000
parents 0899bfe4105c
children 0a990429e524
comparison
equal deleted inserted replaced
1431:2d8a17631520 1432:4f4bebc36aad
28 #else 28 #else
29 # include "barpainet.h" 29 # include "barpainet.h"
30 #endif 30 #endif
31 #include <netdb.h> 31 #include <netdb.h>
32 32
33 #include "base64.h"
33 34
34 /* XXX: POST protocol is not completly implemented because ffmpeg use 35 /* XXX: POST protocol is not completly implemented because ffmpeg use
35 only a subset of it */ 36 only a subset of it */
36 37
37 //#define DEBUG 38 //#define DEBUG
49 } HTTPContext; 50 } HTTPContext;
50 51
51 static int http_connect(URLContext *h, const char *path, const char *hoststr, 52 static int http_connect(URLContext *h, const char *path, const char *hoststr,
52 const char *auth); 53 const char *auth);
53 static int http_write(URLContext *h, uint8_t *buf, int size); 54 static int http_write(URLContext *h, uint8_t *buf, int size);
54 static char *b64_encode(const unsigned char *src );
55 55
56 56
57 /* return non zero if error */ 57 /* return non zero if error */
58 static int http_open(URLContext *h, const char *uri, int flags) 58 static int http_open(URLContext *h, const char *uri, int flags)
59 { 59 {
187 187
188 188
189 /* send http header */ 189 /* send http header */
190 post = h->flags & URL_WRONLY; 190 post = h->flags & URL_WRONLY;
191 191
192 auth_b64 = b64_encode(auth); 192 auth_b64 = av_base64_encode((uint8_t *)auth, strlen(auth));
193 snprintf(s->buffer, sizeof(s->buffer), 193 snprintf(s->buffer, sizeof(s->buffer),
194 "%s %s HTTP/1.0\r\n" 194 "%s %s HTTP/1.0\r\n"
195 "User-Agent: %s\r\n" 195 "User-Agent: %s\r\n"
196 "Accept: */*\r\n" 196 "Accept: */*\r\n"
197 "Host: %s\r\n" 197 "Host: %s\r\n"
285 http_read, 285 http_read,
286 http_write, 286 http_write,
287 NULL, /* seek */ 287 NULL, /* seek */
288 http_close, 288 http_close,
289 }; 289 };
290
291 /*****************************************************************************
292 * b64_encode: stolen from VLC's http.c
293 * simplified by michael
294 *****************************************************************************/
295
296 static char *b64_encode( const unsigned char *src )
297 {
298 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
299 unsigned int len= strlen(src);
300 char *ret, *dst;
301 unsigned i_bits = 0;
302 unsigned i_shift = 0;
303
304 if(len < UINT_MAX/4){
305 ret=dst= av_malloc( len * 4 / 3 + 12 );
306 }else
307 return NULL;
308
309 while(*src){
310 i_bits = (i_bits << 8) + *src++;
311 i_shift += 8;
312
313 do{
314 *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
315 i_shift -= 6;
316 }while( i_shift > 6 || (*src == 0 && i_shift>0));
317 }
318 *dst++ = '=';
319 *dst = '\0';
320
321 return ret;
322 }
323