Revision a7c6aa73 libavformat/http.c

View differences:

libavformat/http.c
30 30
#endif
31 31
#include <netdb.h>
32 32

  
33
#include "base64.h"
33 34

  
34 35
/* XXX: POST protocol is not completly implemented because ffmpeg use
35 36
   only a subset of it */
......
51 52
static int http_connect(URLContext *h, const char *path, const char *hoststr,
52 53
                        const char *auth);
53 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 57
/* return non zero if error */
......
189 189
    /* send http header */
190 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 193
    snprintf(s->buffer, sizeof(s->buffer),
194 194
             "%s %s HTTP/1.0\r\n"
195 195
             "User-Agent: %s\r\n"
......
287 287
    NULL, /* seek */
288 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

  

Also available in: Unified diff