changeset 1236:b912173aecd1

Added a_Dpip_get_attr_l() to DPIP's API
author Jorge Arellano Cid <jcid@dillo.org>
date Fri, 17 Jul 2009 19:19:35 -0400
parents 81e5a3d2dbf0
children 688f9ad32e2a
files ChangeLog dpi/bookmarks.c dpi/cookies.c dpi/datauri.c dpi/downloads.cc dpi/file.c dpi/ftp.c dpi/hello.c dpi/https.c dpid/dpid.c dpid/main.c dpip/dpip.c dpip/dpip.h src/IO/dpi.c src/cookies.c src/dpiapi.c
diffstat 16 files changed, 69 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jul 17 15:48:00 2009 -0400
+++ b/ChangeLog	Fri Jul 17 19:19:35 2009 -0400
@@ -11,6 +11,7 @@
 +- Cleaned up system includes in dpid directory.
  - Fixed CustProgressBox() for systems without weak symbols.
  - Handle signed chars. Added dIsspace() and dIsalnum() to dlib.
+ - Added a_Dpip_get_attr_l() to DPIP's API.
    Patches: Jorge Arellano Cid
 +- Fix segfault from AREA when MAP is missing name attribute.
    Patch: corvid
--- a/dpi/bookmarks.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/bookmarks.c	Fri Jul 17 19:19:35 2009 -0400
@@ -1580,11 +1580,11 @@
    }
 
    BufSize = strlen(Buf);
