summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.c22
-rw-r--r--icclient/admin.h14
-rw-r--r--icclient/member.h14
-rw-r--r--login.c6
-rw-r--r--login.h12
-rw-r--r--member.c82
-rw-r--r--request.h8
7 files changed, 114 insertions, 44 deletions
diff --git a/admin.c b/admin.c
index 3b7cd9c..f0c5d49 100644
--- a/admin.c
+++ b/admin.c
@@ -1,16 +1,24 @@
+#include <stdlib.h>
+#include <stdbool.h>
#include "login.h"
#include "icclient/admin.h"
-void icclient_admin_login(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username,
- const char *password, const char *successpage, const char *nextpage,
- const char *failpage)
+typedef struct icclient_admin icclient_admin;
+
+icclient_admin *icclient_admin_login(const char *username, const char *password,
+ const char *successpage, const char *nextpage, const char *failpage,
+ size_t (*handler)(void *, size_t, size_t, void *))
{
- login(handler, member, username, password, NULL, "MMLogin", successpage, nextpage,
- failpage);
+ icclient_admin *admin = malloc(sizeof(icclient_admin));
+ admin->name = NULL;
+ admin->username = NULL;
+ admin->super = false;
+ login(username, password, NULL, "MMLogin", successpage, nextpage, failpage,
+ handler, admin);
+ return admin;
}
-void icclient_admin_logout()
+void icclient_admin_logout(icclient_admin *admin)
{
request(NULL, NULL, NULL, "%s", "admin/login");
}
diff --git a/icclient/admin.h b/icclient/admin.h
index faff559..fa38676 100644
--- a/icclient/admin.h
+++ b/icclient/admin.h
@@ -1,15 +1,21 @@
#ifndef ICCLIENT_ADMIN_H
#define ICCLIENT_ADMIN_H
+struct icclient_admin {
+ char *name;
+ char *username;
+ bool super;
+};
+
#ifdef __cplusplus
extern "C" {
#endif
- void icclient_admin_login(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username,
+ struct icclient_admin *icclient_admin_login(const char *username,
const char *password, const char *successpage,
- const char *nextpage, const char *failpage);
- void icclient_admin_logout();
+ const char *nextpage, const char *failpage,
+ size_t (*handler)(void *, size_t, size_t, void *));
+ void icclient_admin_logout(struct icclient_admin *admin);
#ifdef __cplusplus
}
diff --git a/icclient/member.h b/icclient/member.h
index a91c5d6..d68f814 100644
--- a/icclient/member.h
+++ b/icclient/member.h
@@ -55,21 +55,21 @@ struct icclient_member {
extern "C" {
#endif
- void icclient_member_newaccount(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username,
+ struct icclient_member *icclient_member_newaccount(const char *username,
const char *password, const char *verify, const char *successpage,
- const char *nextpage, const char *failpage);
- void icclient_member_login(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username,
+ const char *nextpage, const char *failpage,
+ size_t (*handler)(void *, size_t, size_t, void *));
+ struct icclient_member *icclient_member_login(const char *username,
const char *password, const char *successpage,
- const char *nextpage, const char *failpage);
+ const char *nextpage, const char *failpage,
+ size_t (*handler)(void *, size_t, size_t, void *));
void icclient_member_account(const char *fname, const char *lname,
const char *address1, const char *address2, const char *city,
const char *state, const char *zip, const char *email,
const char *phone_day);
void icclient_member_changepassword(const char *password_old, const char *password,
const char *verify);
- void icclient_member_logout();
+ void icclient_member_logout(struct icclient_member *member);
#ifdef __cplusplus
}
diff --git a/login.c b/login.c
index 679a962..0a5bcb2 100644
--- a/login.c
+++ b/login.c
@@ -1,5 +1,5 @@
#include "login.h"
-extern inline void login(size_t (*)(void *, size_t, size_t, void *),
- struct icclient_member *, const char *, const char *, const char *,
- const char *, const char *, const char *, const char *);
+extern inline void login(const char *, const char *, const char *, const char *,
+ const char *, const char *, const char *,
+ size_t (*)(void *, size_t, size_t, void *), void *);
diff --git a/login.h b/login.h
index e8ce170..903adf8 100644
--- a/login.h
+++ b/login.h
@@ -3,12 +3,10 @@
#include "request.h"
-struct icclient_member;
-
-inline void login(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username, const char *password,
- const char *verify, const char *click, const char *successpage,
- const char *nextpage, const char *failpage)
+inline void login(const char *username, const char *password, const char *verify,
+ const char *click, const char *successpage, const char *nextpage,
+ const char *failpage, size_t (*handler)(void *, size_t, size_t, void *),
+ void *user)
{
struct curl_httppost *post, *last = NULL;
curl_formadd(&post, &last,
@@ -44,7 +42,7 @@ inline void login(size_t (*handler)(void *, size_t, size_t, void *),
CURLFORM_PTRCONTENTS, failpage,
CURLFORM_END);
last = NULL;
- request(handler, member, post, "%s", "process");
+ request(handler, user, post, "%s", "process");
curl_formfree(post);
post = NULL;
}
diff --git a/member.c b/member.c
index b8076d0..c9e62b4 100644
--- a/member.c
+++ b/member.c
@@ -1,23 +1,81 @@
-#include <stddef.h>
+#include <stdlib.h>
#include <stdbool.h>
#include "login.h"
#include "icclient/member.h"
-void icclient_member_newaccount(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username, const char *password,
+typedef struct icclient_member icclient_member;
+
+icclient_member *initialise(const char *username, const char *password)
+{
+ icclient_member *member = malloc(sizeof(icclient_member));
+ member->username = NULL;
+ member->usernick = NULL;
+ member->password = NULL;
+ member->expiration = NULL;
+ member->acl = NULL;
+ member->mod_time = NULL;
+ member->s_nickname = NULL;
+ member->company = NULL;
+ member->fname = NULL;
+ member->lname = NULL;
+ member->address1 = NULL;
+ member->address2 = NULL;
+ member->address3 = NULL;
+ member->city = NULL;
+ member->state = NULL;
+ member->zip = NULL;
+ member->country = NULL;
+ member->phone_day = NULL;
+ member->mv_shipmode = NULL;
+ member->b_nickname = NULL;
+ member->b_fname = NULL;
+ member->b_lname = NULL;
+ member->b_company = NULL;
+ member->b_address1 = NULL;
+ member->b_address2 = NULL;
+ member->b_address3 = NULL;
+ member->b_city = NULL;
+ member->b_state = NULL;
+ member->b_zip = NULL;
+ member->b_country = NULL;
+ member->b_phone = NULL;
+ member->p_nickname = NULL;
+ member->email = NULL;
+ member->fax = NULL;
+ member->phone_night = NULL;
+ member->address_book = NULL;
+ member->accounts = NULL;
+ member->preferences = NULL;
+ member->carts = NULL;
+ member->owner = NULL;
+ member->file_acl = NULL;
+ member->db_acl = NULL;
+ member->mail_list = NULL;
+ member->credit_limit = NULL;
+ member->inactive = false;
+ member->dealer = false;
+ member->price_level = NULL;
+ return member;
+}
+
+icclient_member *icclient_member_newaccount(const char *username, const char *password,
const char *verify, const char *successpage, const char *nextpage,
- const char *failpage)
+ const char *failpage, size_t (*handler)(void *, size_t, size_t, void *))
{
- login(handler, member, username, password, verify, "NewAccount", successpage,
- nextpage, failpage);
+ icclient_member *member = initialise(username, password);
+ login(username, password, verify, "NewAccount", successpage, nextpage, failpage,
+ handler, member);
+ return member;
}
-void icclient_member_login(size_t (*handler)(void *, size_t, size_t, void *),
- struct icclient_member *member, const char *username, const char *password,
- const char *successpage, const char *nextpage, const char *failpage)
+icclient_member *icclient_member_login(const char *username, const char *password,
+ const char *successpage, const char *nextpage, const char *failpage,
+ size_t (*handler)(void *, size_t, size_t, void *))
{
- login(handler, member, username, password, NULL, "Login", successpage, nextpage,
- failpage);
+ icclient_member *member = initialise(username, password);
+ login(username, password, NULL, "Login", successpage, nextpage, failpage, handler,
+ member);
+ return member;
}
void icclient_member_account(const char *fname, const char *lname, const char *address1,
@@ -117,7 +175,7 @@ void icclient_member_changepassword(const char *password_old, const char *passwo
post = NULL;
}
-void icclient_member_logout()
+void icclient_member_logout(icclient_member *member)
{
request(NULL, NULL, NULL, "%s", "logout");
}
diff --git a/request.h b/request.h
index 68411d9..1d15b6a 100644
--- a/request.h
+++ b/request.h
@@ -12,8 +12,8 @@
extern CURL *curl;
extern char *server_url;
-inline void request(size_t (*writefunction)(void *, size_t, size_t, void *)
- , void *writedata, struct curl_httppost *post, char *fmt, ...)
+inline void request(size_t (*writefunction)(void *, size_t, size_t, void *),
+ void *writedata, struct curl_httppost *post, char *fmt, ...)
{
va_list ap;
char *p, *sval;
@@ -83,8 +83,8 @@ inline void request(size_t (*writefunction)(void *, size_t, size_t, void *)
if (res != CURLE_OK) {
const char *error = curl_easy_strerror(res);
#ifdef ANDROID
- __android_log_print(ANDROID_LOG_ERROR, "libicclient", "%s: %s"
- , __func__, error);
+ __android_log_print(ANDROID_LOG_ERROR, "libicclient", "%s: %s", __func__,
+ error);
#else
fprintf(stderr, "%s: %s\n", __func__, error);
#endif // ANDROID