diff options
Diffstat (limited to 'user.c')
-rw-r--r-- | user.c | 246 |
1 files changed, 123 insertions, 123 deletions
@@ -4,6 +4,129 @@ typedef struct rtclient_user rtclient_user; +void rtclient_user_new(const char *name + , const char *password + , const char *emailaddress + , const char *realname + , const char *nickname + , 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 + , const char *contactinfo + , const char *comments + , const char *signature + , const char *gecos + , enum rtclient_lang lang + , enum rtclient_timezone timezone + , bool disabled + , bool privileged) +{ + size_t length = 0; + if (name && strcmp(name, "")) + length += strlen("Name: \n") + strlen(name); + if (password && strcmp(password, "")) + length += strlen("Password: \n") + strlen(password); + 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 (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); + if (contactinfo && strcmp(contactinfo, "")) + length += strlen("ContactInfo: \n") + strlen(contactinfo); + if (comments && strcmp(comments, "")) + length += strlen("Comments: \n") + strlen(comments); + if (signature && strcmp(signature, "")) + length += strlen("Signature: \n") + strlen(signature); + if (gecos && strcmp(gecos, "")) + length += strlen("Gecos: \n") + strlen(gecos); + + char content[length + strlen("Privileged: \nDisabled: \n") + 3]; + memset(content, 0, strlen(content)); + if (name && strcmp(name, "")) + sprintf(content, "%sName: %s\n", content, name); + if (password && strcmp(password, "")) + sprintf(content, "%sPassword: %s\n", content, password); + 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 (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); + if (contactinfo && strcmp(contactinfo, "")) + sprintf(content, "%sContactInfo: %s\n", content, contactinfo); + if (comments && strcmp(comments, "")) + sprintf(content, "%sComments: %s\n", content, comments); + if (signature && strcmp(signature, "")) + sprintf(content, "%sSignature: %s\n", content, signature); + if (gecos && strcmp(gecos, "")) + sprintf(content, "%sGecos: %s\n", content, gecos); + sprintf(content, "%sPrivileged: %d\nDisabled: %d\n", content, privileged + , disabled); + + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last + , CURLFORM_COPYNAME, "content" + , CURLFORM_PTRCONTENTS, content + , CURLFORM_END); + last = NULL; + request("/REST/1.0/user/new", "", NULL, NULL, post); + curl_formfree(post); + post = NULL; +} + static size_t show_callback(void *contents, size_t size, size_t nmemb , void *writedata) { @@ -157,129 +280,6 @@ void rtclient_user_show(rtclient_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 *password - , const char *emailaddress - , const char *realname - , const char *nickname - , 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 - , const char *contactinfo - , const char *comments - , const char *signature - , const char *gecos - , enum rtclient_lang lang - , enum rtclient_timezone timezone - , bool disabled - , bool privileged) -{ - size_t length = 0; - if (name && strcmp(name, "")) - length += strlen("Name: \n") + strlen(name); - if (password && strcmp(password, "")) - length += strlen("Password: \n") + strlen(password); - 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 (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); - if (contactinfo && strcmp(contactinfo, "")) - length += strlen("ContactInfo: \n") + strlen(contactinfo); - if (comments && strcmp(comments, "")) - length += strlen("Comments: \n") + strlen(comments); - if (signature && strcmp(signature, "")) - length += strlen("Signature: \n") + strlen(signature); - if (gecos && strcmp(gecos, "")) - length += strlen("Gecos: \n") + strlen(gecos); - - char content[length + strlen("Privileged: \nDisabled: \n") + 3]; - memset(content, 0, strlen(content)); - if (name && strcmp(name, "")) - sprintf(content, "%sName: %s\n", content, name); - if (password && strcmp(password, "")) - sprintf(content, "%sPassword: %s\n", content, password); - 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 (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); - if (contactinfo && strcmp(contactinfo, "")) - sprintf(content, "%sContactInfo: %s\n", content, contactinfo); - if (comments && strcmp(comments, "")) - sprintf(content, "%sComments: %s\n", content, comments); - if (signature && strcmp(signature, "")) - sprintf(content, "%sSignature: %s\n", content, signature); - if (gecos && strcmp(gecos, "")) - sprintf(content, "%sGecos: %s\n", content, gecos); - sprintf(content, "%sPrivileged: %d\nDisabled: %d\n", content, privileged - , disabled); - - struct curl_httppost *post, *last = NULL; - curl_formadd(&post, &last - , CURLFORM_COPYNAME, "content" - , CURLFORM_PTRCONTENTS, content - , CURLFORM_END); - last = NULL; - request("/REST/1.0/user/new", "", NULL, NULL, post); - curl_formfree(post); - post = NULL; -} - void rtclient_user_free(rtclient_user *user) { if (user->id) |