summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-22 16:31:01 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-22 16:31:01 +0800
commiteab0c675a0375411ccb94d509d1437af109d1ad4 (patch)
treedfd29ad90dbaf859bbe180296c4e76a89112dd21
parent33c38800f850bb673bbe1555e007a2e462e682c7 (diff)
Remove slash prefix, but append it if the url value is not yet
-rw-r--r--client.c8
-rw-r--r--ticket.c4
-rw-r--r--user.c6
3 files changed, 11 insertions, 7 deletions
diff --git a/client.c b/client.c
index f6fdc4a..179825c 100644
--- a/client.c
+++ b/client.c
@@ -1,5 +1,5 @@
-#include <stdlib.h>
#include <stdbool.h>
+#include <stdlib.h>
#include "request.h"
#include "rtclient/client.h"
@@ -17,8 +17,12 @@ bool rtclient_init(const char *url)
#ifdef DEBUG
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
- server_url = malloc(strlen(url) + 1);
+ size_t length = strlen(url);
+ bool append = !(bool)(url[length - 1] == '/');
+ server_url = malloc(length + (size_t)append + 1);
strcpy(server_url, url);
+ if (append)
+ strcat(server_url, "/");
}
return (bool)curl;
diff --git a/ticket.c b/ticket.c
index 7b71bb7..9c5f4f4 100644
--- a/ticket.c
+++ b/ticket.c
@@ -19,7 +19,7 @@ void rtclient_ticket_new(const char *queue
, const char *due
, const char *text)
{
- post("/REST/1.0/ticket/new", (const char *[]){
+ post("REST/1.0/ticket/new", (const char *[]){
"ticket/new", "id"
, queue, "Queue"
, requestor, "Requestor"
@@ -96,7 +96,7 @@ void rtclient_ticket_search(rtclient_ticketlist **listptr, const char *query)
*listptr = malloc(sizeof(rtclient_ticketlist));
(*listptr)->length = 0;
request(search_callback, (void *)listptr, NULL, "%s%s"
- , "/REST/1.0/search/ticket?query=", query);
+ , "REST/1.0/search/ticket?query=", query);
}
void rtclient_ticket_freelist(rtclient_ticketlist *list)
diff --git a/user.c b/user.c
index 38c0178..1792ac7 100644
--- a/user.c
+++ b/user.c
@@ -30,7 +30,7 @@ void rtclient_user_new(const char *name
, bool disabled
, bool privileged)
{
- post("/REST/1.0/user/new", (const char *[]){
+ post("REST/1.0/user/new", (const char *[]){
name, "Name"
, password, "Password"
, emailaddress, "EmailAddress"
@@ -214,14 +214,14 @@ static inline void user_init(rtclient_user **userptr)
void rtclient_user_showid(rtclient_user **userptr, unsigned int id)
{
user_init(userptr);
- request(show_callback, (void *)userptr, NULL, "%s%d", "/REST/1.0/user/"
+ request(show_callback, (void *)userptr, NULL, "%s%d", "REST/1.0/user/"
, id);
}
void rtclient_user_showname(rtclient_user **userptr, const char *name)
{
user_init(userptr);
- request(show_callback, (void *)userptr, NULL, "%s%s", "/REST/1.0/user/"
+ request(show_callback, (void *)userptr, NULL, "%s%s", "REST/1.0/user/"
, name);
}