This patch changes the method of retrieving the parameters from
the web service URL. Instead of taking index of the parameter as
the argument, duda_param_get function now takes a char *, specifying
the name of the parameter.
In terms of performance it will be a bit slower beacuse of an
increased string comparision loop to find the parameter name, but
is a good modification for ease of access of parameters.
---
plugins/duda/duda_api.h | 2 +-
plugins/duda/duda_param.c | 32 +++++++++++++++++++++++++++-----
plugins/duda/duda_param.h | 2 +-
plugins/duda/webservice.c | 1 +
4 files changed, 30 insertions(+), 7 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/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