summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rtclient.c22
-rw-r--r--rtclient.h4
-rw-r--r--rtuser.h24
3 files changed, 32 insertions, 18 deletions
diff --git a/rtclient.c b/rtclient.c
index a66cd56..44088ec 100644
--- a/rtclient.c
+++ b/rtclient.c
@@ -11,6 +11,7 @@
#include <curl/curl.h>
#include "rtclient.h"
+typedef struct rt_user rt_user;
static CURL *curl = NULL;
static char *server_url = NULL;
@@ -71,10 +72,18 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata)
char response[realsize + 1];
memcpy(&response[0], contents, realsize);
response[realsize] = '\0';
- char *token = strtok(response, "\n");
- if (strstr(token, "200 Ok"))
- while (token)
- token = strtok(NULL, "\n");
+ char *lines[21];
+ char *line = strtok(response, "\n");
+ if (strstr(line, "200 Ok")) {
+ rt_user *user = (rt_user *)writedata;
+ user = malloc(sizeof(rt_user));
+ line = strtok(NULL, "\n");
+ while (line) {
+ printf("Line:\n%s\n", line);
+ line = strtok(NULL, "\n");
+ }
+ free(user);
+ }
return realsize;
}
@@ -87,10 +96,13 @@ static inline void request(const char *path, const char *suffix)
curl_easy_perform(curl);
}
-void rtclient_user(const char *name)
+rt_user *rtclient_user(const char *name)
{
+ rt_user *user = NULL;
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, user);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, user_callback);
request("/REST/1.0/user/", name);
+ return user;
}
void rtclient_search(const char *query)
diff --git a/rtclient.h b/rtclient.h
index dd3cb61..bdf6965 100644
--- a/rtclient.h
+++ b/rtclient.h
@@ -1,13 +1,15 @@
#ifndef RTCLIENT_H
#define RTCLIENT_H
+#include "rtuser.h"
+
#ifdef __cplusplus
extern "C" {
#endif
bool rtclient_init(const char *server_url);
void rtclient_login(const char *name, const char *password);
- void rtclient_user(const char *name);
+ struct rt_user *rtclient_user(const char *name);
void rtclient_search(const char *query);
void rtclient_cleanup();
diff --git a/rtuser.h b/rtuser.h
index dff3de0..9038a4a 100644
--- a/rtuser.h
+++ b/rtuser.h
@@ -1,28 +1,28 @@
#ifndef RTUSER_H
#define RTUSER_H
-typedef struct rt_user {
- unsigned int id;
- char *name;
+struct rt_user {
+ char *id;
char *password;
- char *authtoken;
+ char *name;
char *emailaddress;
- char *organization;
char *realname;
char *nickname;
- char *lang;
char *gecos;
- char *homephone;
- char *workphone;
- char *mobilephone;
- char *pagerphone;
+ char *organization;
char *address1;
char *address2;
char *city;
char *state;
char *zip;
char *country;
- char *timezone;
-} rt_user;
+ char *homephone;
+ char *workphone;
+ char *mobilephone;
+ char *pagerphone;
+ char lang[2];
+ bool privileged;
+ bool disabled;
+};
#endif // RTUSER_H