From 777246ed4d138c7919d0dcc47dd3c1a893cd2fba 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: Sat, 14 Sep 2019 09:21:48 +0800 Subject: Rename test file and binary --- .gitignore | 2 +- Makefile.am | 8 ++++---- main.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.c | 64 ------------------------------------------------------------- 4 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 main.c delete mode 100644 test.c diff --git a/.gitignore b/.gitignore index b8cc4af..20500ec 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ configure depcomp install-sh missing +rtclienttest stamp-h1 -test diff --git a/Makefile.am b/Makefile.am index 27ceecd..b4caab6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,7 @@ librtclient_a_SOURCES = \ rtclient/rtclient.h \ rtclient.c -bin_PROGRAMS = test -test_SOURCES = test.c -test_LDADD = librtclient.a -test_LDFLAGS = -lcurl +bin_PROGRAMS = rtclienttest +rtclienttest_SOURCES = main.c +rtclienttest_LDADD = librtclient.a +rtclienttest_LDFLAGS = -lcurl diff --git a/main.c b/main.c new file mode 100644 index 0000000..6dd385c --- /dev/null +++ b/main.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include "rtclient/rtclient.h" + +int main(void) +{ + char *url_line = NULL, *name_line = NULL, *pass_line = NULL; + printf("URL: "); + ssize_t url_nread = getline(&url_line, &(size_t){0}, stdin); + printf("Name: "); + ssize_t name_nread = getline(&name_line, &(size_t){0}, stdin); + printf("Pass: "); + ssize_t pass_nread = getline(&pass_line, &(size_t){0}, stdin); + + char *url = malloc(--url_nread + 1), *name = malloc(--name_nread + 1) + , *pass = malloc(--pass_nread + 1); + strncpy(url, url_line, url_nread); + free(url_line); + strncpy(name, name_line, name_nread); + free(name_line); + strncpy(pass, pass_line, pass_nread); + free(pass_line); + + rtclient_init(url); + free(url); + + rtclient_login(name, pass); + free(pass); + + struct rt_user *user = NULL; + rtclient_user_show(&user, name); + + if (user) { + printf("id: %s\npassword: %s\nname: %s\nemailaddress: %s\nrealname: %s\nnickname: %s\ngecos: %s\norganization: %s\naddress1: %s\naddress2: %s\ncity: %s\nstate: %s\nzip: %s\ncountry: %s\nhomephone: %s\nworkphone: %s\nmobilephone: %s\npagerphone: %s\ncontactinfo: %s\ncomments: %s\nsignature: %s\nlang: %s\nprivileged: %d\ndisabled: %d\n" + , user->id, user->password, user->name, user->emailaddress + , user->realname, user->nickname, user->gecos + , user->organization, user->address1, user->address2 + , user->city, user->state, user->zip, user->country + , user->homephone, user->workphone, user->mobilephone + , user->pagerphone, user->contactinfo, user->comments + , user->signature, user->lang, user->privileged + , user->disabled); + rtclient_user_free(user); + + struct rt_ticketlist *list = NULL; + static const char *prefix = "Owner='"; + char query[strlen(prefix) + strlen(name) + 2]; + sprintf(query, "%s%s'", prefix, name); + rtclient_ticket_search(&list, query); + if (list) { + for (unsigned short i = 0; i < list->length; i++) { + char *ticket = list->tickets[i]; + printf("Ticket %d: %s\n", i, ticket); + } + rtclient_ticket_freelist(list); + } + } + free(name); + + rtclient_cleanup(); + + return 0; +} diff --git a/test.c b/test.c deleted file mode 100644 index 6dd385c..0000000 --- a/test.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include "rtclient/rtclient.h" - -int main(void) -{ - char *url_line = NULL, *name_line = NULL, *pass_line = NULL; - printf("URL: "); - ssize_t url_nread = getline(&url_line, &(size_t){0}, stdin); - printf("Name: "); - ssize_t name_nread = getline(&name_line, &(size_t){0}, stdin); - printf("Pass: "); - ssize_t pass_nread = getline(&pass_line, &(size_t){0}, stdin); - - char *url = malloc(--url_nread + 1), *name = malloc(--name_nread + 1) - , *pass = malloc(--pass_nread + 1); - strncpy(url, url_line, url_nread); - free(url_line); - strncpy(name, name_line, name_nread); - free(name_line); - strncpy(pass, pass_line, pass_nread); - free(pass_line); - - rtclient_init(url); - free(url); - - rtclient_login(name, pass); - free(pass); - - struct rt_user *user = NULL; - rtclient_user_show(&user, name); - - if (user) { - printf("id: %s\npassword: %s\nname: %s\nemailaddress: %s\nrealname: %s\nnickname: %s\ngecos: %s\norganization: %s\naddress1: %s\naddress2: %s\ncity: %s\nstate: %s\nzip: %s\ncountry: %s\nhomephone: %s\nworkphone: %s\nmobilephone: %s\npagerphone: %s\ncontactinfo: %s\ncomments: %s\nsignature: %s\nlang: %s\nprivileged: %d\ndisabled: %d\n" - , user->id, user->password, user->name, user->emailaddress - , user->realname, user->nickname, user->gecos - , user->organization, user->address1, user->address2 - , user->city, user->state, user->zip, user->country - , user->homephone, user->workphone, user->mobilephone - , user->pagerphone, user->contactinfo, user->comments - , user->signature, user->lang, user->privileged - , user->disabled); - rtclient_user_free(user); - - struct rt_ticketlist *list = NULL; - static const char *prefix = "Owner='"; - char query[strlen(prefix) + strlen(name) + 2]; - sprintf(query, "%s%s'", prefix, name); - rtclient_ticket_search(&list, query); - if (list) { - for (unsigned short i = 0; i < list->length; i++) { - char *ticket = list->tickets[i]; - printf("Ticket %d: %s\n", i, ticket); - } - rtclient_ticket_freelist(list); - } - } - free(name); - - rtclient_cleanup(); - - return 0; -} -- cgit v1.2.3