---
 plugins/duda/duda_api.h      |    2 +-
 plugins/duda/duda_param.c    |   32 +++++++++++++++++++++++++++-----
 plugins/duda/duda_param.h    |    2 +-
 plugins/duda/example/hello.c |    6 ++++--
 plugins/duda/webservice.c    |    1 +
 5 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/plugins/duda/duda_api.h b/plugins/duda/duda_api.h
index b75ba46..a6abec5 100644
--- a/plugins/duda/duda_api.h
+++ b/plugins/duda/duda_api.h
@@ -165,7 +165,7 @@ struct duda_api_debug {
 
 /* PARAMS object: params->() */
 struct duda_api_params{
-    char *(*get) (duda_request_t *, short int);
+    char *(*get) (duda_request_t *, char *);
     short int (*count) (duda_request_t *);
     short int (*len) (duda_request_t *, short int);
 };
diff --git a/plugins/duda/duda_param.c b/plugins/duda/duda_param.c
index 82cf656..438d912 100644
--- a/plugins/duda/duda_param.c
+++ b/plugins/duda/duda_param.c
@@ -22,15 +22,37 @@
 #include "MKPlugin.h"
 #include "duda.h"
 
-/* Return ith parameter */
-char *duda_param_get(duda_request_t *dr, short int idx)
+/* Return value of query */
+char *duda_param_get(duda_request_t *dr, char *query)
 {
-    if (idx >= dr->n_params) {
+    if (!query) {
+		PLUGIN_TRACE("Null Parameter Query");
         return NULL;
     }
+    int idx = -1;
+    short int valid = MK_FALSE;
+    duda_method_t *i_method = dr->_method;
+    duda_param_t *entry_param;
+    struct mk_list *head_params;
+    
+    mk_list_foreach(head_params, &i_method->params) {
+        entry_param = mk_list_entry(head_params, struct duda_param, _head);
+        idx++;
+        if (entry_param->name == query) {
+			valid = MK_TRUE;
+			break;
+		}
+	}
 
-    return mk_api->str_copy_substr(dr->params[idx].data, 0,
-                                   (int) dr->params[idx].len);
+    if(dr->params[idx].len > entry_param->max_len) {
+		PLUGIN_TRACE("Max value length:%d", entry_param->max_len);
+		return NULL;
+	}
+	if(valid) {
+	    return mk_api->str_copy_substr(dr->params[idx].data, 0,
+                                       (int) dr->params[idx].len);
+	}
+	return NULL;
 }
 
 /* Return the total no of parameters */
diff --git a/plugins/duda/duda_param.h b/plugins/duda/duda_param.h
index 3df4246..66c9118 100644
--- a/plugins/duda/duda_param.h
+++ b/plugins/duda/duda_param.h
@@ -20,6 +20,6 @@
  */
 
 
-char *duda_param_get(duda_request_t *dr, short int i);
+char *duda_param_get(duda_request_t *dr, char *query);
 short int duda_param_count(duda_request_t *dr);
 short int duda_param_len(duda_request_t *dr, short int idx);
diff --git a/plugins/duda/example/hello.c b/plugins/duda/example/hello.c
index bb5b19e..33acebd 100644
--- a/plugins/duda/example/hello.c
+++ b/plugins/duda/example/hello.c
@@ -12,6 +12,8 @@
 #define PARSE "parse"
 #define FORMATTED "formatted"
 #define UNFORMATTED "unformatted"
+#define PARAM1 "action"
+#define PARAM2 "format"
 
 DUDA_REGISTER("Service Example", "service");
 
@@ -155,9 +157,9 @@ void cb_json_second(duda_request_t *dr){
     response->http_header(dr, "Content-Type: text/plain", 24);
 
     pnumber = 0;
-    pvalue1 = params->get(dr, pnumber);
+    pvalue1 = params->get(dr, PARAM1);
     pnumber = 1;
-    pvalue2 = params->get(dr, pnumber);
+    pvalue2 = params->get(dr, PARAM2);
     
     if(!pvalue1 || !pvalue2) {
         response->body_write(dr, INCORRECT_PARAMETERS, sizeof(INCORRECT_PARAMETERS) - 1);
diff --git a/plugins/duda/webservice.c b/plugins/duda/webservice.c
index 963c67e..87f5283 100644
--- a/plugins/duda/webservice.c
+++ b/plugins/duda/webservice.c
@@ -71,6 +71,7 @@ duda_param_t *duda_param_new(char *uid, short int max_len)
     duda_param_t *param;
 
     param = mk_api->mem_alloc(sizeof(duda_param_t));
+    param->name = uid;
     param->max_len = max_len;
 
     return param;
_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to