Skip to content

Commit

Permalink
Merge pull request #5 from pakrentos/dev
Browse files Browse the repository at this point in the history
Response codes
  • Loading branch information
pakrentos authored May 18, 2020
2 parents a9d7ab6 + da1707e commit fbf2beb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ sudo ./install.sh
SELECT send_<post/put/delete>([<URL or IP with port>] as alias0, data1 as alias1, data2 as alias2, ...) FROM ...;
```

Returns 0 per request if request was successfully delivered (but HTTP response code could be 4xx or 5xx)
Returns response code per request if request was somehow delivered
NULL if something went wrong;
26 changes: 9 additions & 17 deletions src/libmsqlcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ my_bool send_post_deinit(UDF_INIT *initid, UDF_ARGS *args, char *message)

long long send_post(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
CURLcode code = 1;
long long code = 0;
char method[] = "POST";
if (wrapup_request(args, method, &code))
{
*error = 1;
}
if (code)
{
*error = 1;
}
return code;
}

Expand All @@ -68,16 +64,12 @@ my_bool send_put_deinit(UDF_INIT *initid, UDF_ARGS *args, char *message)

long long send_put(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
CURLcode code = 1;
long long code = 0;
char method[] = "PUT";
if (wrapup_request(args, method, &code))
{
*error = 1;
}
if (code)
{
*error = 1;
}
return code;
}

Expand All @@ -93,16 +85,12 @@ my_bool send_delete_deinit(UDF_INIT *initid, UDF_ARGS *args, char *message)

long long send_delete(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
CURLcode code = 1;
long long code = 0;
char method[] = "DELETE";
if (wrapup_request(args, method, &code))
{
*error = 1;
}
if (code)
{
*error = 1;
}
return code;
}

Expand Down Expand Up @@ -213,7 +201,7 @@ void encapsulate_data(UDF_ARGS* udf_args, char** res_str)
(*res_str)[res_len + 2] = '\0';
}

int wrapup_request(UDF_ARGS *args, const char *method, CURLcode *code)
int wrapup_request(UDF_ARGS *args, const char *method, long long *response_code)
{
curl_global_init(CURL_GLOBAL_ALL);
CURL *handle = curl_easy_init();
Expand All @@ -234,7 +222,11 @@ int wrapup_request(UDF_ARGS *args, const char *method, CURLcode *code)
{
return 1;
}
*code = curl_easy_perform(handle);
if(curl_easy_perform(handle))
{
return 1;
}
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, response_code);
curl_global_cleanup();
return 0;
}
2 changes: 1 addition & 1 deletion src/libmsqlcurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ my_bool wrapped_init(UDF_INIT *, UDF_ARGS *, char *);

my_bool wrapped_deinit(UDF_INIT *, UDF_ARGS *, char *);

int wrapup_request(UDF_ARGS *, const char *, CURLcode *);
int wrapup_request(UDF_ARGS *, const char *, long long *);

void encapsulate_data(UDF_ARGS *, char **);

Expand Down

0 comments on commit fbf2beb

Please sign in to comment.