diff options
-rw-r--r-- | rtclient/user.h | 12 | ||||
-rw-r--r-- | user.c | 106 |
2 files changed, 112 insertions, 6 deletions
diff --git a/rtclient/user.h b/rtclient/user.h index 719b8dc..7d0ab64 100644 --- a/rtclient/user.h +++ b/rtclient/user.h @@ -4,7 +4,8 @@ #include <stdbool.h> enum rt_lang { - RT_LANG_ar + RT_LANG_NONE = 0 + , RT_LANG_ar , RT_LANG_eu , RT_LANG_nb , RT_LANG_bg @@ -46,7 +47,8 @@ enum rt_lang { }; enum rt_timezone { - RT_TIMEZONE_Africa_Abidjan + RT_TIMEZONE_NONE = 0 + , RT_TIMEZONE_Africa_Abidjan , RT_TIMEZONE_Africa_Accra , RT_TIMEZONE_Africa_Algiers , RT_TIMEZONE_Africa_Bissau @@ -440,8 +442,7 @@ extern "C" { #endif void rtclient_user_show(struct rt_user **userptr, const char *name); - void rtclient_user_new( - const char *name + void rtclient_user_new(const char *name , const char *emailaddress , const char *realname , const char *nickname @@ -464,8 +465,7 @@ extern "C" { , const char *homephone , const char *workphone , const char *mobilephone - , const char *pagerphone - ); + , const char *pagerphone); void rtclient_user_free(struct rt_user *user); #ifdef __cplusplus @@ -134,6 +134,112 @@ void rtclient_user_show(rt_user **userptr, const char *name) request("/REST/1.0/user/", name, show_callback, (void *)userptr, NULL); } +void rtclient_user_new(const char *name, const char *emailaddress + , const char *realname, const char *nickname, const char *gecos + , enum rt_lang lang, enum rt_timezone timezone + , const char *contactinfo, bool enabled, bool privileged + , const char *password, const char *comments, const char *signature + , const char *organization, const char *address1 + , const char *address2, const char *city, const char *state + , const char *zip, const char *country, const char *homephone + , const char *workphone, const char *mobilephone + , const char *pagerphone) +{ + size_t length = 0; + if (name && strcmp(name, "")) + length += strlen("name: \n") + strlen(name); + if (emailaddress && strcmp(emailaddress, "")) + length += strlen("emailaddress: \n") + strlen(emailaddress); + if (realname && strcmp(realname, "")) + length += strlen("realname: \n") + strlen(realname); + if (nickname && strcmp(nickname, "")) + length += strlen("nickname: \n") + strlen(nickname); + if (gecos && strcmp(gecos, "")) + length += strlen("gecos: \n") + strlen(gecos); + if (contactinfo && strcmp(contactinfo, "")) + length += strlen("contactinfo: \n") + strlen(contactinfo); + if (password && strcmp(password, "")) + length += strlen("password: \n") + strlen(password); + if (comments && strcmp(comments, "")) + length += strlen("comments: \n") + strlen(comments); + if (signature && strcmp(signature, "")) + length += strlen("signature: \n") + strlen(signature); + if (organization && strcmp(organization, "")) + length += strlen("organization: \n") + strlen(organization); + if (address1 && strcmp(address1, "")) + length += strlen("address1: \n") + strlen(address1); + if (address2 && strcmp(address2, "")) + length += strlen("address1: \n") + strlen(address2); + if (city && strcmp(city, "")) + length += strlen("city: \n") + strlen(city); + if (state && strcmp(state, "")) + length += strlen("state: \n") + strlen(state); + if (zip && strcmp(zip, "")) + length += strlen("zip: \n") + strlen(zip); + if (country && strcmp(country, "")) + length += strlen("country: \n") + strlen(country); + if (homephone && strcmp(homephone, "")) + length += strlen("homephone: \n") + strlen(homephone); + if (workphone && strcmp(workphone, "")) + length += strlen("workphone: \n") + strlen(workphone); + if (mobilephone && strcmp(mobilephone, "")) + length += strlen("mobilephone: \n") + strlen(mobilephone); + if (pagerphone && strcmp(pagerphone, "")) + length += strlen("pagerphone: \n") + strlen(pagerphone); + + char content[length + strlen("privileged: \nenabled: \n") + 3]; + if (name && strcmp(name, "")) + sprintf(content, "%sname: %s\n", content, name); + if (emailaddress && strcmp(emailaddress, "")) + sprintf(content, "%semailaddress: %s\n", content, emailaddress); + if (realname && strcmp(realname, "")) + sprintf(content, "%srealname: %s\n", content, realname); + if (nickname && strcmp(nickname, "")) + sprintf(content, "%snickname: %s\n", content, nickname); + if (gecos && strcmp(gecos, "")) + sprintf(content, "%sgecos: %s\n", content, gecos); + if (contactinfo && strcmp(contactinfo, "")) + sprintf(content, "%scontactinfo: %s\n", content, contactinfo); + if (password && strcmp(password, "")) + sprintf(content, "%spassword: %s\n", content, password); + if (comments && strcmp(comments, "")) + sprintf(content, "%scomments: %s\n", content, comments); + if (signature && strcmp(signature, "")) + sprintf(content, "%ssignature: %s\n", content, signature); + if (organization && strcmp(organization, "")) + sprintf(content, "%sorganization: %s\n", content, organization); + if (address1 && strcmp(address1, "")) + sprintf(content, "%saddress1: %s\n", content, address1); + if (address2 && strcmp(address2, "")) + sprintf(content, "%saddress2: %s\n", content, address2); + if (city && strcmp(city, "")) + sprintf(content, "%scity: %s\n", content, city); + if (state && strcmp(state, "")) + sprintf(content, "%sstate: %s\n", content, state); + if (zip && strcmp(zip, "")) + sprintf(content, "%szip: %s\n", content, zip); + if (country && strcmp(country, "")) + sprintf(content, "%scountry: %s\n", content, country); + if (homephone && strcmp(homephone, "")) + sprintf(content, "%shomephone: %s\n", content, homephone); + if (workphone && strcmp(workphone, "")) + sprintf(content, "%sworkphone: %s\n", content, workphone); + if (mobilephone && strcmp(mobilephone, "")) + sprintf(content, "%smobilephone: %s\n", content, mobilephone); + if (pagerphone && strcmp(pagerphone, "")) + sprintf(content, "%spagerphone: %s\n", content, pagerphone); + + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last + , CURLFORM_COPYNAME, "content" + , CURLFORM_PTRCONTENTS, content + , CURLFORM_END); + last = NULL; + request("", "", NULL, NULL, post); + curl_formfree(post); + post = NULL; +} + void rtclient_user_free(rt_user *user) { free(user->id); |