475 |
475 |
476 Proxy* get_https_proxy() { |
476 Proxy* get_https_proxy() { |
477 return https_proxy; |
477 return https_proxy; |
478 } |
478 } |
479 |
479 |
|
480 |
|
481 int add_repository(Repository *repo) { |
|
482 char *file = util_concat_path(ENV_HOME, ".dav/config.xml"); |
|
483 xmlDoc *doc = xmlReadFile(file, NULL, 0); |
|
484 if(!doc) { |
|
485 free(file); |
|
486 fprintf(stderr, "Cannot load config.xml\n"); |
|
487 return 1; |
|
488 } |
|
489 |
|
490 xmlNode *root = xmlDocGetRootElement(doc); |
|
491 |
|
492 xmlNode *repoNode = xmlNewNode(NULL, BAD_CAST "repository"); |
|
493 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t"); |
|
494 xmlNewTextChild(repoNode, NULL, BAD_CAST "name", BAD_CAST repo->name); |
|
495 xmlNodeAddContent(repoNode, BAD_CAST "\n\t\t"); |
|
496 xmlNewTextChild(repoNode, NULL, BAD_CAST "url", BAD_CAST repo->url); |
|
497 xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
|
498 if(repo->user) { |
|
499 xmlNodeAddContent(repoNode, BAD_CAST "\t\t"); |
|
500 xmlNewChild(repoNode, NULL, BAD_CAST "user", BAD_CAST repo->user); |
|
501 xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
|
502 if(repo->password) { |
|
503 char *pwenc = util_base64encode( |
|
504 repo->password, |
|
505 strlen(repo->password)); |
|
506 xmlNodeAddContent(repoNode, BAD_CAST "\t\t"); |
|
507 xmlNewTextChild(repoNode, NULL, BAD_CAST "password", BAD_CAST pwenc); |
|
508 free(pwenc); |
|
509 xmlNodeAddContent(repoNode, BAD_CAST "\n"); |
|
510 } |
|
511 } |
|
512 xmlNodeAddContent(repoNode, BAD_CAST "\t"); |
|
513 |
|
514 xmlNodeAddContent(root, "\n\t"); |
|
515 xmlAddChild(root, repoNode); |
|
516 xmlNodeAddContent(root, BAD_CAST "\n"); |
|
517 |
|
518 int ret = 0; |
|
519 if(xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) == -1) { |
|
520 ret = 1; |
|
521 } |
|
522 xmlFreeDoc(doc); |
|
523 free(file); |
|
524 |
|
525 return ret; |
|
526 } |