summaryrefslogtreecommitdiffstats
path: root/webservice.c
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-01-18 19:52:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-18 10:07:17 -0800
commit9fa6b224f75e4c99fc8ab2c68309319150b7164f (patch)
treea1ae5395a3b01df6998aeecb46db77e550508673 /webservice.c
parent334e51988da0bcb6f55fd86bc503255275056d5a (diff)
downloadsubsurface-9fa6b224f75e4c99fc8ab2c68309319150b7164f.tar.gz
Fixed some small issues in webservice.c
1) download_dialog_status_text() had some statements with no effect due to missing return keywords. This fixes incorrect error reporting. 2) Optimize the traversion of the response XML. Assuming that the status tag should be always under the root tag. We check if the root tag has children and enter a loop until we find a the "download" or "error" node names. If there are no children we return a parser error. 3) Clamp the number of input characters to 30 in the user id GtkEntry field. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'webservice.c')
-rw-r--r--webservice.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/webservice.c b/webservice.c
index 01bf76263..5acfb2da9 100644
--- a/webservice.c
+++ b/webservice.c
@@ -18,17 +18,15 @@ static const gchar *download_dialog_status_text(const gint status)
switch (status) {
case DD_STATUS_ERROR_CONNECT:
return _("Connection Error: ");
- break;
case DD_STATUS_ERROR_ID:
- _("Invalid user identifier!");
- break;
+ return _("Invalid user identifier!");
case DD_STATUS_ERROR_PARSE:
- _("Cannot parse response!");
+ return _("Cannot parse response!");
}
return _("Download Success!");
}
-/* provides a state of the download dialog contents and the download xml */
+/* provides a state of the download dialog contents and the downloaded xml */
struct download_dialog_state {
GtkWidget *uid;
GtkWidget *status;
@@ -69,20 +67,18 @@ gboolean webservice_request_user_xml(const gchar *user_id,
return ret;
}
-static void download_dialog_traverse_xml(xmlNodePtr node, gboolean *download_status)
+/* requires that there is a <download> or <error> tag under the <root> tag */
+static void download_dialog_traverse_xml(xmlNodePtr node, guint *download_status)
{
xmlNodePtr cur_node;
-
for (cur_node = node; cur_node; cur_node = cur_node->next) {
- if (!strcmp(cur_node->name, (const gchar *)"download")) {
- if (!strcmp(xmlNodeGetContent(cur_node), (const gchar *)"ok")) {
- *download_status = DD_STATUS_OK;
- return;
- }
- } else if (!strcmp(cur_node->name, (const gchar *)"error")) {
+ if ((!strcmp(cur_node->name, (const gchar *)"download")) &&
+ (!strcmp(xmlNodeGetContent(cur_node), (const gchar *)"ok"))) {
+ *download_status = DD_STATUS_OK;
+ return;
+ } else if (!strcmp(cur_node->name, (const gchar *)"error")) {
*download_status = DD_STATUS_ERROR_ID;
- } else {
- download_dialog_traverse_xml(cur_node->children, download_status);
+ return;
}
}
}
@@ -100,7 +96,8 @@ static guint download_dialog_parse_response(gchar *xmldata, guint len)
status = DD_STATUS_ERROR_PARSE;
goto end;
}
- download_dialog_traverse_xml(root, &status);
+ if (root->children)
+ download_dialog_traverse_xml(root->children, &status);
end:
xmlFreeDoc(doc);
return status;
@@ -177,6 +174,7 @@ void webservice_download_dialog(void)
gtk_box_pack_start(GTK_BOX(vbox), frame_uid, FALSE, TRUE, pad);
uid = gtk_entry_new();
gtk_container_add(GTK_CONTAINER(frame_uid), uid);
+ gtk_entry_set_max_length(GTK_ENTRY(uid), 30);
gtk_entry_set_text(GTK_ENTRY(uid), current_uid);
download = gtk_button_new_with_label(_(" Download"));