Skip to content

Commit fbf2beb

Browse files
authored
Merge pull request #5 from pakrentos/dev
Response codes
2 parents a9d7ab6 + da1707e commit fbf2beb

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ sudo ./install.sh
2626
SELECT send_<post/put/delete>([<URL or IP with port>] as alias0, data1 as alias1, data2 as alias2, ...) FROM ...;
2727
```
2828

29-
Returns 0 per request if request was successfully delivered (but HTTP response code could be 4xx or 5xx)
29+
Returns response code per request if request was somehow delivered
3030
NULL if something went wrong;

src/libmsqlcurl.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@ my_bool send_post_deinit(UDF_INIT *initid, UDF_ARGS *args, char *message)
4343

4444
long long send_post(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
4545
{
46-
CURLcode code = 1;
46+
long long code = 0;
4747
char method[] = "POST";
4848
if (wrapup_request(args, method, &code))
4949
{
5050
*error = 1;
5151
}
52-
if (code)
53-
{
54-
*error = 1;
55-
}
5652
return code;
5753
}
5854

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

6965
long long send_put(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
7066
{
71-
CURLcode code = 1;
67+
long long code = 0;
7268
char method[] = "PUT";
7369
if (wrapup_request(args, method, &code))
7470
{
7571
*error = 1;
7672
}
77-
if (code)
78-
{
79-
*error = 1;
80-
}
8173
return code;
8274
}
8375

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

9486
long long send_delete(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
9587
{
96-
CURLcode code = 1;
88+
long long code = 0;
9789
char method[] = "DELETE";
9890
if (wrapup_request(args, method, &code))
9991
{
10092
*error = 1;
10193
}
102-
if (code)
103-
{
104-
*error = 1;
105-
}
10694
return code;
10795
}
10896

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

216-
int wrapup_request(UDF_ARGS *args, const char *method, CURLcode *code)
204+
int wrapup_request(UDF_ARGS *args, const char *method, long long *response_code)
217205
{
218206
curl_global_init(CURL_GLOBAL_ALL);
219207
CURL *handle = curl_easy_init();
@@ -234,7 +222,11 @@ int wrapup_request(UDF_ARGS *args, const char *method, CURLcode *code)
234222
{
235223
return 1;
236224
}
237-
*code = curl_easy_perform(handle);
225+
if(curl_easy_perform(handle))
226+
{
227+
return 1;
228+
}
229+
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, response_code);
238230
curl_global_cleanup();
239231
return 0;
240232
}

src/libmsqlcurl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ my_bool wrapped_init(UDF_INIT *, UDF_ARGS *, char *);
4848

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

51-
int wrapup_request(UDF_ARGS *, const char *, CURLcode *);
51+
int wrapup_request(UDF_ARGS *, const char *, long long *);
5252

5353
void encapsulate_data(UDF_ARGS *, char **);
5454

0 commit comments

Comments
 (0)