From 4865ff5eb644fe226b21fd0e8b59fa5648a17803 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 28 Jan 2010 13:36:47 +0100 Subject: [PATCH] Implement GetDataBoxUsers as isds_GetDataBoxUsers() This function allows to get list of users assigned to given box. Current implementation and documentation is wrong: Input is not empty dummy request and the function does not work on current box. User must supply box ID which is he interrested in. --- client/getuserboxinfo.c | 23 ++++++++++-- src/isds.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++- src/isds.h | 6 +++ 3 files changed, 122 insertions(+), 5 deletions(-) diff --git a/client/getuserboxinfo.c b/client/getuserboxinfo.c index 4d060bc..60f2359 100644 --- a/client/getuserboxinfo.c +++ b/client/getuserboxinfo.c @@ -108,10 +108,27 @@ int main(int argc, char **argv) { isds_DbOwnerInfo_free(&db_owner_info); + { + /* Get info all users of this box */ + struct isds_list *users = NULL, *item; + printf("Getting my box users:\n"); + err = isds_GetDataBoxUsers(ctx, &users); + if (err) { + printf("isds_GetDataBoxUsers() failed: %s: %s\n", + isds_strerror(err), isds_long_message(ctx)); + } else { + printf("isds_GetDataBoxUsers() succeeded\n"); + for(item = users; item; item = item->next) { + printf("List item:\n"); + print_DbUserInfo(item->data); + } + } + isds_list_free(&users); + } { + /* Get info about my account */ struct isds_DbUserInfo *db_user_info = NULL; - printf("Getting info about my account:\n"); err = isds_GetUserInfoFromLogin(ctx, &db_user_info); if (err) { @@ -119,9 +136,9 @@ int main(int argc, char **argv) { isds_strerror(err), isds_long_message(ctx)); } else { printf("isds_GetUserInfoFromLogin() succeeded\n"); + print_DbUserInfo(db_user_info); } - print_DbUserInfo(db_user_info); - + isds_DbUserInfo_free(&db_user_info); } { diff --git a/src/isds.c b/src/isds.c index a926385..365ecb2 100644 --- a/src/isds.c +++ b/src/isds.c @@ -3372,7 +3372,6 @@ isds_error isds_GetUserInfoFromLogin(struct isds_ctx *context, xmlChar *code = NULL, *message = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr result = NULL; - char *string = NULL; if (!context) return IE_INVALID_CONTEXT; if (!db_user_info) return IE_INVAL; @@ -3434,7 +3433,102 @@ leave: isds_DbUserInfo_free(db_user_info); } - free(string); + xmlXPathFreeObject(result); + xmlXPathFreeContext(xpath_ctx); + + free(code); + free(message); + xmlFreeDoc(response); + + if (!err) + isds_log(ILF_ISDS, ILL_DEBUG, + _("GetUserInfoFromLogin request processed by server " + "successfully.\n")); + + return err; +} + + +/* Get data about all users with access to your box. + * @context is session context + * @users is automatically reallocated list of struct isds_DbUserInfo */ +isds_error isds_GetDataBoxUsers(struct isds_ctx *context, + struct isds_list **users) { + isds_error err = IE_SUCCESS; + xmlDocPtr response = NULL; + xmlChar *code = NULL, *message = NULL; + xmlXPathContextPtr xpath_ctx = NULL; + xmlXPathObjectPtr result = NULL; + int i; + struct isds_list *item, *prev_item = NULL; + + if (!context) return IE_INVALID_CONTEXT; + if (!users) return IE_INVAL; + + /* Check if connection is established */ + if (!context->curl) return IE_CONNECTION_CLOSED; + + + /* Do request and check for success */ + err = build_send_check_dbdummy_request(context, + BAD_CAST "GetDataBoxUsers", + &response, NULL, NULL, &code, &message); + if (err) goto leave; + + + /* Extract data */ + /* Prepare stucture */ + isds_list_free(users); + xpath_ctx = xmlXPathNewContext(response); + if (!xpath_ctx) { + err = IE_ERROR; + goto leave; + } + if (register_namespaces(xpath_ctx, MESSAGE_NS_UNSIGNED)) { + err = IE_ERROR; + goto leave; + } + + /* Set context node */ + result = xmlXPathEvalExpression(BAD_CAST + "/isds:EnableOwnDataBoxResponse/isds:dbUsers/isds:dbUserInfo", + xpath_ctx); + if (!result) { + err = IE_ERROR; + goto leave; + } + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { + isds_log_message(context, _("Missing dbUserInfo element")); + err = IE_ISDS; + goto leave; + } + + /* Iterate over all users */ + for (i = 0; i < result->nodesetval->nodeNr; i++) { + + /* Prepare structure */ + item = calloc(1, sizeof(*item)); + if (!item) { + err = IE_NOMEM; + goto leave; + } + item->destructor = (void(*)(void**))isds_DbUserInfo_free; + if (i == 0) *users = item; + else prev_item->next = item; + prev_item = item; + + /* Extract it */ + xpath_ctx->node = result->nodesetval->nodeTab[i]; + err = extract_DbUserInfo(context, + (struct isds_DbUserInfo **) (&item->data), xpath_ctx); + if (err) goto leave; + } + +leave: + if (err) { + isds_list_free(users); + } + xmlXPathFreeObject(result); xmlXPathFreeContext(xpath_ctx); diff --git a/src/isds.h b/src/isds.h index 2fd969d..3c928dc 100644 --- a/src/isds.h +++ b/src/isds.h @@ -568,6 +568,12 @@ isds_error isds_GetOwnerInfoFromLogin(struct isds_ctx *context, isds_error isds_GetUserInfoFromLogin(struct isds_ctx *context, struct isds_DbUserInfo **db_user_info); +/* Get data about all users with access to your box. + * @context is session context + * @users is automatically reallocated list of struct isds_DbUserInfo */ +isds_error isds_GetDataBoxUsers(struct isds_ctx *context, + struct isds_list **users); + /* Get expiration time of current password * @context is session context * @expiration is automatically reallocated time when password expires, In -- 2.11.4.GIT