-   cmd = a_Dpip_get_attr(Buf, BufSize, "cmd");
+   cmd = a_Dpip_get_attr_l(Buf, BufSize, "cmd");
 
    if (cmd && strcmp(cmd, "chat") == 0) {
       dFree(cmd);
-      msg = a_Dpip_get_attr(Buf, BufSize, "msg");
+      msg = a_Dpip_get_attr_l(Buf, BufSize, "msg");
       if (*msg == 'H') {
          /* "Hi server" */
          if (sock_handler_write_str(sh, 1, msg1))
@@ -1611,8 +1611,8 @@
 
    } else if (cmd && strcmp(cmd, "add_bookmark") == 0) {
       dFree(cmd);
-      url = a_Dpip_get_attr(Buf, BufSize, "url");
-      title = a_Dpip_get_attr(Buf, BufSize, "title");
+      url = a_Dpip_get_attr_l(Buf, BufSize, "url");
+      title = a_Dpip_get_attr_l(Buf, BufSize, "title");
       if (strlen(title) == 0) {
          dFree(title);
          title = dStrdup("(Untitled)");
@@ -1625,7 +1625,7 @@
 
    } else if (cmd && strcmp(cmd, "open_url") == 0) {
       dFree(cmd);
-      url = a_Dpip_get_attr(Buf, BufSize, "url");
+      url = a_Dpip_get_attr_l(Buf, BufSize, "url");
 
       if (strcmp(url, "dpi:/bm/modify") == 0) {
          st = Bmsrv_send_modify_answer(sh, url);
--- a/dpi/cookies.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/cookies.c	Fri Jul 17 19:19:35 2009 -0400
@@ -1354,7 +1354,7 @@
       return 1;
    }
 
-   cmd = a_Dpip_get_attr(Buf, BufSize, "cmd");
+   cmd = a_Dpip_get_attr_l(Buf, BufSize, "cmd");
 
    if (cmd && strcmp(cmd, "DpiBye") == 0) {
       dFree(cmd);
@@ -1363,10 +1363,10 @@
 
    } else if (cmd && strcmp(cmd, "set_cookie") == 0) {
       dFree(cmd);
-      cookie = a_Dpip_get_attr(Buf, BufSize, "cookie");
-      host = a_Dpip_get_attr(Buf, BufSize, "host");
-      path = a_Dpip_get_attr(Buf, BufSize, "path");
-      p = a_Dpip_get_attr(Buf, BufSize, "port");
+      cookie = a_Dpip_get_attr_l(Buf, BufSize, "cookie");
+      host = a_Dpip_get_attr_l(Buf, BufSize, "host");
+      path = a_Dpip_get_attr_l(Buf, BufSize, "path");
+      p = a_Dpip_get_attr_l(Buf, BufSize, "port");
       port = strtol(p, NULL, 10);
       dFree(p);
 
@@ -1379,10 +1379,10 @@
 
    } else if (cmd && strcmp(cmd, "get_cookie") == 0) {
       dFree(cmd);
-      scheme = a_Dpip_get_attr(Buf, BufSize, "scheme");
-      host = a_Dpip_get_attr(Buf, BufSize, "host");
-      path = a_Dpip_get_attr(Buf, BufSize, "path");
-      p = a_Dpip_get_attr(Buf, BufSize, "port");
+      scheme = a_Dpip_get_attr_l(Buf, BufSize, "scheme");
+      host = a_Dpip_get_attr_l(Buf, BufSize, "host");
+      path = a_Dpip_get_attr_l(Buf, BufSize, "path");
+      p = a_Dpip_get_attr_l(Buf, BufSize, "port");
       port = strtol(p, NULL, 10);
       dFree(p);
 
--- a/dpi/datauri.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/datauri.c	Fri Jul 17 19:19:35 2009 -0400
@@ -291,8 +291,8 @@
    dpip_tag = sock_handler_read(sh);
    MSG("[%s]\n", dpip_tag);
 
-   cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
-   url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
+   cmd = a_Dpip_get_attr(dpip_tag, "cmd");
+   url = a_Dpip_get_attr(dpip_tag, "url");
    if (!cmd || !url) {
       MSG("Error, cmd=%s, url=%s\n", cmd, url);
       exit (EXIT_FAILURE);
--- a/dpi/downloads.cc	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/downloads.cc	Fri Jul 17 19:19:35 2009 -0400
@@ -899,7 +899,7 @@
    close(new_socket);
    _MSG("Received tag={%s}\n", tag->str);
 
-   if ((cmd = a_Dpip_get_attr(tag->str, (size_t)tag->len, "cmd")) == NULL) {
+   if ((cmd = a_Dpip_get_attr(tag->str, "cmd")) == NULL) {
       MSG("Failed to parse 'cmd' in {%s}\n", tag->str);
       goto end;
    }
@@ -911,11 +911,11 @@
       MSG("unknown command: '%s'. Aborting.\n", cmd);
       goto end;
    }
-   if (!(url = a_Dpip_get_attr(tag->str,(size_t)tag->len, "url"))){
+   if (!(url = a_Dpip_get_attr(tag->str, "url"))){
       MSG("Failed to parse 'url' in {%s}\n", tag->str);
       goto end;
    }
-   if (!(dl_dest = a_Dpip_get_attr(tag->str,(size_t)tag->len,"destination"))){
+   if (!(dl_dest = a_Dpip_get_attr(tag->str, "destination"))){
       MSG("Failed to parse 'destination' in {%s}\n", tag->str);
       goto end;
    }
--- a/dpi/file.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/file.c	Fri Jul 17 19:19:35 2009 -0400
@@ -854,12 +854,12 @@
    _MSG("dpip_tag={%s}\n", dpip_tag);
 
    if (dpip_tag) {
-      cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
+      cmd = a_Dpip_get_attr(dpip_tag, "cmd");
       if (cmd) {
          if (strcmp(cmd, "DpiBye") == 0) {
             DPIBYE = 1;
          } else {
-            url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
+            url = a_Dpip_get_attr(dpip_tag, "url");
             if (!url)
                MSG("file.dpi:: Failed to parse 'url'\n");
          }
--- a/dpi/ftp.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/ftp.c	Fri Jul 17 19:19:35 2009 -0400
@@ -288,8 +288,8 @@
       dpip_tag = sock_handler_read(sh);
    MSG("tag=[%s]\n", dpip_tag);
 
-   cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
-   url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
+   cmd = a_Dpip_get_attr(dpip_tag, "cmd");
+   url = a_Dpip_get_attr(dpip_tag, "url");
    if (!cmd || !url) {
       MSG("ERROR, cmd=%s, url=%s\n", cmd, url);
       exit (EXIT_FAILURE);
--- a/dpi/hello.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/hello.c	Fri Jul 17 19:19:35 2009 -0400
@@ -56,8 +56,8 @@
    dpip_tag = sock_handler_read(sh);
    MSG("tag = [%s]\n", dpip_tag);
 
-   cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
-   url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
+   cmd = a_Dpip_get_attr(dpip_tag, "cmd");
+   url = a_Dpip_get_attr(dpip_tag, "url");
 
 /*-- Dialog part */
 {
@@ -77,7 +77,7 @@
    MSG("tag = [%s]\n", dpip_tag2);
 
    /* Get "msg" value */
-   dialog_msg = a_Dpip_get_attr(dpip_tag2, strlen(dpip_tag2), "msg");
+   dialog_msg = a_Dpip_get_attr(dpip_tag2, "msg");
    choice_num = 0;
    if (dialog_msg)
       choice_num = *dialog_msg - '0';
--- a/dpi/https.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpi/https.c	Fri Jul 17 19:19:35 2009 -0400
@@ -108,7 +108,7 @@
 
    /* Read the dpi command from STDIN */
    dpip_tag = sock_handler_read(sh);
-   response = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "msg");
+   response = a_Dpip_get_attr(dpip_tag, "msg");
    response_number = (response) ? strtol (response, NULL, 10) : -1;
    dFree(dpip_tag);
    dFree(response);
@@ -194,12 +194,12 @@
 
       /*Get the network address and command to be used*/
       dpip_tag = sock_handler_read(sh);
-      cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
-      proxy_url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "proxy_url");
+      cmd = a_Dpip_get_attr(dpip_tag, "cmd");
+      proxy_url = a_Dpip_get_attr(dpip_tag, "proxy_url");
       proxy_connect =
-                  a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "proxy_connect");
-      url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
-      http_query = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "query");
+                  a_Dpip_get_attr(dpip_tag, "proxy_connect");
+      url = a_Dpip_get_attr(dpip_tag, "url");
+      http_query = a_Dpip_get_attr(dpip_tag, "query");
 
       if (cmd == NULL || url == NULL || http_query == NULL){
          MSG("***Value of cmd, url or http_query is NULL"
@@ -699,9 +699,9 @@
    MSG("{In https.filter.dpi}\n");
    MSG("no_ssl_support version\n");
 
-   cmd = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cmd");
-   url = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "url");
-   http_query = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "query");
+   cmd = a_Dpip_get_attr(dpip_tag, "cmd");
+   url = a_Dpip_get_attr(dpip_tag, "url");
+   http_query = a_Dpip_get_attr(dpip_tag, "query");
 
    MSG("{ cmd: %s}\n", cmd);
    MSG("{ url: %s}\n", url);
--- a/dpid/dpid.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpid/dpid.c	Fri Jul 17 19:19:35 2009 -0400
@@ -859,7 +859,7 @@
 {
    char *msg, *d_cmd;
 
-   msg = a_Dpip_get_attr(dpi_tag, strlen(dpi_tag), "msg");
+   msg = a_Dpip_get_attr(dpi_tag, "msg");
    if (msg == NULL) {
       ERRMSG("get_message", "failed to parse msg", 0);
       d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s",
--- a/dpid/main.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpid/main.c	Fri Jul 17 19:19:35 2009 -0400
@@ -155,7 +155,7 @@
       return (-1);
    }
 
-   cmd = a_Dpip_get_attr(dpi_tag, strlen(dpi_tag), "cmd");
+   cmd = a_Dpip_get_attr(dpi_tag, "cmd");
 
    if (cmd == NULL) {
       ERRMSG("get_command", "a_Dpip_get_attr", 0);
--- a/dpip/dpip.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpip/dpip.c	Fri Jul 17 19:19:35 2009 -0400
@@ -107,17 +107,18 @@
 }
 
 /*
- * Task: given a tag and an attribute name, return its value.
- *       (stuffing of ' is removed here)
+ * Task: given a tag, its size and an attribute name, return the
+ * attribute value (stuffing of ' is removed here).
+ *
  * Return value: the attribute value, or NULL if not present or malformed.
  */
-char *a_Dpip_get_attr(char *tag, size_t tagsize, const char *attrname)
+char *a_Dpip_get_attr_l(char *tag, size_t tagsize, const char *attrname)
 {
    uint_t i, n = 0, found = 0;
    char *p, *q, *start, *val = NULL;
    DpipTagParsingState state = SEEK_NAME;
 
-   if (!attrname || !*attrname)
+   if (!tag || !tagsize || !attrname || !*attrname)
       return NULL;
 
    for (i = 1; i < tagsize && !found; ++i) {
@@ -164,5 +165,14 @@
    return val;
 }
 
+/*
+ * Task: given a tag and an attribute name, return its value.
+ * Return value: the attribute value, or NULL if not present or malformed.
+ */
+char *a_Dpip_get_attr(char *tag, const char *attrname)
+{
+   return (tag ? a_Dpip_get_attr_l(tag, strlen(tag), attrname) : NULL);
+}
+
 /* ------------------------------------------------------------------------- */
 
--- a/dpip/dpip.h	Fri Jul 17 15:48:00 2009 -0400
+++ b/dpip/dpip.h	Fri Jul 17 19:19:35 2009 -0400
@@ -23,7 +23,8 @@
  *       (dpip character escaping is removed here)
  * Return value: the attribute value, or NULL if not present or malformed.
  */
-char *a_Dpip_get_attr(char *tag, size_t tagsize, const char *attrname);
+char *a_Dpip_get_attr(char *tag, const char *attrname);
+char *a_Dpip_get_attr_l(char *tag, size_t tagsize, const char *attrname);
 
 
 #ifdef __cplusplus
--- a/src/IO/dpi.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/src/IO/dpi.c	Fri Jul 17 19:19:35 2009 -0400
@@ -221,14 +221,14 @@
    tag = dStrndup(Tok, (size_t)conn->TokSize);
    _MSG("Dpi_parse_token: {%s}\n", tag);
 
-   cmd = a_Dpip_get_attr(Tok, conn->TokSize, "cmd");
+   cmd = a_Dpip_get_attr_l(Tok, conn->TokSize, "cmd");
    if (strcmp(cmd, "send_status_message") == 0) {
-      msg = a_Dpip_get_attr(Tok, conn->TokSize, "msg");
+      msg = a_Dpip_get_attr_l(Tok, conn->TokSize, "msg");
       a_Chain_fcb(OpSend, conn->InfoRecv, msg, cmd);
       dFree(msg);
 
    } else if (strcmp(cmd, "chat") == 0) {
-      msg = a_Dpip_get_attr(Tok, conn->TokSize, "msg");
+      msg = a_Dpip_get_attr_l(Tok, conn->TokSize, "msg");
       a_Chain_fcb(OpSend, conn->InfoRecv, msg, cmd);
       dFree(msg);
 
@@ -238,13 +238,13 @@
 
    } else if (strcmp(cmd, "start_send_page") == 0) {
       conn->Send2EOF = 1;
-      urlstr = a_Dpip_get_attr(Tok, conn->TokSize, "url");
+      urlstr = a_Dpip_get_attr_l(Tok, conn->TokSize, "url");
       a_Chain_fcb(OpSend, conn->InfoRecv, urlstr, cmd);
       dFree(urlstr);
-      /* TODO: a_Dpip_get_attr(Tok, conn->TokSize, "send_mode") */
+      /* TODO: a_Dpip_get_attr_l(Tok, conn->TokSize, "send_mode") */
 
    } else if (strcmp(cmd, "reload_request") == 0) {
-      urlstr = a_Dpip_get_attr(Tok, conn->TokSize, "url");
+      urlstr = a_Dpip_get_attr_l(Tok, conn->TokSize, "url");
       a_Chain_fcb(OpSend, conn->InfoRecv, urlstr, cmd);
       dFree(urlstr);
    }
@@ -531,9 +531,9 @@
 
       /* Parse reply */
       if (rdlen == 0 && rply) {
-         cmd = a_Dpip_get_attr(rply, (int)strlen(rply), "cmd");
+         cmd = a_Dpip_get_attr(rply, "cmd");
          if (strcmp(cmd, "send_data") == 0)
-            server_uds_name = a_Dpip_get_attr(rply, (int)strlen(rply), "msg");
+            server_uds_name = a_Dpip_get_attr(rply, "msg");
          dFree(cmd);
          dFree(rply);
       }
--- a/src/cookies.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/src/cookies.c	Fri Jul 17 19:19:35 2009 -0400
@@ -207,7 +207,7 @@
    query = dStrdup("Cookie2: $Version=\"1\"\r\n");
 
    if (dpip_tag != NULL) {
-      char *cookie = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cookie");
+      char *cookie = a_Dpip_get_attr(dpip_tag, "cookie");
       char *old_query = query;
       query = dStrconcat(old_query, cookie, NULL);
       dFree(old_query);
--- a/src/dpiapi.c	Fri Jul 17 15:48:00 2009 -0400
+++ b/src/dpiapi.c	Fri Jul 17 19:19:35 2009 -0400
@@ -61,12 +61,12 @@
 
    /* other options can be parsed the same way */
    dpip_tag_len = strlen(dpip_tag);
-   question = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "msg");
-   alt1 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt1");
-   alt2 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt2");
-   alt3 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt3");
-   alt4 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt4");
-   alt5 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt5");
+   question = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "msg");
+   alt1 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt1");
+   alt2 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt2");
+   alt3 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt3");
+   alt4 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt4");
+   alt5 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt5");
 
    ret = a_Dialog_choice5(question, alt1, alt2, alt3, alt4, alt5);
    /* As choice5 is modal, call the callback function directly. */