summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin.c15
-rw-r--r--icclient/admin.h3
-rw-r--r--icclient/member.h19
-rw-r--r--icclient/typedefs.h2
-rw-r--r--login.c2
-rw-r--r--login.h4
-rw-r--r--main.c6
-rw-r--r--member.c73
-rw-r--r--request.c2
-rw-r--r--request.h2
10 files changed, 29 insertions, 99 deletions
diff --git a/admin.c b/admin.c
index b06a751..57d88ff 100644
--- a/admin.c
+++ b/admin.c
@@ -3,16 +3,10 @@
#include "login.h"
#include "icclient/admin.h"
-typedef struct icclient_admin icclient_admin;
-
-icclient_admin *icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *))
+void icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *),
+ void (*callback)(struct icclient_admin *))
{
- icclient_admin *admin = malloc(sizeof(icclient_admin));
- admin->name = NULL;
- admin->username = NULL;
- admin->super = false;
- login(username, password, NULL, "MMLogin", handler, admin);
- return admin;
+ login(username, password, NULL, "MMLogin", handler, (void (*)(void *))callback);
}
void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super,
@@ -65,7 +59,7 @@ void icclient_admin_new_item(const char *description, const char *comment, const
}}, "%s", "admin/item_edit");
}
-void icclient_admin_logout(icclient_admin *admin, void (*handler)(icclient_fetch_t *))
+void icclient_admin_logout(struct icclient_admin *admin, void (*handler)(icclient_fetch_t *))
{
request(handler, NULL, NULL, "%s", "admin/login");
if (admin->name)
@@ -73,5 +67,4 @@ void icclient_admin_logout(icclient_admin *admin, void (*handler)(icclient_fetch
if (admin->username)
free(admin->username);
free(admin);
- admin = NULL;
}
diff --git a/icclient/admin.h b/icclient/admin.h
index 9756f40..e1acee9 100644
--- a/icclient/admin.h
+++ b/icclient/admin.h
@@ -19,7 +19,8 @@ struct icclient_admin {
extern "C" {
#endif
- struct icclient_admin *icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *));
+ void icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *),
+ void (*callback)(struct icclient_admin *));
void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super,
enum icclient_admin_group group, void (*handler)(icclient_fetch_t *));
void icclient_admin_new_item(const char *description, const char *comment, const char *price, const char *image_path,
diff --git a/icclient/member.h b/icclient/member.h
index 3c6a41d..a1943a0 100644
--- a/icclient/member.h
+++ b/icclient/member.h
@@ -60,20 +60,17 @@ struct icclient_member {
extern "C" {
#endif
- struct icclient_member *icclient_member_newaccount(const char *username, const char *password, const char *verify,
- void (*handler)(icclient_fetch_t *));
- struct icclient_member *icclient_member_login(const char *username, const char *password,
- void (*handler)(icclient_fetch_t *));
- 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_newaccount(const char *username, const char *password, const char *verify,
+ void (*handler)(icclient_fetch_t *), void (*callback)(struct icclient_member *));
+ void icclient_member_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *),
+ void (*callback)(struct icclient_member *));
+ 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(struct icclient_member *member);
#ifdef __cplusplus
}
#endif
-#endif // ICCLIENT_MEMBER_H
+#endif
diff --git a/icclient/typedefs.h b/icclient/typedefs.h
index fbfa0d0..ff5caca 100644
--- a/icclient/typedefs.h
+++ b/icclient/typedefs.h
@@ -27,7 +27,7 @@ typedef struct curl_httppost icclient_post;
struct icclient_post_callback {
icclient_post *post;
- void (*callback)(icclient_fetch_t *);
+ void (*callback)(void *);
};
#endif
diff --git a/login.c b/login.c
index de81b02..588cb37 100644
--- a/login.c
+++ b/login.c
@@ -1,3 +1,3 @@
#include "login.h"
-extern inline void login(const char *, const char *, const char *, const char *, void (*)(icclient_fetch_t *), void *);
+extern inline void login(const char *, const char *, const char *, const char *, void (*)(icclient_fetch_t *), void (*)(void *));
diff --git a/login.h b/login.h
index 2ea4e17..57d3446 100644
--- a/login.h
+++ b/login.h
@@ -4,9 +4,9 @@
#include "request.h"
static inline void login(const char *username, const char *password, const char *verify, const char *click,
- void (*handler)(icclient_fetch_t *), void *user)
+ void (*handler)(icclient_fetch_t *), void (*callback)(void *))
{
- request(handler, user, &(struct body){ 4, {
+ request(handler, callback, &(struct body){ 4, {
{ "mv_username", username },
{ "mv_password", password },
{ "mv_verify", verify },
diff --git a/main.c b/main.c
index 113abe3..2fd9dfa 100644
--- a/main.c
+++ b/main.c
@@ -34,9 +34,7 @@ int main(int argc, char *argv[])
{
icclient_init("https://demo.interchangecommerce.org/i/demo", "/demo/images", NULL);
icclient_allproducts(NULL, print_catalog);
- struct icclient_admin *admin = icclient_admin_login("demo", "demo", NULL);
- icclient_admin_logout(admin, NULL);
- struct icclient_member *member = icclient_member_login("kirk@icdevgroup.net", "kirk", print);
- icclient_member_logout(member);
+ icclient_admin_login("demo", "demo", print, NULL);
+ icclient_member_login("kirk@icdevgroup.net", "kirk", print, NULL);
icclient_cleanup();
}
diff --git a/member.c b/member.c
index 66ceb22..9f53113 100644
--- a/member.c
+++ b/member.c
@@ -3,74 +3,16 @@
#include "login.h"
#include "icclient/member.h"
-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,
- void (*handler)(icclient_fetch_t *))
+void icclient_member_newaccount(const char *username, const char *password, const char *verify,
+ void (*handler)(icclient_fetch_t *), void (*callback)(struct icclient_member *))
{
- icclient_member *member = initialise(username, password);
- login(username, password, verify, "NewAccount", handler, member);
- return member;
+ login(username, password, verify, "NewAccount", handler, (void (*)(void *))callback);
}
-icclient_member *icclient_member_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *))
+void icclient_member_login(const char *username, const char *password, void (*handler)(icclient_fetch_t *),
+ void (*callback)(struct icclient_member *))
{
- icclient_member *member = initialise(username, password);
- login(username, password, NULL, "Login", handler, member);
- return member;
+ login(username, password, NULL, "Login", handler, (void (*)(void *))callback);
}
void icclient_member_account(const char *fname, const char *lname, const char *address1,
@@ -106,7 +48,7 @@ void icclient_member_changepassword(const char *password_old, const char *passwo
}}, "%s", "member/change_password");
}
-void icclient_member_logout(icclient_member *member)
+void icclient_member_logout(struct icclient_member *member)
{
request(NULL, NULL, NULL, "%s", "logout");
if (member->username)
@@ -200,5 +142,4 @@ void icclient_member_logout(icclient_member *member)
if (member->price_level)
free(member->price_level);
free(member);
- member = NULL;
}
diff --git a/request.c b/request.c
index 0a5f7fd..0912fa8 100644
--- a/request.c
+++ b/request.c
@@ -16,5 +16,5 @@ size_t append(char *data, size_t size, size_t nmemb, icclient_fetch_t *fetch)
#endif
extern inline void init(const char *);
-extern inline void request(void (*)(icclient_fetch_t *), void *, struct body *, char *, ...);
+extern inline void request(void (*)(icclient_fetch_t *), void (*)(void *), struct body *, char *, ...);
extern inline void cleanup();
diff --git a/request.h b/request.h
index 1327ef3..64d6974 100644
--- a/request.h
+++ b/request.h
@@ -44,7 +44,7 @@ static inline void init(const char *certificate)
#endif
}
-static inline void request(void (*handler)(icclient_fetch_t *), void *callback, struct body *body, char *fmt, ...)
+static inline void request(void (*handler)(icclient_fetch_t *), void (*callback)(void *), struct body *body, char *fmt, ...)
{
va_list ap;
char *p, *sval;