diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index 6a8ee5a9..1dea5882 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -173,9 +173,9 @@ m->init(); regn = cw_register_actions_capwap_ac(&capwap_actions); - struct outelem * l = cw_actionlist_out_get_mlist(capwap_actions.out,CW_MSG_DISCOVERY_RESPONSE); + //struct outelem * l = cw_actionlist_out_get_mlist(capwap_actions.out,CW_MSG_DISCOVERY_RESPONSE); - printf("List got: %p\n",l); + //printf("List got: %p\n",l); diff --git a/src/capwap/action.c b/src/capwap/action.c index 4b1e3f25..1c74ad36 100644 --- a/src/capwap/action.c +++ b/src/capwap/action.c @@ -62,12 +62,11 @@ static inline int cw_action_in_cmp(const void *elem1, const void *elem2) - +/* cw_action_fun_t cw_set_msg_end_callback(struct conn *conn, int capwap_state,int msg_id, cw_action_fun_t callback) { cw_action_in_t as; - /* prepare struct for search operation */ as.capwap_state = capwap_state; as.msg_id = msg_id; as.vendor_id = 0; @@ -88,12 +87,28 @@ cw_action_fun_t cw_set_msg_end_callback(struct conn *conn, } - +*/ cw_action_in_t *cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a) { - return cw_actionlist_add(t, a, sizeof(struct cw_action_in)); + int s = sizeof(struct cw_action_in); + + void *r = mavl_replace_data(t, a, s); + if (r) + return r; + + void *an = malloc(s); + if (!an) + return NULL; + + memcpy(an, a, s); + return mavl_add(t, an); + + + + +// return cw_actionlist_add(t, a, sizeof(struct cw_action_in)); } @@ -103,12 +118,19 @@ struct cw_action_in *cw_actionlist_in_get(cw_actionlist_in_t t, struct cw_action } +/** + * Create an action list for incomming messages + */ cw_actionlist_in_t cw_actionlist_in_create() { - return avltree_create(cw_action_in_cmp, free); + return mavl_create(cw_action_in_cmp, free); } - +/** + * Register actions in an action list for incommin messages + * @param t action list, where messaes will be registered + * @param actions an array of actions to reggister + */ int cw_actionlist_in_register_actions(cw_actionlist_in_t t, cw_action_in_t * actions) { int n=0; @@ -140,49 +162,22 @@ int cw_actionlist_out_register_actions(cw_actionlist_out_t t, cw_action_out_t * +struct outelem{ + uint32_t msg_id; + mlist_t * mlist; +}; + + + + /* * Compare function for actionlist_out_t lists */ static int cw_action_out_cmp(const void *elem1, const void *elem2) { - - - struct outelem *e1 = (struct outelem *) elem1; struct outelem *e2 = (struct outelem *) elem2; - - - //printf("cmp %d and %d\n",e1->msg_id,e2->msg_id); return e1->msg_id - e2->msg_id; - -/* - r = e1->msg_id - e2->msg_id; - if (r != 0) - return r; - - if (!e1->item_id && !e2->item_id){ - r=0; - } - else{ - if (!e1->item_id) { - r = strcmp(CW_ITEM_NONE, e2->item_id); - } - else if (!e2->item_id){ - r = strcmp(e1->item_id,CW_ITEM_NONE); - } - else{ - r = strcmp(e1->item_id, e2->item_id); - } - } - if (r != 0) - return r; -*/ - -/* - r = e1->vendor_id - e2->vendor_id; - if (r != 0) - return r; -*/ return 0; } @@ -259,7 +254,7 @@ cw_actionlist_out_t cw_actionlist_out_create() } -struct outelem * cw_actionlist_out_get_mlist(cw_actionlist_out_t t, int msg_id) +static struct outelem * cw_actionlist_out_get_outelem(cw_actionlist_out_t t, int msg_id) { struct outelem search; search.msg_id=msg_id; @@ -268,6 +263,14 @@ struct outelem * cw_actionlist_out_get_mlist(cw_actionlist_out_t t, int msg_id) } +mlist_t * cw_actionlist_out_get(cw_actionlist_out_t t,int msg_id) +{ + struct outelem *o = cw_actionlist_out_get_outelem(t,msg_id); + if (!o) + return NULL; + return o->mlist; +} + struct outelem * cw_actionlist_mout_create(int msg_id) { struct outelem * o = malloc(sizeof(struct outelem)); @@ -295,7 +298,7 @@ cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_o } */ - struct outelem * o = cw_actionlist_out_get_mlist(t,a->msg_id); + struct outelem * o = cw_actionlist_out_get_outelem(t,a->msg_id); if (!o){ @@ -327,7 +330,7 @@ cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_o } - +/* cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a, uint8_t capwap_state, uint32_t msg_id, @@ -351,6 +354,6 @@ cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a, } - +*/ diff --git a/src/capwap/action.h b/src/capwap/action.h index 6a6f11ba..41d3e15c 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -27,21 +27,32 @@ #include -#include "avltree.h" +#include "mavl.h" #include "conn.h" #include "mbag.h" #include "strheap.h" #include "intavltree.h" #include "item.h" +#include "mlist.h" + struct conn; -/* Generic functions and structs */ -void * cw_actionlist_add(struct avltree *t, void *a, size_t s); + +/** + * @file action.h + * @brief Header for actions + */ +/** + * @defgroup ACTION Action + * @{ + */ -/* Definitions for incomming messages */ +/** + * Definition of an action for incomming messages + */ struct cw_action_in{ uint32_t vendor_id; uint8_t proto; @@ -57,32 +68,24 @@ struct cw_action_in{ uint8_t mand; }; -typedef int(*cw_action_fun_t)(struct conn *,struct cw_action_in *,uint8_t*,int ,struct sockaddr *); +/** a handy type for incomming actions */ typedef struct cw_action_in cw_action_in_t; -extern cw_action_fun_t cw_set_msg_end_callback(struct conn *conn, - int capwap_state,int msg_id, cw_action_fun_t callback); +/** Definition of an action list for incomming messages */ +typedef mavl_t cw_actionlist_in_t; -typedef struct avltree * cw_actionlist_in_t; - extern cw_actionlist_in_t cw_actionlist_in_create(); extern cw_action_in_t * cw_actionlist_in_get(cw_actionlist_in_t t,cw_action_in_t *a); -extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a); +//extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a); extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions); -extern cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a, - uint8_t capwap_state, - uint32_t msg_id, - int (*fun) (struct conn * conn, - struct cw_action_in * a, uint8_t * data, - int len,struct sockaddr *from)); -cw_action_fun_t cw_set_msg_end_callback(struct conn *conn, - int capwap_state,int msg_id, cw_action_fun_t callback); -/* Definitions for outgoing messages */ +/** + * Definitioni of an action foroutgoing messages + * */ struct cw_action_out{ uint32_t msg_id; const char * item_id; @@ -93,30 +96,36 @@ struct cw_action_out{ int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); struct mbag_item *(*get)(struct conn *conn,struct cw_action_out *a); uint8_t mand; -// uint8_t itemtype; struct mbag_typedef * itemtype; - void *defval; -// int xopt; - }; - - - - - typedef struct cw_action_out cw_action_out_t; - typedef struct mavl *cw_actionlist_out_t; +extern cw_actionlist_out_t cw_actionlist_out_create(); +extern int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions); +mlist_t * cw_actionlist_out_get(cw_actionlist_out_t,int msg_id); + +//extern cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a); + +/** + * @} + */ + + + + + + + + extern cw_actionlist_out_t cw_actionlist_out_create(); extern cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a); extern int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions); -#define cw_actionlist_out_get(t,a) avltree_get(t,a); /** * Definition CAPWAP modes @@ -141,7 +150,6 @@ enum capwapmodes { }; -#include "mlist.h" @@ -160,11 +168,6 @@ struct cw_actiondef{ struct avltree * wbids; }; -struct outelem{ - uint32_t msg_id; - mlist_t * mlist; -}; - extern struct outelem * cw_actionlist_out_get_mlist(cw_actionlist_out_t t, int msg_id); diff --git a/src/capwap/cw_put_msg.c b/src/capwap/cw_put_msg.c index 9ccc200c..726d883f 100644 --- a/src/capwap/cw_put_msg.c +++ b/src/capwap/cw_put_msg.c @@ -53,26 +53,22 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout) uint8_t *dst = msgptr+8; + mlist_t *m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr)); - struct outelem *o; - - o = cw_actionlist_out_get_mlist(conn->actions->out,cw_get_msg_type(msgptr)); - - if (!o) + if (!m){ + cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.", + as.msg_id,cw_strmsg(as.msg_id)); return -1; - mlist_t *m; - m=o->mlist; + } + struct mlist_elem *e; int len = 0; for (e=m->list; e; e=e->next) { - printf("E: %p\n",e); cw_action_out_t *ae=(cw_action_out_t*)e->data; - - DBGX("Put %d %i %p\n",ae->msg_id,ae->elem_id,ae->item_id); DBGX("Elem ID %s",ae->item_id); if ( ae->item_id ) { diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index 3e1527fe..dacd29b2 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -142,7 +142,6 @@ static cw_action_out_t actions_out[]={ } , - /* Discovery Response Elem AC_NAME */ { .msg_id = CW_MSG_DISCOVERY_RESPONSE, @@ -153,6 +152,7 @@ static cw_action_out_t actions_out[]={ .mand = 1 } , + {0,0} };