mirror of
https://github.com/curl/curl.git
synced 2026-08-25 00:33:31 +03:00
examples: consistent variable naming across examples
- 'CURL *' handles are called 'curl' - 'CURLM *' handles are called 'multi' - write callbacks are called 'write_cb' - read callbacs are called 'read_cb' - CURLcode variables are called 'res' It makes the examples look and feel more consistent. It allows for easier copy and pasting between examples. Closes #19299
This commit is contained in:
parent
0313223853
commit
928363f28c
59 changed files with 715 additions and 725 deletions
|
|
@ -95,8 +95,8 @@ static void endElement(void *userData, const XML_Char *name)
|
|||
printf("%5lu %10lu %s\n", state->depth, state->characters.size, name);
|
||||
}
|
||||
|
||||
static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb,
|
||||
void *userp)
|
||||
static size_t write_cb(void *contents, size_t length, size_t nmemb,
|
||||
void *userp)
|
||||
{
|
||||
XML_Parser parser = (XML_Parser) userp;
|
||||
size_t real_size = length * nmemb;
|
||||
|
|
@ -116,14 +116,14 @@ static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb,
|
|||
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl_handle;
|
||||
CURL *curl;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* Initialize a libcurl handle. */
|
||||
curl_handle = curl_easy_init();
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
XML_Parser parser;
|
||||
struct ParserStruct state;
|
||||
|
|
@ -138,15 +138,15 @@ int main(void)
|
|||
XML_SetElementHandler(parser, startElement, endElement);
|
||||
XML_SetCharacterDataHandler(parser, characterDataHandler);
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL,
|
||||
curl_easy_setopt(curl, CURLOPT_URL,
|
||||
"https://www.w3schools.com/xml/simple.xml");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)parser);
|
||||
|
||||
printf("Depth Characters Closing Tag\n");
|
||||
|
||||
/* Perform the request and any follow-up parsing. */
|
||||
res = curl_easy_perform(curl_handle);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
|
|
@ -168,7 +168,7 @@ int main(void)
|
|||
free(state.characters.memory);
|
||||
XML_ParserFree(parser);
|
||||
|
||||
curl_easy_cleanup(curl_handle);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue