From e93d85b3c1515950fbb1c8d39f12566df87f1387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Wed, 4 Sep 2019 18:04:11 +0800 Subject: The search function For now it only takes the query parameter, and the library user is responsible for building the query. --- rtclient.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'rtclient.c') diff --git a/rtclient.c b/rtclient.c index 30f2942..7d75946 100644 --- a/rtclient.c +++ b/rtclient.c @@ -21,6 +21,7 @@ bool rtclient_init(const char *url) if (curl) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); + curl_easy_setopt(curl, CURLOPT_REFERER, url); #ifdef DEBUG curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); #endif // DEBUG @@ -62,16 +63,29 @@ void rtclient_login(const char *name, const char *password) #endif // DEBUG } -void rtclient_user(const char *name) +static inline void request(const char *url) { - static const char *user_path = "/REST/1.0/user/"; - char user_url[strlen(server_url) + strlen(user_path) + strlen(name) + 1]; - sprintf(user_url, "%s%s%s", server_url, user_path, name); - curl_easy_setopt(curl, CURLOPT_URL, user_url); + curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_perform(curl); } +void rtclient_user(const char *name) +{ + static const char *path = "/REST/1.0/user/"; + char url[strlen(server_url) + strlen(path) + strlen(name) + 1]; + sprintf(url, "%s%s%s", server_url, path, name); + request(url); +} + +void rtclient_search(const char *query) +{ + static const char *path = "/REST/1.0/search/ticket?query="; + char url[strlen(server_url) + strlen(path) + strlen(query) + 1]; + sprintf(url, "%s%s%s", server_url, path, query); + request(url); +} + void rtclient_cleanup() { if (curl) { -- cgit v1.2.3