Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <tag1>
- <tag2>
- <Server>
- <Host>content1</Host>
- <User>content2</User>
- <Pass encoding="base64">content3</Pass>
- </Server>
- <Server>
- <Host>content4</Host>
- <User>content5</User>
- <Pass encoding="base64">content6</Pass>
- </Server>
- <Server>
- <Host>content7</Host>
- <User>content8</User>
- <Pass encoding="base64">content9</Pass>
- </Server>
- </tag2>
- </tag1>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <curl/curl.h>
- #define keyurl "http://www.link.com"
- int getKeyVal(char *key);
- // return data from the server
- struct return_string {
- char *ptr;
- size_t len;
- };
- // utility functions
- size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s);
- void init_string(struct return_string *s);
- /* get the <key> */
- int getKeyVal(char *key)
- {
- CURL *curl;
- CURLcode res;
- char url[128];
- sprintf(url, "%s/k=%s", keyurl, key);
- curl = curl_easy_init();
- if (curl) {
- struct return_string s;
- init_string(&s);
- curl_easy_setopt(curl, CURLOPT_URL, keyurl);
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, accumulate);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
- res = curl_easy_perform(curl);
- printf("result: %sn", s.ptr);
- free(s.ptr);
- curl_easy_cleanup(curl);
- }
- else {
- res = -99;
- }
- return(res);
- }
- /* Initialize the string handler so that it is thread safe */
- void init_string(struct return_string *s)
- {
- s->len = 0;
- s->ptr = malloc(s->len + 1);
- if (s->ptr == NULL) {
- fprintf(stderr, "malloc() failedn");
- exit(-1);
- }
- s->ptr[0] = '