Skip to content

Commit

Permalink
Fixed bugs for posting and headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon authored and Brandon committed Aug 10, 2015
1 parent 9d3bb33 commit 5699e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions CurlSSL.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ void Curl_SetHeaderCapture(CurlSock* curl_info, bool Enable)

bool Curl_SetHeader(CurlSock* curl_info, const char* Key, const char* Value)
{
if (Key == NULL && Value == NULL)
if ((Key == NULL && Value == NULL) || (!strlen(Key) && !strlen(Value)))
{
curl_slist_free_all(curl_info->hdrs);
curl_info->hdrs = NULL;
return false;
}

char buffer[512];
sprintf(buffer, "%s: %s", Key, Value);
sprintf(buffer, Value ? "%s: %s" : "%s:", Key, Value);
struct curl_slist *tmp = curl_slist_append(curl_info->hdrs, buffer);
if (tmp)
{
Expand Down Expand Up @@ -398,32 +398,30 @@ bool Curl_AddParameter(CurlSock* curl_info, const char *Key, const char *Value,
{
bool result = false;
const char* val = NULL;
CurlMemoryStruct* params = NULL;

if (Key && Value && strlen(Key) && strlen(Value))
{
val = Escape ? curl_easy_escape(curl_info->curl_handle, Value, 0) : Value;

if (curl_info->caller_allocates)
{
if (!curl_info->func_str_len(curl_info->params))
if (curl_info->func_str_len(curl_info->params))
{
result = curl_info->func_write_buffer((void *)"&", 1, 1, curl_info->params);
}
}
else
{
params = (CurlMemoryStruct *)curl_info->params;
Curl_InitMemoryStruct((CurlMemoryStruct **)&curl_info->params);
if (!params->size)
if (((CurlMemoryStruct *)curl_info->params)->size)
{
result = curl_info->func_write_buffer((void *)"&", 1, 1, params);
result = curl_info->func_write_buffer((void *)"&", 1, 1, curl_info->params);
}
}

result = result && curl_info->func_write_buffer((void *)Key, 1, strlen(Key), curl_info->params);
result = result && curl_info->func_write_buffer((void *)"=", 1, 1, curl_info->params);
result = result && curl_info->func_write_buffer((void *)val, 1, strlen(val), curl_info->params);
curl_info->func_write_buffer((void *)Key, 1, strlen(Key), curl_info->params);
curl_info->func_write_buffer((void *)"=", 1, 1, curl_info->params);
curl_info->func_write_buffer((void *)val, 1, strlen(val), curl_info->params);
return result;
}
return result;
Expand Down Expand Up @@ -462,7 +460,7 @@ CurlMemoryStruct* Curl_DoPost(CurlSock* curl_info)

curl_easy_setopt(curl_info->curl_handle, CURLOPT_UPLOAD, 0L);
curl_easy_setopt(curl_info->curl_handle, CURLOPT_POST, 1L);
curl_easy_setopt(curl_info->curl_handle, CURLOPT_POSTFIELDS, curl_info->func_str_len ? curl_info->params : ((CurlMemoryStruct *)curl_info->params)->memory);
curl_easy_setopt(curl_info->curl_handle, CURLOPT_POSTFIELDS, curl_info->func_str_len ? curl_info->params : curl_info->params ? ((CurlMemoryStruct *)curl_info->params)->memory : NULL);
CurlMemoryStruct* res = Curl_Perform(curl_info);
curl_easy_setopt(curl_info->curl_handle, CURLOPT_POST, 0L);
return res;
Expand Down
2 changes: 1 addition & 1 deletion Exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#if __STDC_VERSION__ >= 199901L
#define standard_c_1999
#include <stdbool.h>
#else
#elifndef bool_defined
#define bool_defined
typedef enum {false, true} bool;
#endif
Expand Down

0 comments on commit 5699e81

Please sign in to comment.