libidav/utils.c

changeset 505
481802342fdf
parent 404
5c08b8e14df8
child 512
3320a015a3bc
equal deleted inserted replaced
504:bf3695fee719 505:481802342fdf
385 } 385 }
386 386
387 return url.ptr; 387 return url.ptr;
388 } 388 }
389 389
390 char* util_get_url(DavSession *sn, char *href) { 390 char* util_get_url(DavSession *sn, const char *href) {
391 sstr_t base = sstr(sn->base_url); 391 scstr_t base = scstr(sn->base_url);
392 sstr_t href_str = sstr(href); 392 scstr_t href_str = scstr(href);
393 393
394 char *base_path = util_url_path(sn->base_url); 394 char *base_path = util_url_path(sn->base_url);
395 base.length -= strlen(base_path); 395 base.length -= strlen(base_path);
396 396
397 sstr_t url = sstrcat(2, base, href_str); 397 sstr_t url = sstrcat(2, base, href_str);
398 return url.ptr; 398 return url.ptr;
399 } 399 }
400 400
401 void util_set_url(DavSession *sn, char *href) { 401 void util_set_url(DavSession *sn, const char *href) {
402 char *url = util_get_url(sn, href); 402 char *url = util_get_url(sn, href);
403 curl_easy_setopt(sn->handle, CURLOPT_URL, url); 403 curl_easy_setopt(sn->handle, CURLOPT_URL, url);
404 free(url); 404 free(url);
405 } 405 }
406 406
461 } 461 }
462 return NULL; 462 return NULL;
463 } 463 }
464 464
465 465
466 char* util_base64decode(char *in) { 466 char* util_base64decode(const char *in) {
467 int len = 0; 467 int len = 0;
468 return util_base64decode_len(in, &len); 468 return util_base64decode_len(in, &len);
469 } 469 }
470 470
471 #define WHITESPACE 64 471 #define WHITESPACE 64
482 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66, 482 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
483 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66, 483 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
484 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66, 484 66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
485 66,66,66,66,66,66 485 66,66,66,66,66,66
486 }; 486 };
487 char* util_base64decode_len(char* in, int *outlen) { 487 char* util_base64decode_len(const char* in, int *outlen) {
488 /* code is mostly from wikibooks */ 488 /* code is mostly from wikibooks */
489 489
490 size_t inlen = strlen(in); 490 size_t inlen = strlen(in);
491 size_t bufsize = (inlen*3) / 4; 491 size_t bufsize = (inlen*3) / 4;
492 char *outbuf = malloc(bufsize+1); 492 char *outbuf = malloc(bufsize+1);
493 *outlen = -1; 493 *outlen = -1;
494 494
495 unsigned char *out = (unsigned char*)outbuf; 495 unsigned char *out = (unsigned char*)outbuf;
496 496
497 char *end = in + inlen; 497 const char *end = in + inlen;
498 char iter = 0; 498 char iter = 0;
499 uint32_t buf = 0; 499 uint32_t buf = 0;
500 size_t len = 0; 500 size_t len = 0;
501 501
502 while (in < end) { 502 while (in < end) {
557 return outbuf; 557 return outbuf;
558 } 558 }
559 559
560 560
561 static char* b64enctable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 561 static char* b64enctable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
562 char* util_base64encode(char *in, size_t len) { 562 char* util_base64encode(const char *in, size_t len) {
563 // calculate length of base64 output and create buffer 563 // calculate length of base64 output and create buffer
564 size_t outlen = 4 * ((len + 2) / 3); 564 size_t outlen = 4 * ((len + 2) / 3);
565 int pad = len % 3; 565 int pad = len % 3;
566 566
567 char *out = malloc(outlen + 1); 567 char *out = malloc(outlen + 1);

mercurial