new mavl is working now
FossilOrigin-Name: 65a4eefffea57509c0d7fd573e53b15bf4a730ce297b7db182aaac796ea92448
This commit is contained in:
parent
e4d65ef470
commit
4171d208d0
@ -25,6 +25,8 @@
|
|||||||
</VirtualDirectory>
|
</VirtualDirectory>
|
||||||
<Description/>
|
<Description/>
|
||||||
<Dependencies/>
|
<Dependencies/>
|
||||||
|
<Dependencies Name="Debug"/>
|
||||||
|
<Dependencies Name="Release"/>
|
||||||
<Settings Type="Executable">
|
<Settings Type="Executable">
|
||||||
<GlobalSettings>
|
<GlobalSettings>
|
||||||
<Compiler Options="" C_Options="" Assembler="">
|
<Compiler Options="" C_Options="" Assembler="">
|
||||||
@ -43,7 +45,7 @@
|
|||||||
<ResourceCompiler Options="" Required="no"/>
|
<ResourceCompiler Options="" Required="no"/>
|
||||||
<General OutputFile="" IntermediateDirectory="./" Command="$(WorkspacePath)/src/ac/actube" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(WorkspacePath)/src/ac/" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
|
<General OutputFile="" IntermediateDirectory="./" Command="$(WorkspacePath)/src/ac/actube" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(WorkspacePath)/src/ac/" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
|
||||||
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
|
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
|
||||||
<![CDATA[]]>
|
<![CDATA[LD_LIBRARY_PATH=../../lib]]>
|
||||||
</Environment>
|
</Environment>
|
||||||
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
|
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
|
||||||
<DebuggerSearchPaths/>
|
<DebuggerSearchPaths/>
|
||||||
@ -112,6 +114,4 @@
|
|||||||
</Completion>
|
</Completion>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
</Settings>
|
</Settings>
|
||||||
<Dependencies Name="Debug"/>
|
|
||||||
<Dependencies Name="Release"/>
|
|
||||||
</CodeLite_Project>
|
</CodeLite_Project>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CodeLite_Workspace Name="actube" Database="">
|
<CodeLite_Workspace Name="actube" Database="">
|
||||||
<Project Name="ac" Path="ac.project" Active="No"/>
|
<Project Name="ac" Path="ac.project" Active="Yes"/>
|
||||||
<Project Name="wtp" Path="wtp.project" Active="No"/>
|
<Project Name="wtp" Path="wtp.project" Active="No"/>
|
||||||
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
|
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
|
||||||
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
|
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
|
||||||
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
|
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
|
||||||
<Project Name="libcw" Path="libcw.project" Active="Yes"/>
|
<Project Name="libcw" Path="libcw.project" Active="No"/>
|
||||||
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
|
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
|
||||||
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
|
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
|
||||||
<BuildMatrix>
|
<BuildMatrix>
|
||||||
|
@ -224,7 +224,6 @@
|
|||||||
<File Name="src/cw/fragman.c"/>
|
<File Name="src/cw/fragman.c"/>
|
||||||
<File Name="src/cw/lwmsg.h"/>
|
<File Name="src/cw/lwmsg.h"/>
|
||||||
<File Name="src/cw/cw_check_missing_mand.c"/>
|
<File Name="src/cw/cw_check_missing_mand.c"/>
|
||||||
<File Name="src/cw/cw_strnelem.c"/>
|
|
||||||
<File Name="src/cw/format_dot11_fc.c"/>
|
<File Name="src/cw/format_dot11_fc.c"/>
|
||||||
<File Name="src/cw/wtpinfo_lwreadelem_wtp_descriptor.c"/>
|
<File Name="src/cw/wtpinfo_lwreadelem_wtp_descriptor.c"/>
|
||||||
<File Name="src/cw/dbg_strings.c"/>
|
<File Name="src/cw/dbg_strings.c"/>
|
||||||
@ -289,8 +288,6 @@
|
|||||||
<File Name="src/cw/capwap_strings_state.c"/>
|
<File Name="src/cw/capwap_strings_state.c"/>
|
||||||
<File Name="src/cw/cw_out_radio_info.c"/>
|
<File Name="src/cw/cw_out_radio_info.c"/>
|
||||||
<File Name="src/cw/capwap_items.c"/>
|
<File Name="src/cw/capwap_items.c"/>
|
||||||
<File Name="src/cw/message_set.c"/>
|
|
||||||
<File Name="src/cw/message_set.h"/>
|
|
||||||
<File Name="src/mod/cisco/mod_cisco.h"/>
|
<File Name="src/mod/cisco/mod_cisco.h"/>
|
||||||
<File Name="src/cw/cw_filename.c"/>
|
<File Name="src/cw/cw_filename.c"/>
|
||||||
<File Name="src/cw/mdata.h"/>
|
<File Name="src/cw/mdata.h"/>
|
||||||
@ -298,33 +295,33 @@
|
|||||||
<File Name="src/cw/mdata_elem_new.c"/>
|
<File Name="src/cw/mdata_elem_new.c"/>
|
||||||
<File Name="src/cw/cw_type_byte.c"/>
|
<File Name="src/cw/cw_type_byte.c"/>
|
||||||
<File Name="src/cw/cw_type_word.c"/>
|
<File Name="src/cw/cw_type_word.c"/>
|
||||||
<File Name="src/cw/cw_types.h"/>
|
|
||||||
<File Name="src/cw/cw_type_dword.c"/>
|
<File Name="src/cw/cw_type_dword.c"/>
|
||||||
<File Name="src/cw/mavl_cmp_dword.c"/>
|
|
||||||
<File Name="src/cw/mavl_free_bin.c"/>
|
|
||||||
<File Name="src/cw/debug.h"/>
|
<File Name="src/cw/debug.h"/>
|
||||||
<File Name="src/cw/debug.c"/>
|
<File Name="src/cw/debug.c"/>
|
||||||
<File Name="src/cw/mavl_get_ptr.c"/>
|
<File Name="src/cw/mavl_get_ptr.c"/>
|
||||||
<File Name="src/cw/mavl_add_strdup.c"/>
|
|
||||||
<File Name="src/cw/mavl_cmp_str.c"/>
|
|
||||||
<File Name="src/cw/mavliter_init.c"/>
|
<File Name="src/cw/mavliter_init.c"/>
|
||||||
<File Name="src/cw/mavl_add_ptr.c"/>
|
<File Name="src/cw/mavl_add_ptr.c"/>
|
||||||
<File Name="src/cw/cw_format_dump.c"/>
|
<File Name="src/cw/cw_format_dump.c"/>
|
||||||
<File Name="src/cw/cw_format_pkt_hdr.c"/>
|
<File Name="src/cw/cw_format_pkt_hdr.c"/>
|
||||||
<File Name="src/cw/mavl_cmp_kv.c"/>
|
|
||||||
<File Name="src/cw/mavl_add_kv_byte.c"/>
|
|
||||||
<File Name="src/cw/cw_types_mavl_delete.c"/>
|
<File Name="src/cw/cw_types_mavl_delete.c"/>
|
||||||
<File Name="src/cw/cw_format_scan_hex_bytes.c"/>
|
<File Name="src/cw/cw_format_scan_hex_bytes.c"/>
|
||||||
<File Name="src/cw/cw_dbg_elem.c"/>
|
<File Name="src/cw/cw_dbg_elem.c"/>
|
||||||
<File Name="src/cw/cw_kvstore_mavl_delete.c"/>
|
|
||||||
<File Name="src/cw/cw_format_version.c"/>
|
<File Name="src/cw/cw_format_version.c"/>
|
||||||
<File Name="src/cw/cw_strdup.c"/>
|
<File Name="src/cw/cw_strdup.c"/>
|
||||||
<File Name="src/cw/kvstore.h"/>
|
|
||||||
<File Name="src/cw/cw_kvstore_add.c"/>
|
|
||||||
<File Name="src/cw/cw_types_del_null.c"/>
|
|
||||||
<File Name="src/cw/cw_type_bstr16.c"/>
|
<File Name="src/cw/cw_type_bstr16.c"/>
|
||||||
<File Name="src/cw/cw_process_element.c"/>
|
<File Name="src/cw/cw_process_element.c"/>
|
||||||
<File Name="src/cw/cw_result_is_ok.c"/>
|
<File Name="src/cw/cw_result_is_ok.c"/>
|
||||||
|
<File Name="src/cw/mavliter_get.c"/>
|
||||||
|
<File Name="src/cw/kvt.h"/>
|
||||||
|
<File Name="src/cw/cw_kvt_mavlcmp.c"/>
|
||||||
|
<File Name="src/cw/cw_kvt_mavldel.c"/>
|
||||||
|
<File Name="src/cw/mavliter_get_ptr.c"/>
|
||||||
|
<File Name="src/cw/mavl_cmpstr.c"/>
|
||||||
|
<File Name="src/cw/mavl_freeptr.c"/>
|
||||||
|
<File Name="src/cw/msgset.c"/>
|
||||||
|
<File Name="src/cw/msget.h"/>
|
||||||
|
<File Name="src/cw/mavl_replace.c"/>
|
||||||
|
<File Name="src/cw/cw_kvt_add.c"/>
|
||||||
</VirtualDirectory>
|
</VirtualDirectory>
|
||||||
</VirtualDirectory>
|
</VirtualDirectory>
|
||||||
<Description/>
|
<Description/>
|
||||||
|
180
src/ac/ac_main.c
180
src/ac/ac_main.c
@ -73,15 +73,18 @@ static int parse_args(int argc, char *argv[])
|
|||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
int o;
|
int o;
|
||||||
|
|
||||||
while ( (o = getopt_long (argc, argv, "v", long_options, &option_index)) != -1) {
|
while ( (o = getopt_long (argc, argv, "v", long_options, &option_index)) != -1) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf ("AC-Tube 0.01, %s\n", SYS_ARCH);
|
printf ("AC-Tube 0.01, %s\n", SYS_ARCH);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,11 +97,166 @@ extern struct cw_Mod * cw_get_mod_ac(const char *name);
|
|||||||
|
|
||||||
extern void test_sets();
|
extern void test_sets();
|
||||||
#include "cw/file.h"
|
#include "cw/file.h"
|
||||||
#include "cw/cw_types.h"
|
#include "cw/kvt.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct mykv {
|
||||||
|
int key;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
int mycmp (void *e1, void *e2)
|
||||||
|
{
|
||||||
|
struct mykv * k1 = e1;
|
||||||
|
struct mykv * k2 = e2;
|
||||||
|
|
||||||
|
//printf("My CMP: %d and %d\n", k1->key, k2->key);
|
||||||
|
|
||||||
|
if (k1->key > k2->key)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (k1->key < k2->key)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mavl_walk (struct mavlnode * node)
|
||||||
|
{
|
||||||
|
struct mykv * kv;
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
printf ("\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
kv = mavlnode_dataptr (node);
|
||||||
|
printf ("KV %d\n", kv->key);
|
||||||
|
|
||||||
|
printf ("go left:");
|
||||||
|
mavl_walk (node->left);
|
||||||
|
printf ("go right:");
|
||||||
|
mavl_walk (node->right);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int stcmp (const void * sa1, const void *sa2)
|
||||||
|
{
|
||||||
|
const char **s1 = sa1;
|
||||||
|
const char **s2 = sa2;
|
||||||
|
int rc;
|
||||||
|
rc = strcmp (*s1, *s2);
|
||||||
|
|
||||||
|
printf ("CMP %s, %s = %d\n", *s1, *s2, rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
mavl_t tree;
|
||||||
|
int i;
|
||||||
|
mavliter_t it;
|
||||||
|
|
||||||
|
|
||||||
|
/*tree = mavl_create_ptr( (int(*)(const void*,const void*))strcmp,free);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
tree = mavl_create_ptr(mycmp,NULL);
|
||||||
|
|
||||||
|
struct mykv * mdata;
|
||||||
|
|
||||||
|
|
||||||
|
mdata = malloc(sizeof(struct mykv));
|
||||||
|
mdata->key=14;
|
||||||
|
mdata->value=15;
|
||||||
|
mavl_add_ptr(tree, mdata);
|
||||||
|
|
||||||
|
mdata = malloc(sizeof(struct mykv));
|
||||||
|
mdata->key=16;
|
||||||
|
mdata->value=17;
|
||||||
|
mavl_add_ptr(tree, mdata);
|
||||||
|
|
||||||
|
mdata = malloc(sizeof(struct mykv));
|
||||||
|
mdata->key=12;
|
||||||
|
mdata->value=13;
|
||||||
|
mavl_add_ptr(tree, mdata);
|
||||||
|
|
||||||
|
mavliter_init(&it,tree);
|
||||||
|
mavliter_foreach(&it){
|
||||||
|
mdata = mavliter_get_ptr(&it);
|
||||||
|
printf("MAVLIT: %d %d\n",mdata->key,mdata->value);
|
||||||
|
|
||||||
|
struct mykv search;
|
||||||
|
search.key=mdata->key;
|
||||||
|
mdata = mavl_get_ptr(tree,&search);
|
||||||
|
printf("Search T: %d %d\n",mdata->key,mdata->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (tree==NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
tree = mavl_create_str();
|
||||||
|
|
||||||
|
mavl_add_str(tree,cw_strdup("7u83"));
|
||||||
|
mavl_add_str(tree,cw_strdup("Herre"));
|
||||||
|
mavl_add_str(tree,cw_strdup("Tube"));
|
||||||
|
mavl_add_str(tree,cw_strdup("Tobias"));
|
||||||
|
printf("Count: %d\n", mavl_get_count(tree));
|
||||||
|
mavliter_init(&it,tree);
|
||||||
|
|
||||||
|
mavliter_foreach(&it){
|
||||||
|
|
||||||
|
printf("iterWert %s\n",mavliter_get_str(&it));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
tree = mavl_create (mycmp, NULL, sizeof (struct mykv));
|
||||||
|
|
||||||
|
struct mykv nwert;
|
||||||
|
int result;
|
||||||
|
struct mykv * mr;
|
||||||
|
|
||||||
|
nwert.key = 7;
|
||||||
|
nwert.value = 777;
|
||||||
|
mr = mavl_add_exists (tree, &nwert, &result);
|
||||||
|
printf ("7Result %d: %d %d\n", result, mr->key, mr->value);
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
//cw_rand(&nwert.key,sizeof(nwert.key));
|
||||||
|
// printf("Addwert: %u\n",nwert.key);
|
||||||
|
// printf("add %u\n", i);
|
||||||
|
nwert.key = 9 - i;
|
||||||
|
nwert.value = 100 + i;
|
||||||
|
result=0;
|
||||||
|
mr = mavl_add_exists (tree, &nwert, &result);
|
||||||
|
printf ("Result %d: %d %d\n", result, mr->key, mr->value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mavliter_init (&it, tree);
|
||||||
|
|
||||||
|
mavliter_foreach (&it) {
|
||||||
|
struct mykv *kv;
|
||||||
|
kv = mavliter_get (&it);
|
||||||
|
printf ("iterWert %u\n", kv->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit (0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* mavl_t kv;
|
/* mavl_t kv;
|
||||||
mavliter_t kviter;
|
mavliter_t kviter;
|
||||||
uint8_t bytes[] = { 99,4,5,7 };
|
uint8_t bytes[] = { 99,4,5,7 };
|
||||||
@ -241,6 +399,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
ac_global_init();
|
ac_global_init();
|
||||||
|
|
||||||
if (!socklist_init())
|
if (!socklist_init())
|
||||||
goto errX;
|
goto errX;
|
||||||
|
|
||||||
@ -287,6 +446,7 @@ int ac_run()
|
|||||||
* good unicast reply socket */
|
* good unicast reply socket */
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < conf_listen_addrs_len; i++) {
|
for (i = 0; i < conf_listen_addrs_len; i++) {
|
||||||
char addr[100];
|
char addr[100];
|
||||||
char port[50];
|
char port[50];
|
||||||
@ -320,9 +480,11 @@ int ac_run()
|
|||||||
socklist_add_multicast (conf_mcast_groups[i], conf_control_port,
|
socklist_add_multicast (conf_mcast_groups[i], conf_control_port,
|
||||||
AC_PROTO_CAPWAP);
|
AC_PROTO_CAPWAP);
|
||||||
#ifdef WITH_LWAPP
|
#ifdef WITH_LWAPP
|
||||||
|
|
||||||
if (conf_lwapp)
|
if (conf_lwapp)
|
||||||
socklist_add_multicast (conf_mcast_groups[i], conf_lw_control_port,
|
socklist_add_multicast (conf_mcast_groups[i], conf_lw_control_port,
|
||||||
AC_PROTO_LWAPP);
|
AC_PROTO_LWAPP);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -336,10 +498,12 @@ int ac_run()
|
|||||||
|
|
||||||
socklist_add_broadcast (addr, port, proto);
|
socklist_add_broadcast (addr, port, proto);
|
||||||
#ifdef WITH_LWAPP
|
#ifdef WITH_LWAPP
|
||||||
|
|
||||||
// printf("Adding %d\n",socklist_len);
|
// printf("Adding %d\n",socklist_len);
|
||||||
if (conf_lwapp)
|
if (conf_lwapp)
|
||||||
socklist_add_broadcast (conf_bcast_addrs[i], conf_lw_control_port,
|
socklist_add_broadcast (conf_bcast_addrs[i], conf_lw_control_port,
|
||||||
AC_PROTO_LWAPP);
|
AC_PROTO_LWAPP);
|
||||||
|
|
||||||
// printf ("SI %d, PROTO: %d\n",socklist_len-1,socklist[socklist_len-1].ac_proto);
|
// printf ("SI %d, PROTO: %d\n",socklist_len-1,socklist[socklist_len-1].ac_proto);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -355,12 +519,16 @@ int ac_run()
|
|||||||
fd_set fset;
|
fd_set fset;
|
||||||
int max = 0;
|
int max = 0;
|
||||||
FD_ZERO (&fset);
|
FD_ZERO (&fset);
|
||||||
|
|
||||||
for (i = 0; i < socklist_len; i++) {
|
for (i = 0; i < socklist_len; i++) {
|
||||||
FD_SET (socklist[i].sockfd, &fset);
|
FD_SET (socklist[i].sockfd, &fset);
|
||||||
|
|
||||||
if (socklist[i].sockfd > max)
|
if (socklist[i].sockfd > max)
|
||||||
max = socklist[i].sockfd;
|
max = socklist[i].sockfd;
|
||||||
|
|
||||||
if (socklist[i].data_sockfd) {
|
if (socklist[i].data_sockfd) {
|
||||||
FD_SET (socklist[i].data_sockfd, &fset);
|
FD_SET (socklist[i].data_sockfd, &fset);
|
||||||
|
|
||||||
if (socklist[i].sockfd > max)
|
if (socklist[i].sockfd > max)
|
||||||
max = socklist[i].sockfd;
|
max = socklist[i].sockfd;
|
||||||
}
|
}
|
||||||
@ -368,6 +536,7 @@ int ac_run()
|
|||||||
|
|
||||||
/* wait for an event */
|
/* wait for an event */
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
while ( (n = select (max + 1, &fset, NULL, NULL, NULL)) < 0) {
|
while ( (n = select (max + 1, &fset, NULL, NULL, NULL)) < 0) {
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
return n;
|
return n;
|
||||||
@ -424,19 +593,23 @@ void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
|||||||
cw_dbg (DBG_X, "Dataman list locked, now gotted");
|
cw_dbg (DBG_X, "Dataman list locked, now gotted");
|
||||||
|
|
||||||
cw_dbg (DBG_INFO, "Packet for dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
|
cw_dbg (DBG_INFO, "Packet for dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
|
||||||
|
|
||||||
if (!dm) {
|
if (!dm) {
|
||||||
cw_dbg (DBG_INFO, "No dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
|
cw_dbg (DBG_INFO, "No dataman %s,%d", sock_addr2str_p (addr, sock_buf), socklist[index].data_sockfd);
|
||||||
dm = dataman_create (socklist[index].data_sockfd, addr);
|
dm = dataman_create (socklist[index].data_sockfd, addr);
|
||||||
|
|
||||||
if (!dm) {
|
if (!dm) {
|
||||||
cw_log (LOG_ERR, "Can't create dataman for packet from %s", sock_addr2str_p (addr, sock_buf));
|
cw_log (LOG_ERR, "Can't create dataman for packet from %s", sock_addr2str_p (addr, sock_buf));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dataman_list_add (dm);
|
dataman_list_add (dm);
|
||||||
|
|
||||||
dataman_start (dm);
|
dataman_start (dm);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dataman_list_unlock();
|
dataman_list_unlock();
|
||||||
|
|
||||||
dataman_add_packet (dm, buffer, len);
|
dataman_add_packet (dm, buffer, len);
|
||||||
@ -451,6 +624,7 @@ void process_cw_data_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
|||||||
printf ("Data packet received len = %d\n", len);
|
printf ("Data packet received len = %d\n", len);
|
||||||
exit (0);
|
exit (0);
|
||||||
struct wtpman *wtpman = wtplist_get (addr);
|
struct wtpman *wtpman = wtplist_get (addr);
|
||||||
|
|
||||||
if (!wtpman) {
|
if (!wtpman) {
|
||||||
cw_dbg (DBG_PKT_ERR, "Discarding packet on data channel from %s - No wtpman found.", sock_addr2str (addr, sock_buf));
|
cw_dbg (DBG_PKT_ERR, "Discarding packet on data channel from %s - No wtpman found.", sock_addr2str (addr, sock_buf));
|
||||||
return;
|
return;
|
||||||
@ -478,6 +652,7 @@ void process_cw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
|||||||
|
|
||||||
wtplist_lock();
|
wtplist_lock();
|
||||||
struct wtpman *wtpman = wtplist_get (addr);
|
struct wtpman *wtpman = wtplist_get (addr);
|
||||||
|
|
||||||
if (!wtpman) {
|
if (!wtpman) {
|
||||||
|
|
||||||
wtpman = wtpman_create (index, addr);
|
wtpman = wtpman_create (index, addr);
|
||||||
@ -537,6 +712,7 @@ void process_lw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
|||||||
|
|
||||||
wtplist_lock();
|
wtplist_lock();
|
||||||
struct wtpman *wtpman = wtplist_get (addr);
|
struct wtpman *wtpman = wtplist_get (addr);
|
||||||
|
|
||||||
if (!wtpman) {
|
if (!wtpman) {
|
||||||
|
|
||||||
wtpman = wtpman_create (index, addr);
|
wtpman = wtpman_create (index, addr);
|
||||||
@ -557,6 +733,7 @@ void process_lw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer,
|
|||||||
|
|
||||||
//wtpman_lw_start(wtpman);
|
//wtpman_lw_start(wtpman);
|
||||||
}
|
}
|
||||||
|
|
||||||
//wtpman_lw_addpacket(wtpman,buffer,len);
|
//wtpman_lw_addpacket(wtpman,buffer,len);
|
||||||
wtplist_unlock();
|
wtplist_unlock();
|
||||||
}
|
}
|
||||||
@ -571,6 +748,7 @@ void process_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int
|
|||||||
case AC_PROTO_CAPWAP:
|
case AC_PROTO_CAPWAP:
|
||||||
process_cw_ctrl_packet (index, addr, buffer, len);
|
process_cw_ctrl_packet (index, addr, buffer, len);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case AC_PROTO_LWAPP:
|
case AC_PROTO_LWAPP:
|
||||||
process_lw_ctrl_packet (index, addr, buffer, len);
|
process_lw_ctrl_packet (index, addr, buffer, len);
|
||||||
return;
|
return;
|
||||||
|
141
src/ac/conf.c
141
src/ac/conf.c
@ -38,7 +38,6 @@ uint8_t conf_macaddress_len = 0;
|
|||||||
|
|
||||||
long conf_strict_capwap = 1;
|
long conf_strict_capwap = 1;
|
||||||
long conf_strict_headers = 0;
|
long conf_strict_headers = 0;
|
||||||
//char *conf_capwap_mode_str = NULL;
|
|
||||||
int conf_capwap_mode = CW_MODE_CAPWAP;
|
int conf_capwap_mode = CW_MODE_CAPWAP;
|
||||||
|
|
||||||
|
|
||||||
@ -79,8 +78,6 @@ char *conf_sslkeypass = NULL;
|
|||||||
char *conf_sslcipher = NULL;
|
char *conf_sslcipher = NULL;
|
||||||
char *conf_dtls_psk = NULL;
|
char *conf_dtls_psk = NULL;
|
||||||
|
|
||||||
//char * conf_ac_hardware_version=NULL;
|
|
||||||
//char * conf_ac_software_version=NULL;
|
|
||||||
int conf_security = 0;
|
int conf_security = 0;
|
||||||
long conf_vendor_id = CONF_DEFAULT_VENDOR_ID;
|
long conf_vendor_id = CONF_DEFAULT_VENDOR_ID;
|
||||||
|
|
||||||
@ -92,11 +89,6 @@ bstr_t conf_cisco_hardware_version = NULL;
|
|||||||
bstr_t conf_cisco_software_version = NULL;
|
bstr_t conf_cisco_software_version = NULL;
|
||||||
|
|
||||||
|
|
||||||
//int conf_hardware_version_len=0;
|
|
||||||
|
|
||||||
//int conf_software_version_len=0;
|
|
||||||
|
|
||||||
|
|
||||||
int conf_use_loopback = 0;
|
int conf_use_loopback = 0;
|
||||||
|
|
||||||
long conf_debug_level = -1;
|
long conf_debug_level = -1;
|
||||||
@ -140,6 +132,8 @@ static int init_acname()
|
|||||||
|
|
||||||
static int init_acid()
|
static int init_acid()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
char *s;
|
||||||
|
|
||||||
if (conf_acid != NULL)
|
if (conf_acid != NULL)
|
||||||
return 1;
|
return 1;
|
||||||
@ -165,11 +159,11 @@ static int init_acid()
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
conf_acid = malloc(2 * conf_macaddress_len + 1);
|
conf_acid = malloc(2 * conf_macaddress_len + 1);
|
||||||
char *s = conf_acid;
|
s = conf_acid;
|
||||||
|
|
||||||
for (i = 0; i < conf_macaddress_len; i++) {
|
for (i = 0; i < conf_macaddress_len; i++) {
|
||||||
s += sprintf(s, "%02X", conf_macaddress[i]);
|
s += sprintf(s, "%02X", conf_macaddress[i]);
|
||||||
@ -178,10 +172,13 @@ static int init_acid()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int init_dtls()
|
static int init_dtls()
|
||||||
{
|
{
|
||||||
if (conf_dtls_psk != NULL) {
|
if (conf_dtls_psk != NULL) {
|
||||||
|
/*
|
||||||
// conf_security=CW_SECURITY_FLAGS_S;
|
// conf_security=CW_SECURITY_FLAGS_S;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -260,17 +257,21 @@ static int init_control_port()
|
|||||||
|
|
||||||
static int init_listen_addrs()
|
static int init_listen_addrs()
|
||||||
{
|
{
|
||||||
|
struct ifaddrs *ifap, *ifa;
|
||||||
|
int rc;
|
||||||
|
int ctr;
|
||||||
|
|
||||||
if (conf_listen_addrs != 0)
|
if (conf_listen_addrs != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
struct ifaddrs *ifap, *ifa;
|
|
||||||
|
|
||||||
int rc = getifaddrs(&ifap);
|
|
||||||
|
rc = getifaddrs(&ifap);
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* count the addresses */
|
/* count the addresses */
|
||||||
int ctr = 0;
|
ctr = 0;
|
||||||
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
|
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
|
||||||
if (!ifa->ifa_addr)
|
if (!ifa->ifa_addr)
|
||||||
continue;
|
continue;
|
||||||
@ -307,8 +308,7 @@ static int init_listen_addrs()
|
|||||||
|
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
|
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4) {
|
||||||
sock_addrtostr(ifa->ifa_addr, str, 100,0);
|
sock_addrtostr(ifa->ifa_addr, str, 100,0);
|
||||||
// printf("The converter has %s\n",str);
|
|
||||||
// *strchr(str, ':') = 0;
|
|
||||||
conf_listen_addrs[ctr] =
|
conf_listen_addrs[ctr] =
|
||||||
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
|
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
|
||||||
(uint8_t *) str, strlen(str));
|
(uint8_t *) str, strlen(str));
|
||||||
@ -346,6 +346,7 @@ static char *conf_default_mcast_groups_ipv4[] = {
|
|||||||
|
|
||||||
#ifdef WITH_IPV6
|
#ifdef WITH_IPV6
|
||||||
static char *conf_default_mcast_groups_ipv6[] = {
|
static char *conf_default_mcast_groups_ipv6[] = {
|
||||||
|
"ff01:0:0:0:0:0:0:18c",
|
||||||
/* "ff01:0:0:0:0:0:0:18c",
|
/* "ff01:0:0:0:0:0:0:18c",
|
||||||
"ff02:0:0:0:0:0:0:18c%em0",
|
"ff02:0:0:0:0:0:0:18c%em0",
|
||||||
"ff03:0:0:0:0:0:0:18c",
|
"ff03:0:0:0:0:0:0:18c",
|
||||||
@ -356,11 +357,8 @@ static char *conf_default_mcast_groups_ipv6[] = {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#include "avltree"
|
|
||||||
//#include "cw/stravltree.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
static int add_bcast_addr(void *priv, void *addr)
|
static int add_bcast_addr(void *priv, void *addr)
|
||||||
{
|
{
|
||||||
printf("Callback Called\n");
|
printf("Callback Called\n");
|
||||||
@ -374,12 +372,17 @@ static int add_bcast_addr(void *priv, void *addr)
|
|||||||
conf_bcast_addrs_len++;
|
conf_bcast_addrs_len++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize broadcast addresses (ipv4 only)
|
* Initialize broadcast addresses (ipv4 only)
|
||||||
*/
|
*/
|
||||||
int init_bcast_addrs()
|
int init_bcast_addrs()
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
char str[100];
|
||||||
|
struct ifaddrs *ifa0, *ifa;
|
||||||
mavl_t t;
|
mavl_t t;
|
||||||
mavliter_t it;
|
mavliter_t it;
|
||||||
|
|
||||||
@ -389,17 +392,17 @@ int init_bcast_addrs()
|
|||||||
if (!conf_ipv4)
|
if (!conf_ipv4)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
t = mavl_create(mavl_cmp_str,mavl_free_str);
|
t = mavl_create_str();
|
||||||
if (!t)
|
if (t==NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* add the default broadast address */
|
/* add the default broadast address */
|
||||||
mavl_add_strdup(t, "255.255.255.255");
|
mavl_add_str(t, cw_strdup("255.255.255.255"));
|
||||||
|
|
||||||
|
|
||||||
/* add all other local broadcast addresses */
|
/* add all other local broadcast addresses */
|
||||||
struct ifaddrs *ifa0, *ifa;
|
|
||||||
int rc = getifaddrs(&ifa0);
|
rc = getifaddrs(&ifa0);
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -421,24 +424,22 @@ int init_bcast_addrs()
|
|||||||
if (sa->sa_family != AF_INET)
|
if (sa->sa_family != AF_INET)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char str[100];
|
|
||||||
if (ifa->ifa_broadaddr) {
|
if (ifa->ifa_broadaddr) {
|
||||||
sock_addrtostr(ifa->ifa_broadaddr, str, 100,1);
|
sock_addrtostr(ifa->ifa_broadaddr, str, 100,1);
|
||||||
*strchr(str, ':') = 0;
|
*strchr(str, ':') = 0;
|
||||||
mavl_add_strdup(t, str);
|
mavl_add_str(t, cw_strdup(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_bcast_addrs = malloc(t->count * sizeof(char *));
|
conf_bcast_addrs = malloc(t->count * sizeof(char *));
|
||||||
|
|
||||||
//mavl_foreach_asc(t, add_bcast_addr, 0);
|
|
||||||
|
|
||||||
mavliter_init(&it,t);
|
mavliter_init(&it,t);
|
||||||
mavliter_foreach(&it){
|
mavliter_foreach(&it){
|
||||||
union mavldata * d;
|
char * d;
|
||||||
d = mavliter_get(&it);
|
d = mavliter_get_str(&it);
|
||||||
conf_bcast_addrs[conf_bcast_addrs_len] = strdup(d->str);
|
conf_bcast_addrs[conf_bcast_addrs_len] = cw_strdup(d);
|
||||||
if (conf_bcast_addrs[conf_bcast_addrs_len] != 0)
|
if (conf_bcast_addrs[conf_bcast_addrs_len] != 0)
|
||||||
conf_bcast_addrs_len++;
|
conf_bcast_addrs_len++;
|
||||||
|
|
||||||
@ -454,19 +455,23 @@ int init_bcast_addrs()
|
|||||||
|
|
||||||
int init_mcast_groups()
|
int init_mcast_groups()
|
||||||
{
|
{
|
||||||
if (conf_mcast_groups)
|
int ctr;
|
||||||
return 1;
|
int i;
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int n4 = 0, n6 = 0;
|
int n4 = 0, n6 = 0;
|
||||||
|
|
||||||
|
if (conf_mcast_groups)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (conf_ipv4) {
|
if (conf_ipv4) {
|
||||||
n4 = sizeof(conf_default_mcast_groups_ipv4) / sizeof(char *);
|
n4 = sizeof(conf_default_mcast_groups_ipv4) / sizeof(char *);
|
||||||
}
|
}
|
||||||
#ifdef WITH_IPV6
|
|
||||||
if (conf_ipv6) {
|
if (conf_ipv6) {
|
||||||
n6 = sizeof(conf_default_mcast_groups_ipv6) / sizeof(char *);
|
n6 = sizeof(conf_default_mcast_groups_ipv6) / sizeof(char *);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
n = n4 + n6;
|
n = n4 + n6;
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -476,8 +481,8 @@ int init_mcast_groups()
|
|||||||
return 0;
|
return 0;
|
||||||
memset(conf_mcast_groups, 0, n * sizeof(char *));
|
memset(conf_mcast_groups, 0, n * sizeof(char *));
|
||||||
|
|
||||||
int ctr = 0;
|
ctr = 0;
|
||||||
int i;
|
|
||||||
for (i = 0; i < n4; i++) {
|
for (i = 0; i < n4; i++) {
|
||||||
uint8_t *g = (uint8_t *) conf_default_mcast_groups_ipv4[i];
|
uint8_t *g = (uint8_t *) conf_default_mcast_groups_ipv4[i];
|
||||||
conf_mcast_groups[ctr] =
|
conf_mcast_groups[ctr] =
|
||||||
@ -546,8 +551,8 @@ static int conf_read_dbg_level(cfg_t * cfg)
|
|||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
char *str = cfg_getnstr(cfg, name, i);
|
char *str = cfg_getnstr(cfg, name, i);
|
||||||
//int u = cw_log_str2dbglevel(str);
|
int b = cw_strlist_get_id(cw_dbg_strings, str);
|
||||||
int b = cw_strlist_get_id(cw_dbg_strings, str); //cw_log_str2dbglevel(str);
|
|
||||||
|
|
||||||
cw_dbg_set_level(b, 1);
|
cw_dbg_set_level(b, 1);
|
||||||
|
|
||||||
@ -555,34 +560,9 @@ static int conf_read_dbg_level(cfg_t * cfg)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct cw_Mod ** conf_mods;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct cw_Mod ** conf_mods; //[10];
|
|
||||||
char *conf_mods_dir = NULL;
|
char *conf_mods_dir = NULL;
|
||||||
|
|
||||||
|
|
||||||
static int init_mods()
|
|
||||||
{
|
|
||||||
|
|
||||||
/* conf_mods[0]=modload_ac("cisco");
|
|
||||||
conf_mods[1]=modload_ac("fortinet");
|
|
||||||
// conf_mods[2]=modload_ac("zyxel");
|
|
||||||
conf_mods[2]=modload_ac("cipwap");
|
|
||||||
conf_mods[3]=modload_ac("capwap");
|
|
||||||
conf_mods[4]=modload_ac("capwap80211");
|
|
||||||
conf_mods[5]=NULL;
|
|
||||||
*/
|
|
||||||
int i;
|
|
||||||
for(i=0; conf_mods[i]; i++){
|
|
||||||
if (conf_mods[i]->init){
|
|
||||||
conf_mods[i]->init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the module names from config file
|
* Read the module names from config file
|
||||||
*/
|
*/
|
||||||
@ -626,6 +606,10 @@ void conf_init_capwap_mode()
|
|||||||
|
|
||||||
int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *proto)
|
int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *proto)
|
||||||
{
|
{
|
||||||
|
char *b;
|
||||||
|
int c;
|
||||||
|
int i, l;
|
||||||
|
char *ctrlport;
|
||||||
char *p = strchr(addrstr, '/');
|
char *p = strchr(addrstr, '/');
|
||||||
if (!p)
|
if (!p)
|
||||||
*proto = AC_PROTO_CAPWAP;
|
*proto = AC_PROTO_CAPWAP;
|
||||||
@ -638,7 +622,7 @@ int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *pr
|
|||||||
*proto = AC_PROTO_UNKNOWN;
|
*proto = AC_PROTO_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ctrlport;
|
|
||||||
switch (*proto) {
|
switch (*proto) {
|
||||||
case AC_PROTO_CAPWAP:
|
case AC_PROTO_CAPWAP:
|
||||||
ctrlport = CAPWAP_CONTROL_PORT_STR;
|
ctrlport = CAPWAP_CONTROL_PORT_STR;
|
||||||
@ -651,8 +635,8 @@ int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int i, l;
|
|
||||||
int c = 0;
|
c = 0;
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
l = p - addrstr;
|
l = p - addrstr;
|
||||||
@ -684,7 +668,7 @@ int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we assume now, its ipv6 */
|
/* we assume now, its ipv6 */
|
||||||
char *b = strstr(addrstr, "]:");
|
b = strstr(addrstr, "]:");
|
||||||
if (!b) {
|
if (!b) {
|
||||||
/* ippv6 w/o port */
|
/* ippv6 w/o port */
|
||||||
strncpy(saddr, addrstr, l);
|
strncpy(saddr, addrstr, l);
|
||||||
@ -716,9 +700,6 @@ int read_config(const char *filename)
|
|||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
if (!init_control_port())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
cfg_opt_t opts[] = {
|
cfg_opt_t opts[] = {
|
||||||
CFG_STR_LIST("mods", "{}", CFGF_NONE),
|
CFG_STR_LIST("mods", "{}", CFGF_NONE),
|
||||||
CFG_SIMPLE_STR("mods_dir", &conf_mods_dir),
|
CFG_SIMPLE_STR("mods_dir", &conf_mods_dir),
|
||||||
@ -733,7 +714,7 @@ int read_config(const char *filename)
|
|||||||
CFG_SIMPLE_BOOL("strict_capwap", &conf_strict_capwap),
|
CFG_SIMPLE_BOOL("strict_capwap", &conf_strict_capwap),
|
||||||
CFG_SIMPLE_BOOL("strict_headers", &conf_strict_headers),
|
CFG_SIMPLE_BOOL("strict_headers", &conf_strict_headers),
|
||||||
CFG_SIMPLE_BOOL("use_loopback", &conf_use_loopback),
|
CFG_SIMPLE_BOOL("use_loopback", &conf_use_loopback),
|
||||||
// CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),
|
/*// CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef WITH_LWAPP
|
#ifdef WITH_LWAPP
|
||||||
@ -765,12 +746,17 @@ int read_config(const char *filename)
|
|||||||
CFG_SIMPLE_BOOL("dtls_verify_peer", &conf_dtls_verify_peer),
|
CFG_SIMPLE_BOOL("dtls_verify_peer", &conf_dtls_verify_peer),
|
||||||
CFG_SIMPLE_BOOL("ipv4", &conf_ipv4),
|
CFG_SIMPLE_BOOL("ipv4", &conf_ipv4),
|
||||||
CFG_SIMPLE_BOOL("ipv6", &conf_ipv6),
|
CFG_SIMPLE_BOOL("ipv6", &conf_ipv6),
|
||||||
CFG_SIMPLE_STR("db_file", conf_db_file),
|
CFG_SIMPLE_STR("db_file", &conf_db_file),
|
||||||
CFG_SIMPLE_STR("image_dir", &conf_image_dir),
|
CFG_SIMPLE_STR("image_dir", &conf_image_dir),
|
||||||
|
|
||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
cfg_t *cfg;
|
cfg_t *cfg;
|
||||||
|
|
||||||
|
if (!init_control_port())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
cfg = cfg_init(opts, CFGF_NONE);
|
cfg = cfg_init(opts, CFGF_NONE);
|
||||||
cfg_set_error_function(cfg, errfunc);
|
cfg_set_error_function(cfg, errfunc);
|
||||||
|
|
||||||
@ -838,18 +824,13 @@ int read_config(const char *filename)
|
|||||||
if (!conf_image_dir)
|
if (!conf_image_dir)
|
||||||
conf_image_dir = CONF_DEFAULT_IMAGE_DIR;
|
conf_image_dir = CONF_DEFAULT_IMAGE_DIR;
|
||||||
|
|
||||||
//printf("INIT MODS\n");
|
|
||||||
// init_mods();
|
|
||||||
//printf("done init mods");
|
|
||||||
|
|
||||||
// conf_init_capwap_mode();
|
|
||||||
|
|
||||||
|
|
||||||
init_listen_addrs();
|
init_listen_addrs();
|
||||||
init_mcast_groups();
|
init_mcast_groups();
|
||||||
init_bcast_addrs();
|
init_bcast_addrs();
|
||||||
|
|
||||||
//printf("Yea all mods inited\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ static int cmp(const void *d1, const void *d2)
|
|||||||
|
|
||||||
int dataman_list_init()
|
int dataman_list_init()
|
||||||
{
|
{
|
||||||
dataman_list = mavl_create(cmp, NULL);
|
dataman_list = mavl_create_ptr(cmp, NULL);
|
||||||
if (!dataman_list)
|
if (!dataman_list)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ struct dataman *dataman_list_add(struct dataman *dm)
|
|||||||
{
|
{
|
||||||
|
|
||||||
cw_dbg(DBG_X,"Adding dataman %p\n",dm);
|
cw_dbg(DBG_X,"Adding dataman %p\n",dm);
|
||||||
return mavl_add(dataman_list, dm);
|
return mavl_add(dataman_list, dm,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
|
||||||
#define MAX_WTPS 200
|
#define MAX_WTPS 200
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "socklist.h"
|
#include "socklist.h"
|
||||||
#include "wtpman.h"
|
#include "wtpman.h"
|
||||||
#include "wtplist.h"
|
#include "wtplist.h"
|
||||||
|
#include "cw/kvt.h"
|
||||||
|
|
||||||
static void reset_echointerval_timer(struct wtpman *wtpman)
|
static void reset_echointerval_timer(struct wtpman *wtpman)
|
||||||
{
|
{
|
||||||
@ -94,10 +94,10 @@ static void wtpman_run_discovery(void *arg)
|
|||||||
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
|
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
|
||||||
// wtpman->conn->actions = &capwap_actions;
|
// wtpman->conn->actions = &capwap_actions;
|
||||||
|
|
||||||
wtpman->conn->outgoing = mbag_create();
|
/* wtpman->conn->outgoing = mbag_create();
|
||||||
wtpman->conn->incomming = mbag_create();
|
wtpman->conn->incomming = mbag_create();
|
||||||
|
*/
|
||||||
wtpman->conn->remote_cfg = mavl_create(mavl_cmp_kv,NULL);
|
wtpman->conn->remote_cfg = cw_kvt_create(); //mavl_cmp_kv,NULL,1312);
|
||||||
|
|
||||||
while (!cw_timer_timeout(timer)
|
while (!cw_timer_timeout(timer)
|
||||||
&& wtpman->conn->capwap_state == CAPWAP_STATE_DISCOVERY) {
|
&& wtpman->conn->capwap_state == CAPWAP_STATE_DISCOVERY) {
|
||||||
|
@ -32,10 +32,10 @@
|
|||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
|
|
||||||
|
|
||||||
static int acip_cmp(const mavldata_t *x1, const mavldata_t *x2)
|
static int acip_cmp(const void *x1, const void *x2)
|
||||||
{
|
{
|
||||||
struct cw_acip *ip1 = (struct cw_acip *) x1->ptr;
|
struct cw_acip *ip1 = *((struct cw_acip **) x1);
|
||||||
struct cw_acip *ip2 = (struct cw_acip *) x2->ptr;
|
struct cw_acip *ip2 = *((struct cw_acip **) x2);
|
||||||
|
|
||||||
int r = ip1->index - ip2->index;
|
int r = ip1->index - ip2->index;
|
||||||
if (r!=0)
|
if (r!=0)
|
||||||
@ -68,9 +68,9 @@ static int acip_cmp(const mavldata_t *x1, const mavldata_t *x2)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void acip_del(mavldata_t *d)
|
static void acip_del(void *d)
|
||||||
{
|
{
|
||||||
free(d->ptr);
|
free(*(void**)d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,6 +79,6 @@ static void acip_del(mavldata_t *d)
|
|||||||
*/
|
*/
|
||||||
cw_aciplist_t cw_aciplist_create()
|
cw_aciplist_t cw_aciplist_create()
|
||||||
{
|
{
|
||||||
return mavl_create(acip_cmp, acip_del);
|
return mavl_create(acip_cmp, acip_del,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ typedef struct mavl * cw_aciplist_t;
|
|||||||
extern cw_aciplist_t cw_aciplist_create();
|
extern cw_aciplist_t cw_aciplist_create();
|
||||||
|
|
||||||
#define cw_aciplist_destroy(l) mavl_destroy(l)
|
#define cw_aciplist_destroy(l) mavl_destroy(l)
|
||||||
#define cw_aciplist_add(l,elem) mavl_add(l,elem)
|
#define cw_aciplist_add(l,elem) mavl_add(l,elem,NULL)
|
||||||
#define cw_aciplist_del(l,elem) mavl_del(l,elem)
|
#define cw_aciplist_del(l,elem) mavl_del(l,elem)
|
||||||
#define cw_aciplist_foreach(l,callback,cbpriv) mavl_foreach_asc(l,callback,cbpriv)
|
#define cw_aciplist_foreach(l,callback,cbpriv) mavl_foreach_asc(l,callback,cbpriv)
|
||||||
#define cw_aciplist_replace(l,r) mavl_replace(l,r)
|
#define cw_aciplist_replace(l,r) mavl_replace(l,r,NULL)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ const struct mbag_typedef mbag_type_acprio = {
|
|||||||
|
|
||||||
cw_acpriolist_t cw_acpriolist_create()
|
cw_acpriolist_t cw_acpriolist_create()
|
||||||
{
|
{
|
||||||
return mavl_create(acprio_cmp, acprio_del);
|
return mavl_create(acprio_cmp, acprio_del,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio)
|
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio)
|
||||||
@ -66,7 +66,7 @@ cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len
|
|||||||
s->prio=prio;
|
s->prio=prio;
|
||||||
|
|
||||||
cw_acpriolist_del(l,s);
|
cw_acpriolist_del(l,s);
|
||||||
return mavl_add(l,s);
|
return mavl_add(l,s,NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ static int cw_action_in_cmp(const void *elem1, const void *elem2)
|
|||||||
*/
|
*/
|
||||||
cw_actionlist_in_t cw_actionlist_in_create()
|
cw_actionlist_in_t cw_actionlist_in_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cw_action_in_cmp, free);
|
return mavl_create(cw_action_in_cmp, free,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +89,7 @@ cw_action_in_t *cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in *
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memcpy(an, a, s);
|
memcpy(an, a, s);
|
||||||
return mavl_add(t, an);
|
return mavl_add(t, an,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,7 +217,7 @@ cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_o
|
|||||||
if (!o) {
|
if (!o) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mavl_add(t,o);
|
mavl_add(t,o,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mlist_elem * e = mlist_replace(o->mlist,NULL,a);
|
struct mlist_elem * e = mlist_replace(o->mlist,NULL,a);
|
||||||
@ -273,7 +273,7 @@ void *cw_actionlist_add(struct mavl *t, void *a, size_t s)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memcpy(an, a, s);
|
memcpy(an, a, s);
|
||||||
return mavl_add(t, an);
|
return mavl_add(t, an,NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ void *cw_actionlist_add(struct mavl *t, void *a, size_t s)
|
|||||||
*/
|
*/
|
||||||
cw_actionlist_out_t cw_actionlist_out_create()
|
cw_actionlist_out_t cw_actionlist_out_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cw_action_out_cmp, free);
|
return mavl_create(cw_action_out_cmp, free,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,10 +30,9 @@
|
|||||||
|
|
||||||
#include "stravltree.h"
|
#include "stravltree.h"
|
||||||
#include "mod.h"
|
#include "mod.h"
|
||||||
#include "message_set.h"
|
#include "msget.h"
|
||||||
|
|
||||||
#include "cw_types.h"
|
|
||||||
|
|
||||||
|
#include "kvt.h"
|
||||||
|
|
||||||
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
|
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
|
||||||
|
|
||||||
@ -301,7 +300,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
|||||||
|
|
||||||
/* Search message */
|
/* Search message */
|
||||||
struct cw_MsgData * message;
|
struct cw_MsgData * message;
|
||||||
message = mavl_find_ptr(conn->msgset->messages,&search);
|
message = mavl_find(conn->msgset->msgdata,&search);
|
||||||
|
|
||||||
int result_code = 0;
|
int result_code = 0;
|
||||||
|
|
||||||
@ -509,12 +508,12 @@ exit(0);
|
|||||||
|
|
||||||
mavliter_foreach(&it){
|
mavliter_foreach(&it){
|
||||||
char value[500];
|
char value[500];
|
||||||
mavldata_t * data;
|
struct cw_KVT * data;
|
||||||
data = mavliter_get(&it);
|
data = mavliter_get(&it);
|
||||||
type = data->kv.priv;
|
type = data->type;
|
||||||
type->to_str(data,value,0);
|
type->to_str(data,value,0);
|
||||||
|
|
||||||
printf("Got %s (%s): %s\n",data->kv.key,type->name, value);
|
printf("Got %s (%s): %s\n",data->key,type->name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,38 +37,38 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int cmp_by_addr(const mavldata_t * d1,const mavldata_t *d2)
|
static int cmp_by_addr ( const void * d1, const void *d2 )
|
||||||
{
|
{
|
||||||
struct conn * c1=(struct conn *) d1->ptr;
|
struct conn * c1 = * ( void ** ) d1 ;
|
||||||
struct conn * c2=(struct conn *) d2->ptr;
|
struct conn * c2 = * ( void ** ) d2 ;
|
||||||
|
|
||||||
return sock_cmpaddr ( ( struct sockaddr* ) &c1->addr, ( struct sockaddr* ) &c2->addr, 1 );
|
return sock_cmpaddr ( ( struct sockaddr* ) &c1->addr, ( struct sockaddr* ) &c2->addr, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmp_by_session_id(const mavldata_t *d1, const mavldata_t *d2)
|
static int cmp_by_session_id ( const void *d1, const void *d2 )
|
||||||
{
|
{
|
||||||
struct conn * c1=(struct conn *) d1->ptr;
|
struct conn * c1 = *( void ** ) d1;
|
||||||
struct conn * c2=(struct conn *) d2->ptr;
|
struct conn * c2 = *( void ** ) d2;
|
||||||
return memcmp ( c1->session_id, c2->session_id, 16 );
|
return memcmp ( c1->session_id, c2->session_id, 16 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct connlist * connlist_create ( int len )
|
struct connlist * connlist_create ( int len )
|
||||||
{
|
{
|
||||||
|
|
||||||
struct connlist * cl = malloc ( sizeof ( struct connlist ) );
|
struct connlist * cl = malloc ( sizeof ( struct connlist ) );
|
||||||
|
|
||||||
if ( !cl )
|
if ( !cl )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
cl->by_addr = mavl_create(cmp_by_addr,0);
|
cl->by_addr = mavl_create_ptr ( cmp_by_addr, NULL );
|
||||||
|
|
||||||
if ( !cl->by_addr ) {
|
if ( !cl->by_addr ) {
|
||||||
free ( cl );
|
free ( cl );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->by_session_id = mavl_create(cmp_by_session_id,0);
|
cl->by_session_id = mavl_create_ptr ( cmp_by_session_id, NULL );
|
||||||
|
|
||||||
|
|
||||||
if ( pthread_mutex_init ( &cl->connlist_mutex, NULL ) ) {
|
if ( pthread_mutex_init ( &cl->connlist_mutex, NULL ) ) {
|
||||||
@ -100,6 +100,7 @@ void connlist_destroy(struct connlist * cl)
|
|||||||
|
|
||||||
if ( cl->by_addr )
|
if ( cl->by_addr )
|
||||||
mavl_destroy ( cl->by_addr );
|
mavl_destroy ( cl->by_addr );
|
||||||
|
|
||||||
pthread_mutex_destroy ( &cl->connlist_mutex );
|
pthread_mutex_destroy ( &cl->connlist_mutex );
|
||||||
free ( cl );
|
free ( cl );
|
||||||
|
|
||||||
@ -119,6 +120,7 @@ struct conn * connlist_add(struct connlist * cl, struct conn * conn)
|
|||||||
if ( cl->len != 0 )
|
if ( cl->len != 0 )
|
||||||
if ( cl->by_addr->count >= cl->len )
|
if ( cl->by_addr->count >= cl->len )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
conn->connlist = cl;
|
conn->connlist = cl;
|
||||||
return mavl_add_ptr ( cl->by_addr, conn );
|
return mavl_add_ptr ( cl->by_addr, conn );
|
||||||
}
|
}
|
||||||
@ -135,12 +137,9 @@ struct conn * connlist_add_by_session_id(struct connlist * cl, struct conn * con
|
|||||||
|
|
||||||
void connlist_remove ( struct connlist *cl, struct conn * conn )
|
void connlist_remove ( struct connlist *cl, struct conn * conn )
|
||||||
{
|
{
|
||||||
mavldata_t md;
|
void * md;
|
||||||
md.ptr=conn;
|
md = conn;
|
||||||
mavl_del ( cl->by_session_id, &md );
|
mavl_del ( cl->by_session_id, &md );
|
||||||
md.ptr=conn;
|
md = conn;
|
||||||
mavl_del ( cl->by_addr, &md );
|
mavl_del ( cl->by_addr, &md );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "lw.h"
|
#include "lw.h"
|
||||||
#include "capwap.h"
|
#include "capwap.h"
|
||||||
#include "message_set.h"
|
#include "msget.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup CW CW
|
* @defgroup CW CW
|
||||||
|
@ -24,7 +24,7 @@ int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8
|
|||||||
|
|
||||||
prio->prio=cw_get_byte(data);
|
prio->prio=cw_get_byte(data);
|
||||||
prio->name=strndup((char*)data+1,len-1);
|
prio->name=strndup((char*)data+1,len-1);
|
||||||
mavl_replace(prios,prio);
|
mavl_replace(prios,prio,NULL);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "message_set.h"
|
#include "msget.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
#include "kvstore.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||||
@ -13,7 +12,7 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
|
|||||||
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cw_kvstore_add(params->conn->remote_cfg, handler->key, handler->type, elem_data,elem_len);
|
cw_kvt_add(params->conn->remote_cfg, handler->key, handler->type, elem_data,elem_len);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "cw_types.h"
|
|
||||||
#include "kvstore.h"
|
|
||||||
|
|
||||||
void cw_types_kvstore_mavl_delete(mavldata_t *data){
|
|
||||||
const struct cw_Type * type = data->kv.priv;
|
|
||||||
if (type->del)
|
|
||||||
type->del(data);
|
|
||||||
free(data->kv.key);
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +1,42 @@
|
|||||||
#include "kvstore.h"
|
#include "kvt.h"
|
||||||
#include "cw_types.h"
|
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
|
|
||||||
const char * cw_kvstore_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
|
const char * cw_kvt_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
||||||
const uint8_t * data, int len)
|
const uint8_t * data, int len)
|
||||||
{
|
{
|
||||||
mavldata_t mdata, *mresult;
|
cw_KVT_t mdata, *mresult;
|
||||||
|
int exists;
|
||||||
|
|
||||||
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
|
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
|
||||||
type->name, key );
|
type->name, key );
|
||||||
*/
|
*/
|
||||||
mdata.kv.key=cw_strdup(key);
|
mdata.key=cw_strdup(key);
|
||||||
if (!mdata.kv.key){
|
if (!mdata.key){
|
||||||
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
|
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
|
||||||
key,strerror(errno));
|
key,strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mresult = type->get(&mdata,data,len);
|
mresult = type->get(&mdata,data,len);
|
||||||
if (!mresult){
|
if (!mresult){
|
||||||
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
|
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
|
||||||
key,type->name, strerror(errno));
|
key,type->name, strerror(errno));
|
||||||
free(mdata.kv.key);
|
free(mdata.key);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mresult = mavl_add(kvstore, &mdata);
|
mresult = mavl_add(kvtstore, &mdata, &exists);
|
||||||
if (mresult != &mdata){
|
if (exists){
|
||||||
cw_log(LOG_ERR, "Element already exists %s", key);
|
cw_log(LOG_ERR, "Element already exists %s", key);
|
||||||
/* element already exists */
|
/* element already exists */
|
||||||
free(mdata.kv.key);
|
free(mdata.key);
|
||||||
|
if (type->del)
|
||||||
type->del(&mdata);
|
type->del(&mdata);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mdata.kv.key;
|
return mdata.key;
|
||||||
}
|
}
|
6
src/cw/cw_kvt_mavlcmp.c
Normal file
6
src/cw/cw_kvt_mavlcmp.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "kvt.h"
|
||||||
|
|
||||||
|
int cw_kvt_mavlcmp(const void *v1, const void *v2)
|
||||||
|
{
|
||||||
|
return strcmp(((cw_KVT_t *) v1)->key, ((cw_KVT_t *) v2)->key);
|
||||||
|
}
|
15
src/cw/cw_kvt_mavldel.c
Normal file
15
src/cw/cw_kvt_mavldel.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "kvt.h"
|
||||||
|
|
||||||
|
void cw_kvt_mavldel(void *data)
|
||||||
|
{
|
||||||
|
struct cw_KVT *kvt = data;
|
||||||
|
|
||||||
|
if (kvt->type->del)
|
||||||
|
kvt->type->del(data);
|
||||||
|
|
||||||
|
free(kvt->key);
|
||||||
|
}
|
@ -30,7 +30,7 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
|||||||
elem_data_search.id=elem_id;
|
elem_data_search.id=elem_id;
|
||||||
elem_data_search.proto=0;
|
elem_data_search.proto=0;
|
||||||
elem_data_search.vendor=0;
|
elem_data_search.vendor=0;
|
||||||
elem_data = mavl_find_ptr(params->msgdata->elements_tree,&elem_data_search);
|
elem_data = mavl_find(params->msgdata->elements_tree,&elem_data_search);
|
||||||
if (!elem_data){
|
if (!elem_data){
|
||||||
cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here",
|
cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here",
|
||||||
elem_id, handler->name);
|
elem_id, handler->name);
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "kvstore.h"
|
|
||||||
|
|
||||||
int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
|
int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
|
||||||
uint8_t * data, int len,
|
uint8_t * data, int len,
|
||||||
@ -69,11 +69,11 @@ int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
|
|||||||
|
|
||||||
/* vendor */
|
/* vendor */
|
||||||
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VENDOR);
|
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VENDOR);
|
||||||
cw_kvstore_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
|
cw_kvt_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
|
||||||
|
|
||||||
/* version */
|
/* version */
|
||||||
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VERSION);
|
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VERSION);
|
||||||
cw_kvstore_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
|
cw_kvt_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
|
||||||
|
|
||||||
sprintf(dbgstr, "%s", key);
|
sprintf(dbgstr, "%s", key);
|
||||||
cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype, vendor_id, data+sub+8,l);
|
cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype, vendor_id, data+sub+8,l);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "capwap.h"
|
#include "capwap.h"
|
||||||
#include "capwap_items.h"
|
#include "capwap_items.h"
|
||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
|
|
||||||
|
|
||||||
static struct cw_DescriptorSubelemDef allowed_default[] = {
|
static struct cw_DescriptorSubelemDef allowed_default[] = {
|
||||||
@ -19,6 +19,10 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
|
|||||||
struct cw_ElemHandler *eh, uint8_t * data, int len,
|
struct cw_ElemHandler *eh, uint8_t * data, int len,
|
||||||
struct cw_DescriptorSubelemDef *allowed)
|
struct cw_DescriptorSubelemDef *allowed)
|
||||||
{
|
{
|
||||||
|
printf( "toto here cw_read_wtp_descriptor\n");
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
/*
|
||||||
int ncrypt, pos,i;
|
int ncrypt, pos,i;
|
||||||
mavldata_t md;
|
mavldata_t md;
|
||||||
char key[64];
|
char key[64];
|
||||||
@ -30,13 +34,12 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
|
|||||||
sprintf(key,"%s/%s",eh->key, "radios_in_use");
|
sprintf(key,"%s/%s",eh->key, "radios_in_use");
|
||||||
md.kv.key=strdup(key);
|
md.kv.key=strdup(key);
|
||||||
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
|
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
|
||||||
|
|
||||||
|
|
||||||
/* mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
|
|
||||||
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1));
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Get number of encryption elements */
|
/* Get number of encryption elements */
|
||||||
|
|
||||||
|
/*
|
||||||
ncrypt = cw_get_byte(data + 2);
|
ncrypt = cw_get_byte(data + 2);
|
||||||
if (ncrypt == 0) {
|
if (ncrypt == 0) {
|
||||||
if (conn->strict_capwap) {
|
if (conn->strict_capwap) {
|
||||||
@ -49,15 +52,18 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = 3;
|
pos = 3;
|
||||||
for (i = 0; i < ncrypt; i++) {
|
*/
|
||||||
/* // It's a dummy for now */
|
//
|
||||||
pos += 3;
|
// for (i = 0; i < ncrypt; i++) {
|
||||||
}
|
///* // It's a dummy for now *
|
||||||
|
// pos += 3;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/*
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
allowed=allowed_default;
|
allowed=allowed_default;
|
||||||
}
|
}
|
||||||
printf("call read subelems\n");
|
printf("call read subelems\n");
|
||||||
return cw_read_descriptor_subelems(cfg,eh->key , data + pos, len - pos, allowed);
|
return cw_read_descriptor_subelems(cfg,eh->key , data + pos, len - pos, allowed);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "capwap.h"
|
#include "capwap.h"
|
||||||
#include "capwap_items.h"
|
#include "capwap_items.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "kvstore.h"
|
|
||||||
|
|
||||||
|
|
||||||
static struct cw_DescriptorSubelemDef allowed_default[] = {
|
static struct cw_DescriptorSubelemDef allowed_default[] = {
|
||||||
@ -24,18 +24,18 @@ int cw_read_wtp_descriptor_7(mavl_t cfg, struct conn *conn,
|
|||||||
struct cw_ElemHandler *eh, uint8_t * data, int len,
|
struct cw_ElemHandler *eh, uint8_t * data, int len,
|
||||||
struct cw_DescriptorSubelemDef *allowed)
|
struct cw_DescriptorSubelemDef *allowed)
|
||||||
{
|
{
|
||||||
int ncrypt, pos,i;
|
|
||||||
mavldata_t md;
|
int ncrypt, pos;
|
||||||
char key[64];
|
char key[64];
|
||||||
|
|
||||||
sprintf(key,"%s/%s",eh->key, "max_radios");
|
sprintf(key,"%s/%s",eh->key, "max_radios");
|
||||||
/* md.kv.key=strdup(key);
|
/* md.kv.key=strdup(key);
|
||||||
mavl_replace (cfg, cw_type_byte.get(&md,data,1));
|
mavl_replace (cfg, cw_type_byte.get(&md,data,1));
|
||||||
*/
|
*/
|
||||||
cw_kvstore_add(cfg,key,CW_TYPE_BYTE,data,1);
|
cw_kvt_add(cfg,key,CW_TYPE_BYTE,data,1);
|
||||||
|
|
||||||
sprintf(key,"%s/%s",eh->key, "radios_in_use");
|
sprintf(key,"%s/%s",eh->key, "radios_in_use");
|
||||||
cw_kvstore_add(cfg,key,CW_TYPE_BYTE,data+1,1);
|
cw_kvt_add(cfg,key,CW_TYPE_BYTE,data+1,1);
|
||||||
|
|
||||||
/* md.kv.key=strdup(key);
|
/* md.kv.key=strdup(key);
|
||||||
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
|
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Duplicate a string
|
||||||
|
* @param s string to duplicate
|
||||||
|
* @return duplicated string, the memory acllocated has to be freed by #free.
|
||||||
|
*/
|
||||||
char *cw_strdup(const char *s) {
|
char *cw_strdup(const char *s) {
|
||||||
size_t size = strlen(s) + 1;
|
size_t size = strlen(s) + 1;
|
||||||
char *p = malloc(size);
|
char *p = malloc(size);
|
||||||
|
@ -20,47 +20,50 @@
|
|||||||
|
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
|
|
||||||
|
|
||||||
static void del(mavldata_t * data){
|
static void del ( struct cw_KVT * data )
|
||||||
free (data->kv.val.ptr);
|
{
|
||||||
|
free ( data->val.ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
|
static struct cw_KVT *get ( struct cw_KVT * data, const uint8_t * src, int len )
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t * s;
|
uint8_t * s;
|
||||||
s = bstr16_create ( src, len );
|
s = bstr16_create ( src, len );
|
||||||
|
|
||||||
if ( !s )
|
if ( !s )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data->kv.priv = &cw_type_bstr16;
|
data->type = &cw_type_bstr16;
|
||||||
data->kv.val.ptr=s;
|
data->val.ptr = s;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put(mavldata_t *data, uint8_t * dst)
|
static int put ( const struct cw_KVT *data, uint8_t * dst )
|
||||||
{
|
{
|
||||||
return cw_put_bstr16(dst, data->kv.val.ptr);
|
return cw_put_bstr16 ( dst, data->val.ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_str(const mavldata_t *data, char *dst, int max_len)
|
static int to_str ( const struct cw_KVT *data, char *dst, int max_len )
|
||||||
{
|
{
|
||||||
char *d;
|
char *d;
|
||||||
d = dst;
|
d = dst;
|
||||||
if (format_is_utf8(bstr16_data(data->kv.val.ptr), bstr16_len(data->kv.val.ptr))) {
|
|
||||||
d += sprintf(d, "%.*s", bstr16_len(data->kv.val.ptr),
|
if ( format_is_utf8 ( bstr16_data ( data->val.ptr ), bstr16_len ( data->val.ptr ) ) ) {
|
||||||
bstr16_data(data->kv.val.ptr));
|
d += sprintf ( d, "%.*s", bstr16_len ( data->val.ptr ),
|
||||||
|
bstr16_data ( data->val.ptr ) );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
d += sprintf ( d, ".x" );
|
d += sprintf ( d, ".x" );
|
||||||
d += format_hex(d, bstr16_data(data->kv.val.ptr), bstr16_len(data->kv.val.ptr));
|
d += format_hex ( d, bstr16_data ( data->val.ptr ), bstr16_len ( data->val.ptr ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return d - dst;
|
return d - dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mavldata_t *from_str(mavldata_t * data, const char *src)
|
static struct cw_KVT *from_str ( struct cw_KVT * data, const char *src )
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -74,4 +77,3 @@ const struct cw_Type cw_type_bstr16 = {
|
|||||||
to_str, /* to_str */
|
to_str, /* to_str */
|
||||||
from_str /* from_str */
|
from_str /* from_str */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,35 +19,35 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
|
|
||||||
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
|
static cw_KVT_t *get(cw_KVT_t * data, const uint8_t * src, int len)
|
||||||
{
|
{
|
||||||
data->kv.priv = &cw_type_byte;
|
data->type = &cw_type_byte;
|
||||||
data->kv.val.byte = cw_get_byte(src);
|
data->val.byte = cw_get_byte(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put(mavldata_t *data, uint8_t * dst)
|
static int put(cw_KVT_t *data, uint8_t * dst)
|
||||||
{
|
{
|
||||||
return cw_put_byte(dst, data->kv.val.byte);
|
return cw_put_byte(dst, data->val.byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_str(const mavldata_t *data, char *dst, int max_len)
|
static int to_str(const cw_KVT_t *data, char *dst, int max_len)
|
||||||
{
|
{
|
||||||
return sprintf(dst, "%d", data->kv.val.byte);
|
return sprintf(dst, "%d", data->val.byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static mavldata_t *from_str(mavldata_t * data, const char *src)
|
static cw_KVT_t *from_str(cw_KVT_t * data, const char *src)
|
||||||
{
|
{
|
||||||
data->kv.val.byte = atoi(src);
|
data->val.byte = atoi(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const struct cw_Type cw_type_byte = {
|
const struct cw_Type cw_type_byte = {
|
||||||
"Byte", /* name */
|
"Byte", /* name */
|
||||||
cw_types_del_null, /* del */
|
NULL, /* del */
|
||||||
put, /* put */
|
put, /* put */
|
||||||
get, /* get */
|
get, /* get */
|
||||||
to_str, /* to_str */
|
to_str, /* to_str */
|
||||||
|
@ -19,34 +19,34 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
|
|
||||||
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
|
static struct cw_KVT *get(struct cw_KVT * data, const uint8_t * src, int len)
|
||||||
{
|
{
|
||||||
data->kv.priv = &cw_type_dword;
|
data->type = &cw_type_dword;
|
||||||
data->kv.val.dword = cw_get_dword(src);
|
data->val.dword = cw_get_dword(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put(mavldata_t *data, uint8_t * dst)
|
static int put(struct cw_KVT *data, uint8_t * dst)
|
||||||
{
|
{
|
||||||
return cw_put_dword(dst, data->kv.val.dword);
|
return cw_put_dword(dst, data->val.dword);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_str(const mavldata_t *data, char *dst, int max_len)
|
static int to_str(const struct cw_KVT *data, char *dst, int max_len)
|
||||||
{
|
{
|
||||||
return sprintf(dst, "%d", data->kv.val.dword);
|
return sprintf(dst, "%d", data->val.dword);
|
||||||
}
|
}
|
||||||
|
|
||||||
static mavldata_t *from_str(mavldata_t * data, const char *src)
|
static struct cw_KVT *from_str(struct cw_KVT * data, const char *src)
|
||||||
{
|
{
|
||||||
data->kv.val.dword = atoi(src);
|
data->val.dword = atoi(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct cw_Type cw_type_dword = {
|
const struct cw_Type cw_type_dword = {
|
||||||
"Dword", /* name */
|
"Dword", /* name */
|
||||||
cw_types_del_null, /* del */
|
NULL, /* del */
|
||||||
put, /* put */
|
put, /* put */
|
||||||
get, /* get */
|
get, /* get */
|
||||||
to_str, /* to_str */
|
to_str, /* to_str */
|
||||||
|
@ -18,36 +18,36 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cw_types.h"
|
#include "kvt.h"
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
|
|
||||||
|
|
||||||
static mavldata_t *get(mavldata_t * data, const uint8_t * src, int len)
|
static struct cw_KVT *get(struct cw_KVT * data, const uint8_t * src, int len)
|
||||||
{
|
{
|
||||||
data->kv.priv = &cw_type_word;
|
data->type = &cw_type_word;
|
||||||
data->kv.val.word = cw_get_word(src);
|
data->val.word = cw_get_word(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put(mavldata_t *data, uint8_t * dst)
|
static int put(cw_KVT_t *data, uint8_t * dst)
|
||||||
{
|
{
|
||||||
return cw_put_word(dst, data->kv.val.word);
|
return cw_put_word(dst, data->val.word);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int to_str(const mavldata_t *data, char *dst, int max_len)
|
static int to_str(const cw_KVT_t *data, char *dst, int max_len)
|
||||||
{
|
{
|
||||||
return sprintf(dst, "%d", data->kv.val.word);
|
return sprintf(dst, "%d", data->val.word);
|
||||||
}
|
}
|
||||||
|
|
||||||
static mavldata_t *from_str(mavldata_t * data, const char *src)
|
static cw_KVT_t *from_str(cw_KVT_t * data, const char *src)
|
||||||
{
|
{
|
||||||
data->kv.val.word = atoi(src);
|
data->val.word = atoi(src);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct cw_Type cw_type_word = {
|
const struct cw_Type cw_type_word = {
|
||||||
"Word", /* name */
|
"Word", /* name */
|
||||||
cw_types_del_null, /* del */
|
NULL, /* del */
|
||||||
put, /* put */
|
put, /* put */
|
||||||
get, /* get */
|
get, /* get */
|
||||||
to_str, /* to_str */
|
to_str, /* to_str */
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
#ifndef __CW_TYPES_H
|
|
||||||
#define __CW_TYPES_H
|
|
||||||
|
|
||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
struct cw_Type{
|
|
||||||
/** A human readable name for this type */
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
/** A pointer to a function to delete elements of this type */
|
|
||||||
void (*del)(mavldata_t *data);
|
|
||||||
|
|
||||||
/** A method to put this object to a buffer */
|
|
||||||
int (*put)(mavldata_t * data, uint8_t*dst);
|
|
||||||
|
|
||||||
/** The get emthod */
|
|
||||||
mavldata_t * (*get)(mavldata_t *data, const uint8_t*src, int len);
|
|
||||||
|
|
||||||
/** A pointer to a function to convert elements of this type to a string.
|
|
||||||
This function is mainly used to store elements to an SQL database
|
|
||||||
or to json strings */
|
|
||||||
int (*to_str)(const mavldata_t * data, char *dst, int max_len);
|
|
||||||
|
|
||||||
/** Cereate an item of this type from a string, which was previously
|
|
||||||
created by the #del function. */
|
|
||||||
mavldata_t * (*from_str)(mavldata_t * data, const char *src);
|
|
||||||
|
|
||||||
/*
|
|
||||||
int (*def)(void *, void *);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
extern const struct cw_Type cw_type_byte;
|
|
||||||
extern const struct cw_Type cw_type_word;
|
|
||||||
extern const struct cw_Type cw_type_dword;
|
|
||||||
extern const struct cw_Type cw_type_bstr16;
|
|
||||||
|
|
||||||
#define CW_TYPE_BYTE (&cw_type_byte)
|
|
||||||
#define CW_TYPE_WORD (&cw_type_word)
|
|
||||||
#define CW_TYPE_DWORD (&cw_type_dword)
|
|
||||||
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
|
|
||||||
|
|
||||||
void cw_types_del_null(mavldata_t *data);
|
|
||||||
|
|
||||||
#endif /* __CW_TYPES_H */
|
|
@ -1,6 +0,0 @@
|
|||||||
#include "mavl.h"
|
|
||||||
#include "cw_types.h"
|
|
||||||
|
|
||||||
void cw_types_del_null(mavldata_t *data){
|
|
||||||
return;
|
|
||||||
}
|
|
@ -36,7 +36,7 @@
|
|||||||
#include "capwap_cisco.h"
|
#include "capwap_cisco.h"
|
||||||
#include "lwapp_cisco.h"
|
#include "lwapp_cisco.h"
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "message_set.h"
|
#include "msget.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
|||||||
|
|
||||||
search.type = msg_id;
|
search.type = msg_id;
|
||||||
|
|
||||||
message = mavl_get_ptr(conn->msgset->messages,&search);
|
message = mavl_get(conn->msgset->msgdata,&search);
|
||||||
|
|
||||||
|
|
||||||
if (!message)
|
if (!message)
|
||||||
|
@ -18,7 +18,7 @@ static void del(void* d)
|
|||||||
|
|
||||||
struct mavl * intavltree_create()
|
struct mavl * intavltree_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cmp,del);
|
return mavl_create(cmp,del,100);
|
||||||
}
|
}
|
||||||
|
|
||||||
int * intavltree_add(struct mavl * t, int val)
|
int * intavltree_add(struct mavl * t, int val)
|
||||||
@ -31,5 +31,5 @@ int * intavltree_add(struct mavl * t, int val)
|
|||||||
if (!v)
|
if (!v)
|
||||||
return NULL;
|
return NULL;
|
||||||
*v=val;
|
*v=val;
|
||||||
return mavl_add(t,v);
|
return mavl_add(t,v,NULL);
|
||||||
}
|
}
|
||||||
|
@ -61,14 +61,14 @@ const cw_itemdef_t * cw_itemdef_get(cw_itemdefheap_t t, const char *id, const ch
|
|||||||
|
|
||||||
cw_itemdefheap_t cw_itemdefheap_create()
|
cw_itemdefheap_t cw_itemdefheap_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cmp, NULL);
|
return mavl_create(cmp, NULL,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cw_itemdefheap_register(cw_itemdefheap_t t, cw_itemdef_t * defs)
|
int cw_itemdefheap_register(cw_itemdefheap_t t, cw_itemdef_t * defs)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (defs->id != CW_ITEM_NONE) {
|
while (defs->id != CW_ITEM_NONE) {
|
||||||
cw_itemdef_t *a = mavl_add(t, defs);
|
cw_itemdef_t *a = mavl_add(t, defs,NULL);
|
||||||
if (a != defs) {
|
if (a != defs) {
|
||||||
cw_log(LOG_ERR, "Duplicated item: %s", defs->id);
|
cw_log(LOG_ERR, "Duplicated item: %s", defs->id);
|
||||||
} else
|
} else
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef __CW_KVSTORE_H
|
|
||||||
#define __CW_KVSTORE_H
|
|
||||||
|
|
||||||
#include "mavl.h"
|
|
||||||
#include "cw_types.h"
|
|
||||||
|
|
||||||
void cw_kvstore_mavl_delete(mavldata_t *data);
|
|
||||||
const char * cw_kvstore_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
|
|
||||||
const uint8_t * data, int len);
|
|
||||||
|
|
||||||
#define cw_kvstore_create()\
|
|
||||||
mavl_create(mavl_cmp_kv, cw_kvstore_mavl_delete)
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CW_KVSTORE_H */
|
|
70
src/cw/kvt.h
Normal file
70
src/cw/kvt.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#ifndef __KVT_H
|
||||||
|
#define __KVT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "mavl.h"
|
||||||
|
|
||||||
|
struct cw_KVT {
|
||||||
|
char *key;
|
||||||
|
union {
|
||||||
|
uint32_t dword;
|
||||||
|
uint16_t word;
|
||||||
|
uint8_t byte;
|
||||||
|
void *ptr;
|
||||||
|
} val;
|
||||||
|
const struct cw_Type *type;
|
||||||
|
};
|
||||||
|
typedef struct cw_KVT cw_KVT_t;
|
||||||
|
|
||||||
|
|
||||||
|
struct cw_Type {
|
||||||
|
/** A human readable name for this type */
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
/** A pointer to a function to delete elements of this type */
|
||||||
|
void (*del) (struct cw_KVT * data);
|
||||||
|
|
||||||
|
/** A method to put this object to a buffer */
|
||||||
|
int (*put) (struct cw_KVT * data, uint8_t * dst);
|
||||||
|
|
||||||
|
/** The get method */
|
||||||
|
struct cw_KVT *(*get) (struct cw_KVT * data, const uint8_t * src, int len);
|
||||||
|
|
||||||
|
/** A pointer to a function to convert elements of this type to a string.
|
||||||
|
This function is mainly used to store elements to an SQL database
|
||||||
|
or to json strings */
|
||||||
|
int (*to_str) (const struct cw_KVT * data, char *dst, int max_len);
|
||||||
|
|
||||||
|
/** Cereate an item of this type from a string, which was previously
|
||||||
|
created by the #del function. */
|
||||||
|
struct cw_KVT *(*from_str) (struct cw_KVT * data, const char *src);
|
||||||
|
|
||||||
|
/*
|
||||||
|
int (*def)(void *, void *);
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct cw_Type cw_type_byte;
|
||||||
|
extern const struct cw_Type cw_type_word;
|
||||||
|
extern const struct cw_Type cw_type_dword;
|
||||||
|
extern const struct cw_Type cw_type_bstr16;
|
||||||
|
|
||||||
|
#define CW_TYPE_BYTE (&cw_type_byte)
|
||||||
|
#define CW_TYPE_WORD (&cw_type_word)
|
||||||
|
#define CW_TYPE_DWORD (&cw_type_dword)
|
||||||
|
#define CW_TYPE_BSTR16 (&cw_type_bstr16)
|
||||||
|
|
||||||
|
/*
|
||||||
|
void cw_kvstore_mavl_delete(const void *data);
|
||||||
|
*/
|
||||||
|
const char *cw_kvt_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
|
||||||
|
const uint8_t * data, int len);
|
||||||
|
|
||||||
|
int cw_kvt_mavlcmp(const void *v1, const void *v2);
|
||||||
|
void cw_kvt_mavldel(void *data);
|
||||||
|
|
||||||
|
#define cw_kvt_create()\
|
||||||
|
mavl_create(cw_kvt_mavlcmp, cw_kvt_mavldel, sizeof(cw_KVT_t))
|
||||||
|
|
||||||
|
#endif /* __KVT_H */
|
124
src/cw/mavl.h
124
src/cw/mavl.h
@ -18,16 +18,17 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief MAVL, Mini AVL Tree,
|
* @brief MAVL, Mini AVL Tree,
|
||||||
* Yet another AVL Tree implementation!
|
* Yet another AVL Tree implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup MAVL MAVL
|
* @addtogroup DATAMGMT
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __MAVL_H
|
#ifndef __MAVL_H
|
||||||
#define __MAVL_H
|
#define __MAVL_H
|
||||||
|
|
||||||
@ -38,8 +39,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup MAV_CONSTANTS Constants
|
* @defgroup MAVL_CONSTANTS Constants
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -53,28 +56,10 @@
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct mavl_KeyVal{
|
/**
|
||||||
char *key;
|
* @addtogroup MAVLStructures Structures
|
||||||
const void *priv;
|
* @{
|
||||||
union{
|
*/
|
||||||
void * ptr;
|
|
||||||
uint32_t dword;
|
|
||||||
uint16_t word;
|
|
||||||
uint8_t byte;
|
|
||||||
char * str;
|
|
||||||
}val;
|
|
||||||
};
|
|
||||||
|
|
||||||
union mavldata {
|
|
||||||
void *ptr;
|
|
||||||
uint32_t dword;
|
|
||||||
uint16_t word;
|
|
||||||
uint8_t byte;
|
|
||||||
char *str;
|
|
||||||
struct mavl_KeyVal kv;
|
|
||||||
};
|
|
||||||
typedef union mavldata mavldata_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,11 +78,8 @@ struct mavlnode {
|
|||||||
int bal;
|
int bal;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define mavlnode_data(node) ((node)+sizeof(struct mavlnode))
|
|
||||||
|
|
||||||
#define mavlnode_copy_data(tree,dst,src)\
|
|
||||||
memcpy(mavlnode_data(dst),mavlnode_data(src),\
|
|
||||||
(tree)->data_size)
|
|
||||||
/**
|
/**
|
||||||
* AVL Tree
|
* AVL Tree
|
||||||
*/
|
*/
|
||||||
@ -105,15 +87,20 @@ struct mavl {
|
|||||||
/** Pointer to root node */
|
/** Pointer to root node */
|
||||||
struct mavlnode *root;
|
struct mavlnode *root;
|
||||||
/** Compare function */
|
/** Compare function */
|
||||||
int (*cmp) (const union mavldata *, const union mavldata *);
|
int ( *cmp ) ( const void *, const void * );
|
||||||
/** Delete element function */
|
/** Delete element function */
|
||||||
void (*del) (union mavldata *);
|
void ( *del ) ( void * );
|
||||||
/** Number of elements currently stored in the tree */
|
/** Number of elements currently stored in the tree */
|
||||||
int count;
|
int count;
|
||||||
|
/** size of data appended to each mavlnode element.
|
||||||
|
* used to allocate space in #mavl_add. */
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MAVL AVL Tree type
|
* MAVL AVL Tree type
|
||||||
*/
|
*/
|
||||||
@ -125,25 +112,30 @@ typedef struct mavl * mavl_t;
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node node
|
||||||
|
*/
|
||||||
|
#define mavlnode_dataptr(node) (((uint8_t*)(node))+sizeof(struct mavlnode))
|
||||||
|
|
||||||
struct mavl *mavl_create ( int ( *cmp ) ( const void *, const void * ),
|
struct mavl *mavl_create ( int ( *cmp ) ( const void *, const void * ),
|
||||||
void ( *del ) ( void * ), size_t data_size );
|
void ( *del ) ( void * ), size_t data_size );
|
||||||
|
|
||||||
void mavlnode_destroy(struct mavl *t, struct mavlnode *n);
|
void *mavl_add ( struct mavl *t, const void *data, int *exists );
|
||||||
|
/*void *mavl_add ( struct mavl *t, const void *data );*/
|
||||||
|
void * mavl_get ( struct mavl *t , void *data );
|
||||||
|
void *mavl_del ( struct mavl *t, const void *data );
|
||||||
|
void *mavl_replace ( struct mavl *t, const void *data, int * result );
|
||||||
|
void mavl_destroy ( struct mavl *t );
|
||||||
void mavl_del_all ( struct mavl *t );
|
void mavl_del_all ( struct mavl *t );
|
||||||
union mavldata *mavl_del(struct mavl *t, union mavldata *data);
|
|
||||||
union mavldata *mavl_add(struct mavl *t, union mavldata *data);
|
|
||||||
union mavldata * mavl_get(struct mavl *t ,union mavldata *data);
|
|
||||||
struct mavlnode *mavl_get_node(struct mavl *t, void *data);
|
|
||||||
void * mavl_get_ptr(mavl_t tree, void * search);
|
|
||||||
void *mavl_add_ptr(mavl_t tree, void *ptr);
|
|
||||||
|
|
||||||
int mavl_cmp_kv(const union mavldata *e1, const union mavldata *e2);
|
|
||||||
union mavldata *mavl_add_kv_byte(mavl_t tree, const char *key, uint8_t val);
|
|
||||||
|
|
||||||
void mavl_merge ( mavl_t m, mavl_t t );
|
void mavl_merge ( mavl_t m, mavl_t t );
|
||||||
|
void mavlnode_destroy ( struct mavl *t, struct mavlnode *n );
|
||||||
|
struct mavlnode *mavl_get_node ( struct mavl *t, void *data );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int mavl_foreach_lr ( struct mavlnode *n, int ( *callback ) ( void *, void * ),
|
extern int mavl_foreach_lr ( struct mavlnode *n, int ( *callback ) ( void *, void * ),
|
||||||
@ -153,6 +145,8 @@ extern int mavl_foreach_rl(struct mavlnode *n, int (*callback) (void *, void *),
|
|||||||
int mavl_foreach_from_lr ( struct mavl *t, struct mavlnode *n, void *data,
|
int mavl_foreach_from_lr ( struct mavl *t, struct mavlnode *n, void *data,
|
||||||
int ( *callback ) ( void *, void * ), void *cbpriv );
|
int ( *callback ) ( void *, void * ), void *cbpriv );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -161,10 +155,6 @@ int mavl_foreach_from_lr(struct mavl *t, struct mavlnode *n, void *data,
|
|||||||
|
|
||||||
void *mavl_replace_data ( struct mavl *t, void *data, int len );
|
void *mavl_replace_data ( struct mavl *t, void *data, int len );
|
||||||
|
|
||||||
union mavldata *mavl_replace(struct mavl *t,union mavldata *data);
|
|
||||||
|
|
||||||
|
|
||||||
void mavl_destroy(struct mavl *t);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -185,7 +175,7 @@ struct mavliter{
|
|||||||
struct mavlnode *cur;
|
struct mavlnode *cur;
|
||||||
int stack_ptr;
|
int stack_ptr;
|
||||||
struct mavlnode * root;
|
struct mavlnode * root;
|
||||||
int (*cmp) (const union mavldata *, const union mavldata *);
|
int ( *cmp ) ( const void *, const void * );
|
||||||
|
|
||||||
};
|
};
|
||||||
typedef struct mavliter mavliter_t;
|
typedef struct mavliter mavliter_t;
|
||||||
@ -200,6 +190,8 @@ void mavliter_init(mavliter_t *i, mavl_t t);
|
|||||||
|
|
||||||
void * mavliter_get ( mavliter_t *i );
|
void * mavliter_get ( mavliter_t *i );
|
||||||
|
|
||||||
|
void * mavliter_get_ptr(mavliter_t *i);
|
||||||
|
|
||||||
extern union mavldata * mavliter_seek ( mavliter_t *i, void *d );
|
extern union mavldata * mavliter_seek ( mavliter_t *i, void *d );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,11 +244,9 @@ extern union mavldata * mavliter_seek(mavliter_t *i,void *d);
|
|||||||
typedef mavl_t mavl_conststr_t;
|
typedef mavl_t mavl_conststr_t;
|
||||||
extern mavl_conststr_t mavl_create_conststr();
|
extern mavl_conststr_t mavl_create_conststr();
|
||||||
|
|
||||||
int mavl_cmp_dword(const union mavldata *e1, const union mavldata *e2);
|
/*
|
||||||
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2);
|
//int mavl_cmp_str ( const union mavldata *e1, const union mavldata *e2 );
|
||||||
|
*/
|
||||||
void mavl_free_bin(union mavldata *data);
|
|
||||||
void mavl_free_str(union mavldata *data);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -281,8 +271,26 @@ static inline void *mavl_replace(struct mavl *t,void *data){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @} */
|
void mavl_freeptr(void *ptr);
|
||||||
|
#define mavl_create_ptr(cmp,del)\
|
||||||
|
mavl_create(cmp,del,sizeof(void*))
|
||||||
|
int mavl_cmpstr(const void *p1, const void *p2);
|
||||||
|
#define mavl_create_str() mavl_create_ptr(mavl_cmpstr,mavl_freeptr)
|
||||||
|
|
||||||
|
void * mavl_get_ptr ( mavl_t tree, void * search );
|
||||||
|
void * mavl_add_ptr ( mavl_t tree, void *ptr );
|
||||||
|
|
||||||
|
#define mavl_add_str(tree,str) mavl_add_ptr(tree,str)
|
||||||
|
#define mavl_get_str(tree,search) ((char *)(mavl_get_ptr(tree,search)))
|
||||||
|
#define mavliter_get_str(iter) ((char*)(mavliter_get_ptr(iter)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
* datamanag
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,40 +1,47 @@
|
|||||||
#include "mavl.h"
|
#include "mavl.h"
|
||||||
|
|
||||||
static struct mavlnode *mavlnode_create(const union mavldata *data)
|
static struct mavlnode *mavlnode_create ( struct mavl *t, const void *data )
|
||||||
{
|
{
|
||||||
struct mavlnode *n = malloc(sizeof(struct mavlnode));
|
struct mavlnode *n = malloc ( sizeof ( struct mavlnode ) + t->data_size );
|
||||||
|
|
||||||
if ( !n )
|
if ( !n )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
n->left = n->right = 0;
|
n->left = n->right = NULL;
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
n->data = *data;
|
|
||||||
|
/*n->data = *data;*/
|
||||||
|
memcpy ( mavlnode_dataptr ( n ), data, t->data_size );
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int mavl_add0 ( struct mavl *t, struct mavlnode **parent, const void ** data )
|
||||||
|
|
||||||
static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata ** data)
|
|
||||||
{
|
{
|
||||||
struct mavlnode *tmp;
|
struct mavlnode *tmp;
|
||||||
|
|
||||||
struct mavlnode *n = *parent;
|
struct mavlnode *n = *parent;
|
||||||
int rc = t->cmp(*data, &n->data);
|
int rc = t->cmp ( *data, mavlnode_dataptr ( n ) );
|
||||||
|
|
||||||
int bal;
|
int bal;
|
||||||
|
|
||||||
if ( rc == 0 ) {
|
if ( rc == 0 ) {
|
||||||
*data = &n->data;
|
/* *data = &n->data;*/
|
||||||
|
|
||||||
|
/* memcpy(data,mavlnode_dataptr(n),t->data_size);*/
|
||||||
|
*data = mavlnode_dataptr ( n );
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
if ( n->left ) {
|
if ( n->left ) {
|
||||||
bal = mavl_add0 ( t, &n->left, data );
|
bal = mavl_add0 ( t, &n->left, data );
|
||||||
|
|
||||||
if ( bal > 1 )
|
if ( bal > 1 )
|
||||||
return bal;
|
return bal;
|
||||||
|
|
||||||
n->bal -= bal;
|
n->bal -= bal;
|
||||||
|
|
||||||
if ( n->bal == 0 )
|
if ( n->bal == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -48,14 +55,18 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
n->left = tmp;
|
n->left = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( n->left->bal == 1 ) {
|
if ( n->left->bal == 1 ) {
|
||||||
*parent = n->left->right;
|
*parent = n->left->right;
|
||||||
|
|
||||||
if ( ( *parent )->bal == 1 ) {
|
if ( ( *parent )->bal == 1 ) {
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
n->left->bal = -1;
|
n->left->bal = -1;
|
||||||
|
|
||||||
} else if ( ( *parent )->bal == -1 ) {
|
} else if ( ( *parent )->bal == -1 ) {
|
||||||
n->bal = 1;
|
n->bal = 1;
|
||||||
n->left->bal = 0;
|
n->left->bal = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
n->left->bal = 0;
|
n->left->bal = 0;
|
||||||
@ -72,12 +83,15 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bal;
|
return bal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* n->left is 0 */
|
/* n->left is 0 */
|
||||||
n->left = mavlnode_create(*data);
|
n->left = mavlnode_create ( t, *data );
|
||||||
|
*data = mavlnode_dataptr(n->left);
|
||||||
|
|
||||||
if ( !n->left )
|
if ( !n->left )
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
@ -94,10 +108,12 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
} else {
|
} else {
|
||||||
if ( n->right ) {
|
if ( n->right ) {
|
||||||
bal = mavl_add0 ( t, &n->right, data );
|
bal = mavl_add0 ( t, &n->right, data );
|
||||||
|
|
||||||
if ( bal > 1 )
|
if ( bal > 1 )
|
||||||
return bal;
|
return bal;
|
||||||
|
|
||||||
n->bal += bal;
|
n->bal += bal;
|
||||||
|
|
||||||
if ( n->bal == 0 )
|
if ( n->bal == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -110,15 +126,18 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
n->right->left = n;
|
n->right->left = n;
|
||||||
n->right = tmp;
|
n->right = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else if ( n->right->bal == -1 ) {
|
} else if ( n->right->bal == -1 ) {
|
||||||
*parent = n->right->left;
|
*parent = n->right->left;
|
||||||
|
|
||||||
if ( ( *parent )->bal == -1 ) {
|
if ( ( *parent )->bal == -1 ) {
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
n->right->bal = 1;
|
n->right->bal = 1;
|
||||||
|
|
||||||
} else if ( ( *parent )->bal == 1 ) {
|
} else if ( ( *parent )->bal == 1 ) {
|
||||||
n->bal = -1;
|
n->bal = -1;
|
||||||
n->right->bal = 0;
|
n->right->bal = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
n->right->bal = 0;
|
n->right->bal = 0;
|
||||||
@ -132,23 +151,27 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
n->right = tmp;
|
n->right = tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return bal;
|
|
||||||
|
|
||||||
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* n->right is 0 */
|
/* n->right is 0 */
|
||||||
|
|
||||||
n->right = mavlnode_create(*data);
|
n->right = mavlnode_create ( t, *data );
|
||||||
|
*data = mavlnode_dataptr(n->right);
|
||||||
|
|
||||||
|
|
||||||
if ( !n->right )
|
if ( !n->right )
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
t->count++;
|
t->count++;
|
||||||
|
|
||||||
if ( n->left == 0 ) {
|
if ( n->left == 0 ) {
|
||||||
n->bal = 1;
|
n->bal = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->bal = 0;
|
n->bal = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -169,29 +192,42 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata **
|
|||||||
* @example mavl_add_example.c
|
* @example mavl_add_example.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
union mavldata *mavl_add(struct mavl *t, union mavldata *data)
|
void *mavl_add ( struct mavl *t, const void *data, int *exists )
|
||||||
{
|
{
|
||||||
union mavldata * d;
|
const void * d;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
|
||||||
if ( t->root == NULL ) {
|
if ( t->root == NULL ) {
|
||||||
t->root = mavlnode_create(data);
|
t->root = mavlnode_create ( t, data );
|
||||||
|
|
||||||
if ( t->root )
|
if ( t->root )
|
||||||
t->count++;
|
t->count++;
|
||||||
|
|
||||||
/* return &t->root->data; */
|
/* return &t->root->data; */
|
||||||
return data;
|
if (exists != NULL)
|
||||||
|
*exists=0;
|
||||||
|
return mavlnode_dataptr(t->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
d = data;
|
d = data;
|
||||||
|
|
||||||
rc = mavl_add0 ( t, &t->root, &d );
|
rc = mavl_add0 ( t, &t->root, &d );
|
||||||
|
|
||||||
if (rc > 3)
|
if ( rc >= 3 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if ( exists != NULL){
|
||||||
|
if (rc==2)
|
||||||
|
*exists=1;
|
||||||
|
else
|
||||||
|
*exists=0;
|
||||||
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void *mavl_add ( struct mavl *t, const void *data)
|
||||||
|
{
|
||||||
|
return mavl_add_exists(t,data,NULL);
|
||||||
|
}
|
||||||
|
*/
|
@ -1,9 +0,0 @@
|
|||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
union mavldata *mavl_add_kv_byte(mavl_t tree, const char *key, uint8_t val)
|
|
||||||
{
|
|
||||||
mavldata_t data;
|
|
||||||
data.kv.key = key;
|
|
||||||
data.kv.val.byte = val;
|
|
||||||
return mavl_add(tree, &data);
|
|
||||||
}
|
|
@ -1,10 +1,9 @@
|
|||||||
#include "mavl.h"
|
#include "mavl.h"
|
||||||
|
|
||||||
void *mavl_add_ptr(mavl_t tree, void *ptr){
|
void *mavl_add_ptr(mavl_t tree, void *ptr){
|
||||||
mavldata_t data, *result;
|
void * result;
|
||||||
data.ptr = ptr;
|
result = mavl_add(tree,&ptr,NULL);
|
||||||
result = mavl_add(tree,&data);
|
|
||||||
if (result)
|
if (result)
|
||||||
return result->ptr;
|
return *(void**)result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
const char * mavl_add_strdup(mavl_t t, const char * str)
|
|
||||||
{
|
|
||||||
mavldata_t s, *result;
|
|
||||||
s.str = strdup(str);
|
|
||||||
if (!s.str)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
result = mavl_add(t,&s);
|
|
||||||
if (!result){
|
|
||||||
free(s.str);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result->str;
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
int mavl_cmp_dword(const union mavldata *e1, const union mavldata *e2){
|
|
||||||
return e1->dword - e2->dword;
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
int mavl_cmp_kv(const union mavldata *e1, const union mavldata *e2){
|
|
||||||
return strcmp(e1->kv.key, e2->kv.key);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2){
|
|
||||||
return strcmp (e1->str,e2->str);
|
|
||||||
}
|
|
6
src/cw/mavl_cmpstr.c
Normal file
6
src/cw/mavl_cmpstr.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "mavl.h"
|
||||||
|
|
||||||
|
int mavl_cmpstr (const void *s1, const void *s2)
|
||||||
|
{
|
||||||
|
return strcmp( *((const char**)s1), *((const char**)s2));
|
||||||
|
}
|
@ -18,17 +18,19 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*@file
|
*@file
|
||||||
*@Implementation of mavl_create
|
*@brief Implementation of mavl_create
|
||||||
*@addtogroup MavlFunctions
|
*@addtogroup MavlFunctions
|
||||||
*@{
|
*@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mavl.h"
|
#include "mavl.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an AVL tree
|
* Create an AVL tree
|
||||||
* @param cmp pointer compare function
|
* @param cmp pointer to compare function
|
||||||
* @param del pointer to delete function which is called when an element will be deletet
|
* @param del pointer to delete function which is called when an element
|
||||||
* @return pointer to an #mavl struct
|
* will be deletet
|
||||||
|
* @return pointer to a #mavl struct
|
||||||
*/
|
*/
|
||||||
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
|
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
|
||||||
void (*del) (void *), size_t data_size)
|
void (*del) (void *), size_t data_size)
|
||||||
@ -40,6 +42,7 @@
|
|||||||
t->count = 0;
|
t->count = 0;
|
||||||
t->cmp = cmp;
|
t->cmp = cmp;
|
||||||
t->del = del;
|
t->del = del;
|
||||||
|
t->data_size=data_size;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,5 +39,5 @@ static int cmp(const void *v1,const void*v2)
|
|||||||
|
|
||||||
mavl_conststr_t mavl_create_conststr()
|
mavl_conststr_t mavl_create_conststr()
|
||||||
{
|
{
|
||||||
return mavl_create(cmp,NULL);
|
return mavl_create(cmp,NULL,1312);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
void mavlnode_destroy(struct mavl *t, struct mavlnode *n)
|
void mavlnode_destroy(struct mavl *t, struct mavlnode *n)
|
||||||
{
|
{
|
||||||
if (t->del) {
|
if (t->del) {
|
||||||
t->del(&n->data);
|
t->del(mavlnode_dataptr(n));
|
||||||
}
|
}
|
||||||
free(n);
|
free(n);
|
||||||
t->count--;
|
t->count--;
|
||||||
@ -107,12 +107,12 @@ static int adj_bal_r(struct mavlnode *n, struct mavlnode **parent)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
|
static int mavl_del_lo(mavl_t t, struct mavlnode **parent, void *data)
|
||||||
{
|
{
|
||||||
struct mavlnode *n = *parent;
|
struct mavlnode *n = *parent;
|
||||||
|
|
||||||
if (n->left != 0) {
|
if (n->left != 0) {
|
||||||
int bal = mavl_del_lo(&n->left, data);
|
int bal = mavl_del_lo(t, &n->left, data);
|
||||||
n->bal += bal;
|
n->bal += bal;
|
||||||
if (n->bal == 1) {
|
if (n->bal == 1) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -126,7 +126,9 @@ static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
|
|||||||
/* found the lowest element */
|
/* found the lowest element */
|
||||||
|
|
||||||
*parent = n->right;
|
*parent = n->right;
|
||||||
*data = n->data;
|
/* *data = n->data;*/
|
||||||
|
memcpy(data,mavlnode_dataptr(n),t->data_size);
|
||||||
|
|
||||||
free(n);
|
free(n);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -143,12 +145,12 @@ static int mavl_del_lo(struct mavlnode **parent, union mavldata *data)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
|
int mavl_del0(struct mavl *t, struct mavlnode **parent, void *data)
|
||||||
{
|
{
|
||||||
struct mavlnode *n = *parent;
|
struct mavlnode *n = *parent;
|
||||||
int rc;
|
int rc;
|
||||||
int bal;
|
int bal;
|
||||||
rc = t->cmp(data, &n->data);
|
rc = t->cmp(data, mavlnode_dataptr(n));
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
if (n->right == 0 && n->left == 0) {
|
if (n->right == 0 && n->left == 0) {
|
||||||
@ -174,10 +176,10 @@ int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
|
|||||||
/* node has two childs */
|
/* node has two childs */
|
||||||
|
|
||||||
if (t->del) {
|
if (t->del) {
|
||||||
t->del(&n->data);
|
t->del(mavlnode_dataptr(n));
|
||||||
}
|
}
|
||||||
t->count--;
|
t->count--;
|
||||||
bal = mavl_del_lo(&n->right, &n->data);
|
bal = mavl_del_lo(t,&n->right, mavlnode_dataptr(n));
|
||||||
n->bal -= bal;
|
n->bal -= bal;
|
||||||
if (n->bal == -1)
|
if (n->bal == -1)
|
||||||
return 0;
|
return 0;
|
||||||
@ -228,9 +230,9 @@ int mavl_del0(struct mavl *t, struct mavlnode **parent, union mavldata *data)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
union mavldata *mavl_del(struct mavl *t, union mavldata *data)
|
void *mavl_del(struct mavl *t, const void *data)
|
||||||
{
|
{
|
||||||
union mavldata *d;
|
void *d;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!t->root)
|
if (!t->root)
|
||||||
|
@ -24,7 +24,7 @@ int mavl_foreach_rl(struct mavlnode *n, int (*callback)(void *,void *),void *cbp
|
|||||||
return 1;
|
return 1;
|
||||||
if (!mavl_foreach_rl(n->right,callback,cbpriv))
|
if (!mavl_foreach_rl(n->right,callback,cbpriv))
|
||||||
return 0;
|
return 0;
|
||||||
if (!callback(cbpriv,&n->data))
|
if (!callback(cbpriv,mavlnode_dataptr(n)))
|
||||||
return 0;
|
return 0;
|
||||||
return mavl_foreach_rl(n->left,callback,cbpriv);
|
return mavl_foreach_rl(n->left,callback,cbpriv);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ int mavl_foreach_lr(struct mavlnode *n, int (*callback)(void *,void *),void *cbp
|
|||||||
return 1;
|
return 1;
|
||||||
if (!mavl_foreach_lr(n->left,callback,cbpriv))
|
if (!mavl_foreach_lr(n->left,callback,cbpriv))
|
||||||
return 0;
|
return 0;
|
||||||
if (!callback(cbpriv,&n->data))
|
if (!callback(cbpriv,mavlnode_dataptr(n)))
|
||||||
return 0;
|
return 0;
|
||||||
return mavl_foreach_lr(n->right,callback,cbpriv);
|
return mavl_foreach_lr(n->right,callback,cbpriv);
|
||||||
|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
void mavl_free_bin(union mavldata *data){
|
|
||||||
free(data->ptr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
#include "mavl.h"
|
|
||||||
|
|
||||||
void mavl_free_str(union mavldata *data){
|
|
||||||
free(data->str);
|
|
||||||
}
|
|
||||||
|
|
5
src/cw/mavl_freeptr.c
Normal file
5
src/cw/mavl_freeptr.c
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "mavl.h"
|
||||||
|
|
||||||
|
void mavl_freeptr(void *ptr){
|
||||||
|
free( *((void**)ptr) );
|
||||||
|
}
|
@ -29,13 +29,13 @@
|
|||||||
* @param data Element to get
|
* @param data Element to get
|
||||||
* @return pointer to element or NULL if not found.
|
* @return pointer to element or NULL if not found.
|
||||||
*/
|
*/
|
||||||
union mavldata * mavl_get(struct mavl *t ,union mavldata *data)
|
void * mavl_get(struct mavl *t ,void *data)
|
||||||
{
|
{
|
||||||
struct mavlnode *n = t->root;
|
struct mavlnode *n = t->root;
|
||||||
while(n){
|
while(n){
|
||||||
int rc=t->cmp(data,&n->data);
|
int rc=t->cmp(data,mavlnode_dataptr(n));
|
||||||
if (rc==0)
|
if (rc==0)
|
||||||
return &n->data;
|
return mavlnode_dataptr(n);
|
||||||
if (rc<0)
|
if (rc<0)
|
||||||
n=n->left;
|
n=n->left;
|
||||||
else
|
else
|
||||||
|
@ -26,7 +26,7 @@ struct mavlnode * mavl_get_node(struct mavl *t ,void *data)
|
|||||||
{
|
{
|
||||||
struct mavlnode *n = t->root;
|
struct mavlnode *n = t->root;
|
||||||
while(n){
|
while(n){
|
||||||
int rc=t->cmp(data,&n->data);
|
int rc=t->cmp(data,mavlnode_dataptr(n));
|
||||||
if (rc==0)
|
if (rc==0)
|
||||||
return n;
|
return n;
|
||||||
if (rc<0)
|
if (rc<0)
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
void * mavl_get_ptr(mavl_t tree, void * search)
|
void * mavl_get_ptr(mavl_t tree, void * search)
|
||||||
{
|
{
|
||||||
mavldata_t search_data, *result;
|
void * result;
|
||||||
search_data.ptr=search;
|
|
||||||
result = mavl_find(tree,&search_data);
|
result = mavl_find(tree,&search);
|
||||||
if (result)
|
if (result)
|
||||||
return result->ptr;
|
return *(void**)result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,17 @@
|
|||||||
|
|
||||||
static void mavlnode_move(mavl_t m,mavl_t t, struct mavlnode *n)
|
static void mavlnode_move(mavl_t m,mavl_t t, struct mavlnode *n)
|
||||||
{
|
{
|
||||||
struct mavlnode * mn = mavl_get_node(m,mavlnode_data(n));
|
struct mavlnode * mn = mavl_get_node(m,mavlnode_dataptr(n));
|
||||||
if (mn) {
|
if (mn) {
|
||||||
if (m->del) {
|
if (m->del) {
|
||||||
m->del(mavlnode_data(mn));
|
m->del(mavlnode_dataptr(mn));
|
||||||
}
|
}
|
||||||
/*mn->data=n->data;*/
|
/*mn->data=n->data;*/
|
||||||
mavlnode_copy_data(m,mn,n);
|
memcpy(mavlnode_dataptr(mn),mavlnode_dataptr(n),t->data_size);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/*mavl_add(m,&n->data);*/
|
/*mavl_add(m,&n->data);*/
|
||||||
mavl_add(m,mavlnode_data(n));
|
mavl_add(m,mavlnode_dataptr(n),NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(n);
|
free(n);
|
||||||
|
@ -1,15 +1,38 @@
|
|||||||
#include "mavl.h"
|
#include "mavl.h"
|
||||||
|
|
||||||
union mavldata *mavl_replace(struct mavl *t,void *data){
|
void *mavl_replace(struct mavl *t,const void *data, int * replaced){
|
||||||
|
|
||||||
|
int exists;
|
||||||
|
void * add = mavl_add(t,data,&exists);
|
||||||
|
|
||||||
|
if (replaced != NULL){
|
||||||
|
*replaced = exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists){
|
||||||
|
return add;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(t->del){
|
||||||
|
t->del(add);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(add,data,t->data_size);
|
||||||
|
return add;
|
||||||
|
|
||||||
|
/*
|
||||||
struct mavlnode * node = mavl_get_node(t,data);
|
struct mavlnode * node = mavl_get_node(t,data);
|
||||||
if (node){
|
if (node){
|
||||||
if (t->del)
|
if (t->del)
|
||||||
t->del(node+sizeof(struct mavlnode));
|
t->del(node+sizeof(struct mavlnode));
|
||||||
/* node->data=*data;
|
// node->data=*data;
|
||||||
*/ mavlnode_copy_data(node+sizeof(struct mavlnode), data);
|
memcpy(mavlnode_dataptr(node), data, t->data_size);
|
||||||
return &node->data;
|
|
||||||
|
// return &node->data;
|
||||||
|
return mavlnode_dataptr(node);
|
||||||
}
|
}
|
||||||
return mavl_add(t,data);
|
return mavl_add(t,data);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
* @param i AVL Iterator
|
* @param i AVL Iterator
|
||||||
* @return element or NULL if not found.
|
* @return element or NULL if not found.
|
||||||
*/
|
*/
|
||||||
void * mavliter_get(mavliter_t *i){
|
void * mavliter_get(mavliter_t *i)
|
||||||
|
{
|
||||||
if (!i->cur)
|
if (!i->cur)
|
||||||
return NULL;
|
return NULL;
|
||||||
/*return &i->cur->data; */
|
|
||||||
|
return mavlnode_dataptr(i->cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
15
src/cw/mavliter_get_ptr.c
Normal file
15
src/cw/mavliter_get_ptr.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "mavl.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element, where AVL Iterator currently is positioned.
|
||||||
|
* @param i AVL Iterator
|
||||||
|
* @return element or NULL if not found.
|
||||||
|
*/
|
||||||
|
void * mavliter_get_ptr(mavliter_t *i)
|
||||||
|
{
|
||||||
|
/*void * data;*/
|
||||||
|
if (!i->cur)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return *(void**)(mavlnode_dataptr(i->cur));
|
||||||
|
}
|
@ -10,10 +10,9 @@
|
|||||||
*
|
*
|
||||||
* @See mavliter_t,
|
* @See mavliter_t,
|
||||||
*/
|
*/
|
||||||
void mavliter_init(mavliter_t *i, mavl_t t){
|
void mavliter_init ( mavliter_t *i, mavl_t t )
|
||||||
|
{
|
||||||
i->root = t->root;
|
i->root = t->root;
|
||||||
i->stack_ptr = 0;
|
i->stack_ptr = 0;
|
||||||
i->cmp = t->cmp;
|
i->cmp = t->cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
union mavldata * mavliter_next ( mavliter_t *i )
|
union mavldata * mavliter_next ( mavliter_t *i )
|
||||||
{
|
{
|
||||||
|
|
||||||
while ( i->stack_ptr ) {
|
while ( i->stack_ptr ) {
|
||||||
i->stack_ptr--;
|
i->stack_ptr--;
|
||||||
i->cur = i->stack[i->stack_ptr];
|
i->cur = i->stack[i->stack_ptr];
|
||||||
@ -40,13 +39,13 @@ union mavldata * mavliter_next(mavliter_t *i)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( ( i->stack_ptr ) & 1 ) {
|
if ( ( i->stack_ptr ) & 1 ) {
|
||||||
return &i->cur->data;
|
/*return &i->cur->data;*/
|
||||||
|
return mavlnode_dataptr ( i->cur );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( !i->cur ) {
|
if ( !i->cur ) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -59,12 +58,11 @@ union mavldata * mavliter_next(mavliter_t *i)
|
|||||||
i->stack[i->stack_ptr++] = i->cur;
|
i->stack[i->stack_ptr++] = i->cur;
|
||||||
|
|
||||||
i->cur = i->cur->left;
|
i->cur = i->cur->left;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i->stack[i->stack_ptr++] = i->cur->right;
|
i->stack[i->stack_ptr++] = i->cur->right;
|
||||||
|
|
||||||
return &i->cur->data;
|
/* return &i->cur->data;*/
|
||||||
|
return mavlnode_dataptr ( i->cur );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ union mavldata * mavliter_seek(mavliter_t *i,void *d)
|
|||||||
|
|
||||||
while(i->cur) {
|
while(i->cur) {
|
||||||
|
|
||||||
rc = i->cmp(d,&i->cur->data);
|
/* rc = i->cmp(d,&i->cur->data); */
|
||||||
|
rc = i->cmp(d,mavlnode_dataptr(i->cur));
|
||||||
if (rc==0){
|
if (rc==0){
|
||||||
i->stack[i->stack_ptr++]=i->cur->right;
|
i->stack[i->stack_ptr++]=i->cur->right;
|
||||||
i->stack[i->stack_ptr++]=i->cur;
|
i->stack[i->stack_ptr++]=i->cur;
|
||||||
|
@ -6,5 +6,3 @@ union mavldata * mavliter_seek_set(struct mavliter *i)
|
|||||||
i->cur = i->root;
|
i->cur = i->root;
|
||||||
return mavliter_next ( i );
|
return mavliter_next ( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,13 +146,13 @@ static int mbag_i_cmp_fun(const void *x1, const void *x2)
|
|||||||
|
|
||||||
mbag_t mbag_i_create()
|
mbag_t mbag_i_create()
|
||||||
{
|
{
|
||||||
return mavl_create(mbag_i_cmp_fun, mbag_i_del_fun);
|
return mavl_create(mbag_i_cmp_fun, mbag_i_del_fun,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mbag_t mbag_create()
|
mbag_t mbag_create()
|
||||||
{
|
{
|
||||||
return mavl_create(mbag_cmp_fun, mbag_del_fun);
|
return mavl_create(mbag_cmp_fun, mbag_del_fun,1312);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ struct mbag_item *mbag_item_create(mbag_t s, const char *id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
i->u1.id = id;
|
i->u1.id = id;
|
||||||
i->dynid=0;
|
i->dynid=0;
|
||||||
return mavl_add(s, i);
|
return mavl_add(s, i,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ struct mbag_item *mbag_i_item_create(mbag_t s, uint32_t id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
i->u1.iid = id;
|
i->u1.iid = id;
|
||||||
i->dynid=0;
|
i->dynid=0;
|
||||||
return mavl_add(s, i);
|
return mavl_add(s, i,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ struct mbag_item *strmbag_item_create(mbag_t s, char *name)
|
|||||||
int mbag_set(mbag_t t,mbag_item_t *is)
|
int mbag_set(mbag_t t,mbag_item_t *is)
|
||||||
{
|
{
|
||||||
mavl_del(t,is);
|
mavl_del(t,is);
|
||||||
mavl_add(t,is);
|
mavl_add(t,is,NULL);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -55,4 +55,3 @@ int cw_fgetmd5sum(uint8_t *digest, FILE *infile)
|
|||||||
md5_digest ( &ctx, MD5_DIGEST_SIZE, digest );
|
md5_digest ( &ctx, MD5_DIGEST_SIZE, digest );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ struct mlist {
|
|||||||
struct mlist_elem *first;
|
struct mlist_elem *first;
|
||||||
struct mlist_elem *last;
|
struct mlist_elem *last;
|
||||||
int count;
|
int count;
|
||||||
//size_t elem_size;
|
/* //size_t elem_size;*/
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct mlist * mlist_t;
|
typedef struct mlist * mlist_t;
|
||||||
|
18
src/cw/mod.c
18
src/cw/mod.c
@ -31,7 +31,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw/message_set.h"
|
#include "cw/msget.h"
|
||||||
|
|
||||||
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
|
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
|
||||||
struct cw_actiondef * actions) = NULL;
|
struct cw_actiondef * actions) = NULL;
|
||||||
@ -77,10 +77,10 @@ struct cw_Mod mod_null = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int cmp(const mavldata_t *p1, const mavldata_t *p2)
|
static int cmp(const void *p1, const void *p2)
|
||||||
{
|
{
|
||||||
struct cache_item *c1 = (struct cache_item *) p1->ptr;
|
struct cache_item *c1 = ((struct cache_item **) p1)[0];
|
||||||
struct cache_item *c2 = (struct cache_item *) p2->ptr;
|
struct cache_item *c2 = ((struct cache_item **) p2)[0];
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
r = strcmp(c1->capwap, c2->capwap);
|
r = strcmp(c1->capwap, c2->capwap);
|
||||||
@ -104,7 +104,7 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
|||||||
struct cw_MsgSet * set;
|
struct cw_MsgSet * set;
|
||||||
|
|
||||||
if (!msgset_cache) {
|
if (!msgset_cache) {
|
||||||
msgset_cache = mavl_create(cmp, NULL);
|
msgset_cache = mavl_create(cmp, NULL,1312);
|
||||||
if (!msgset_cache) {
|
if (!msgset_cache) {
|
||||||
cw_log(LOG_ERR, "Can't initialize msgset cache: %s",
|
cw_log(LOG_ERR, "Can't initialize msgset cache: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -164,9 +164,9 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
|||||||
|
|
||||||
/* static mavl to store modules */
|
/* static mavl to store modules */
|
||||||
static struct mavl * mods_loaded = NULL;
|
static struct mavl * mods_loaded = NULL;
|
||||||
static int mod_cmp_mavl(const mavldata_t *e1, const mavldata_t *e2){
|
static int mod_cmp_mavl(const void *e1, const void *e2){
|
||||||
const struct cw_Mod * m1 = e1->ptr;
|
const struct cw_Mod * m1 = *((const struct cw_Mod**)e1);
|
||||||
const struct cw_Mod * m2 = e2->ptr;
|
const struct cw_Mod * m2 = *((const struct cw_Mod**)e2);
|
||||||
return strcmp(m1->name,m2->name);
|
return strcmp(m1->name,m2->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ struct cw_Mod * cw_mod_load(const char * mod_name){
|
|||||||
|
|
||||||
/* if modlist is not initialized, initialize ... */
|
/* if modlist is not initialized, initialize ... */
|
||||||
if (mods_loaded==NULL){
|
if (mods_loaded==NULL){
|
||||||
mods_loaded=mavl_create(mod_cmp_mavl,NULL);
|
mods_loaded=mavl_create(mod_cmp_mavl,NULL,1312);
|
||||||
if (mods_loaded==NULL){
|
if (mods_loaded==NULL){
|
||||||
cw_log(LOG_ERROR, "Can't init modlist, no memory");
|
cw_log(LOG_ERROR, "Can't init modlist, no memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -102,6 +102,8 @@ struct cw_Mod * cw_mod_detect(struct conn *conn,
|
|||||||
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
||||||
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod);
|
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod);
|
||||||
|
|
||||||
|
void cw_mod_set_mod_path(const char * path);
|
||||||
|
|
||||||
#define CW_MOD_MAX_MOD_NAME_LEN 128
|
#define CW_MOD_MAX_MOD_NAME_LEN 128
|
||||||
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"
|
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
|
||||||
struct cw_MsgSet {
|
struct cw_MsgSet {
|
||||||
mavl_t messages;
|
mavl_t msgdata;
|
||||||
mavl_t handlers_by_id;
|
mavl_t handlers_by_id;
|
||||||
mavl_t handlers_by_key;
|
mavl_t handlers_by_key;
|
||||||
|
|
@ -6,11 +6,11 @@
|
|||||||
#include "dbg.h"
|
#include "dbg.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include "message_set.h"
|
#include "msget.h"
|
||||||
|
|
||||||
static int cmp_cw_elemhandler_by_id(const mavldata_t * elem1, const mavldata_t *elem2){
|
static int cmp_cw_elemhandler_by_id(const void * elem1, const void *elem2){
|
||||||
struct cw_ElemHandler * e1 = elem1->ptr;
|
const struct cw_ElemHandler * e1 = elem1;
|
||||||
struct cw_ElemHandler * e2 = elem2->ptr;
|
const struct cw_ElemHandler * e2 = elem2;
|
||||||
int r;
|
int r;
|
||||||
r = e1->id - e2->id;
|
r = e1->id - e2->id;
|
||||||
if (r!=0)
|
if (r!=0)
|
||||||
@ -24,23 +24,23 @@ static int cmp_cw_elemhandler_by_id(const mavldata_t * elem1, const mavldata_t *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmp_cw_elemhandler_by_key(const mavldata_t *elem1, const mavldata_t *elem2){
|
static int cmp_cw_elemhandler_by_key(const void *elem1, const void *elem2){
|
||||||
struct cw_ElemHandler * e1 = elem1->ptr;
|
const struct cw_ElemHandler * e1 = elem1;
|
||||||
struct cw_ElemHandler * e2 = elem2->ptr;
|
const struct cw_ElemHandler * e2 = elem2;
|
||||||
return strcmp(e1->key,e2->key);
|
return strcmp(e1->key,e2->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmp_msgdata(const mavldata_t * elem1, const mavldata_t *elem2)
|
static int cmp_msgdata(const void * elem1, const void *elem2)
|
||||||
{
|
{
|
||||||
struct cw_MsgData * e1 = elem1->ptr;
|
const struct cw_MsgData * e1 = elem1;
|
||||||
struct cw_MsgData * e2 = elem2->ptr;
|
const struct cw_MsgData * e2 = elem2;
|
||||||
return e1->type - e2->type;
|
return e1->type - e2->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmp_elemdata(const mavldata_t * elem1, const mavldata_t *elem2)
|
static int cmp_elemdata(const void * elem1, const void *elem2)
|
||||||
{
|
{
|
||||||
struct cw_ElemData * e1 = elem1->ptr;
|
const struct cw_ElemData * e1 = elem1;
|
||||||
struct cw_ElemData * e2 = elem2->ptr;
|
const struct cw_ElemData * e2 = elem2;
|
||||||
int r;
|
int r;
|
||||||
r = e1->id - e2->id;
|
r = e1->id - e2->id;
|
||||||
if (r!=0)
|
if (r!=0)
|
||||||
@ -66,26 +66,9 @@ static void msgdata_destroy(struct cw_MsgData *data){
|
|||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cw_MsgData * msgdata_create(int type){
|
|
||||||
struct cw_MsgData * msg;
|
|
||||||
|
|
||||||
msg = malloc( sizeof(struct cw_MsgData));
|
static void del_mavl_msdgdata( void * d ){
|
||||||
if (!msg)
|
msgdata_destroy(d);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
msg->elements_tree = mavl_create(cmp_elemdata,mavl_free_bin);
|
|
||||||
if (!msg->elements_tree){
|
|
||||||
msgdata_destroy(msg);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg->type=type;
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void del_mavl_msdgdata( mavldata_t * d ){
|
|
||||||
msgdata_destroy(d->ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,8 +77,8 @@ static void del_mavl_msdgdata( mavldata_t * d ){
|
|||||||
* @param set Message set to destroy
|
* @param set Message set to destroy
|
||||||
*/
|
*/
|
||||||
void cw_msgset_destroy(struct cw_MsgSet * set){
|
void cw_msgset_destroy(struct cw_MsgSet * set){
|
||||||
if (set->messages)
|
if (set->msgdata)
|
||||||
mavl_destroy(set->messages);
|
mavl_destroy(set->msgdata);
|
||||||
if (set->handlers_by_id)
|
if (set->handlers_by_id)
|
||||||
mavl_destroy(set->handlers_by_id);
|
mavl_destroy(set->handlers_by_id);
|
||||||
if (set->handlers_by_key)
|
if (set->handlers_by_key)
|
||||||
@ -118,22 +101,25 @@ struct cw_MsgSet * cw_msgset_create(){
|
|||||||
memset(set,0,sizeof(struct cw_MsgSet));
|
memset(set,0,sizeof(struct cw_MsgSet));
|
||||||
|
|
||||||
/* create mavl for all_elems by id */
|
/* create mavl for all_elems by id */
|
||||||
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id,mavl_free_bin);
|
set->handlers_by_id = mavl_create(cmp_cw_elemhandler_by_id,NULL,
|
||||||
|
sizeof(struct cw_ElemHandler));
|
||||||
if (set->handlers_by_id==NULL){
|
if (set->handlers_by_id==NULL){
|
||||||
cw_msgset_destroy(set);
|
cw_msgset_destroy(set);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create mavl for all_elems by id */
|
/* create mavl for all_elems by key */
|
||||||
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL);
|
set->handlers_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL,
|
||||||
|
sizeof(struct cw_ElemHandler));
|
||||||
if (set->handlers_by_key==NULL){
|
if (set->handlers_by_key==NULL){
|
||||||
cw_msgset_destroy(set);
|
cw_msgset_destroy(set);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create mavl for messages */
|
/* create mavl for messages */
|
||||||
set->messages = mavl_create(cmp_msgdata,del_mavl_msdgdata);
|
set->msgdata = mavl_create(cmp_msgdata,del_mavl_msdgdata,
|
||||||
if (set->messages==NULL){
|
sizeof(struct cw_MsgData));
|
||||||
|
if (set->msgdata==NULL){
|
||||||
cw_msgset_destroy(set);
|
cw_msgset_destroy(set);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -148,7 +134,7 @@ struct cw_ElemHandler * cw_msgset_get_elemhandler(struct cw_MsgSet * set,
|
|||||||
search.proto=proto;
|
search.proto=proto;
|
||||||
search.vendor=vendor;
|
search.vendor=vendor;
|
||||||
search.id=id;
|
search.id=id;
|
||||||
return mavl_find_ptr(set->handlers_by_id,&search);
|
return mavl_find(set->handlers_by_id,&search);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -156,11 +142,12 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
|
|||||||
struct cw_MsgDef * msgdef)
|
struct cw_MsgDef * msgdef)
|
||||||
{
|
{
|
||||||
struct cw_ElemDef * elemdef;
|
struct cw_ElemDef * elemdef;
|
||||||
mavldata_t mavldata, *result;
|
struct cw_ElemData ed, *result;
|
||||||
|
|
||||||
/* iterate through all defined elements */
|
/* iterate through all defined elements */
|
||||||
for(elemdef = msgdef->elements; elemdef->id; elemdef++){
|
for(elemdef = msgdef->elements; elemdef->id; elemdef++){
|
||||||
struct cw_ElemHandler * handler;
|
struct cw_ElemHandler * handler;
|
||||||
|
int replaced;
|
||||||
|
|
||||||
handler = cw_msgset_get_elemhandler(set,
|
handler = cw_msgset_get_elemhandler(set,
|
||||||
elemdef->proto,
|
elemdef->proto,
|
||||||
@ -175,18 +162,15 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mavldata.ptr = malloc(sizeof(struct cw_ElemData));
|
ed.id=elemdef->id;
|
||||||
if (!mavldata.ptr){
|
ed.proto=elemdef->proto;
|
||||||
cw_log(LOG_ERR,"Can't create ElemData element: %s",strerror(errno));
|
ed.vendor=elemdef->vendor;
|
||||||
}
|
ed.mand=elemdef->mand;
|
||||||
((struct cw_ElemData *)(mavldata.ptr))->id=elemdef->id;
|
|
||||||
((struct cw_ElemData *)(mavldata.ptr))->proto=elemdef->proto;
|
|
||||||
((struct cw_ElemData *)(mavldata.ptr))->vendor=elemdef->vendor;
|
|
||||||
((struct cw_ElemData *)(mavldata.ptr))->mand=elemdef->mand;
|
|
||||||
|
|
||||||
result = mavl_replace(msgdata->elements_tree, &mavldata);
|
|
||||||
|
|
||||||
if (result != &mavldata){
|
result = mavl_replace(msgdata->elements_tree, &ed, &replaced);
|
||||||
|
|
||||||
|
if (!replaced){
|
||||||
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
|
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
|
||||||
elemdef->proto,
|
elemdef->proto,
|
||||||
elemdef->vendor,
|
elemdef->vendor,
|
||||||
@ -194,7 +178,7 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
|
|||||||
handler->name);
|
handler->name);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
cw_dbg(DBG_MOD, " replaceing message element %d %d %d - %s",
|
cw_dbg(DBG_MOD, " replacing message element %d %d %d - %s",
|
||||||
elemdef->proto,
|
elemdef->proto,
|
||||||
elemdef->vendor,
|
elemdef->vendor,
|
||||||
elemdef->id,
|
elemdef->id,
|
||||||
@ -217,46 +201,34 @@ int cw_msgset_add(struct cw_MsgSet * set,
|
|||||||
|
|
||||||
/* Create mavl for all handlers */
|
/* Create mavl for all handlers */
|
||||||
for(handler = handlers; handler->id; handler++){
|
for(handler = handlers; handler->id; handler++){
|
||||||
mavldata_t copy;
|
|
||||||
copy.ptr = malloc(sizeof(struct cw_ElemHandler));
|
|
||||||
if (!copy.ptr){
|
|
||||||
cw_log(LOG_ERR,"Can't alloc mem:", strerror(errno));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cw_dbg(DBG_MOD,"Adding handler for element %d - %s - with key: %s",
|
cw_dbg(DBG_MOD,"Adding handler for element %d - %s - with key: %s",
|
||||||
handler->id,
|
handler->id,
|
||||||
handler->name,
|
handler->name,
|
||||||
handler->key);
|
handler->key);
|
||||||
|
mavl_replace(set->handlers_by_id,handler,NULL);
|
||||||
|
mavl_replace(set->handlers_by_key,handler,NULL);
|
||||||
memcpy(copy.ptr,handler,sizeof(struct cw_ElemHandler));
|
|
||||||
|
|
||||||
mavl_replace(set->handlers_by_id,©);
|
|
||||||
mavl_replace(set->handlers_by_key,©);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (msgdef=messages; msgdef->type !=0; msgdef++){
|
for (msgdef=messages; msgdef->type !=0; msgdef++){
|
||||||
struct cw_MsgData search, *msg;
|
struct cw_MsgData search;
|
||||||
|
struct cw_MsgData *msg;
|
||||||
|
int exists;
|
||||||
|
|
||||||
/* Look if message already exists */
|
/* Look if message already exists */
|
||||||
search.type=msgdef->type;
|
search.type=msgdef->type;
|
||||||
msg = mavl_find_ptr(set->messages,&search);
|
msg = mavl_add(set->msgdata,&search,&exists);
|
||||||
|
|
||||||
if (!msg){
|
if (msg == NULL){
|
||||||
msg = msgdata_create(msgdef->type);
|
|
||||||
|
|
||||||
if (!msg){
|
|
||||||
cw_log(LOG_ERR,"Can't create messae");
|
cw_log(LOG_ERR,"Can't create messae");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mavl_add_ptr(set->messages,msg);
|
if (!exists){
|
||||||
|
msg->elements_tree = mavl_create(cmp_elemdata,NULL,
|
||||||
|
sizeof(struct cw_ElemData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Overwrite the found message */
|
/* Overwrite the found message */
|
||||||
if (msgdef->name)
|
if (msgdef->name)
|
||||||
msg->name=msgdef->name;
|
msg->name=msgdef->name;
|
||||||
@ -283,5 +255,5 @@ int cw_msgset_add(struct cw_MsgSet * set,
|
|||||||
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type){
|
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type){
|
||||||
struct cw_MsgData search;
|
struct cw_MsgData search;
|
||||||
search.type=type;
|
search.type=type;
|
||||||
return mavl_find_ptr(set->messages,&search);
|
return mavl_find_ptr(set->msgdata,&search);
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ static void del(void* d)
|
|||||||
|
|
||||||
struct avltree * stravltree_create()
|
struct avltree * stravltree_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cmp,del);
|
return mavl_create(cmp,del,100);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * stravltree_add(struct avltree * t, const char * str)
|
const char * stravltree_add(struct avltree * t, const char * str)
|
||||||
@ -26,5 +26,5 @@ const char * stravltree_add(struct avltree * t, const char * str)
|
|||||||
char * s = strdup(str);
|
char * s = strdup(str);
|
||||||
if (!s)
|
if (!s)
|
||||||
return 0;
|
return 0;
|
||||||
return mavl_add(t,s);
|
return mavl_add(t,s,NULL);
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,13 @@ static void del(void* d)
|
|||||||
|
|
||||||
cw_strheap_t cw_strheap_create()
|
cw_strheap_t cw_strheap_create()
|
||||||
{
|
{
|
||||||
return mavl_create(cmp,del);
|
return mavl_create(cmp,del,1312);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * cw_strheap_add(cw_strheap_t t, struct cw_strlist_elem *s)
|
const char * cw_strheap_add(cw_strheap_t t, struct cw_strlist_elem *s)
|
||||||
{
|
{
|
||||||
mavl_del(t,s);
|
mavl_del(t,s);
|
||||||
return mavl_add(t,s);
|
return mavl_add(t,s,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cw_strheap_register_strings(cw_strheap_t h, struct cw_strlist_elem *s)
|
int cw_strheap_register_strings(cw_strheap_t h, struct cw_strlist_elem *s)
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "cw/cw.h"
|
#include "cw/cw.h"
|
||||||
#include "cw/cw_types.h"
|
#include "cw/kvt.h"
|
||||||
#include "cw/log.h"
|
#include "cw/log.h"
|
||||||
|
|
||||||
#include "cw/message_set.h"
|
#include "cw/msget.h"
|
||||||
|
|
||||||
#include "mod_capwap.h"
|
#include "mod_capwap.h"
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#include "cw/dbg.h"
|
#include "cw/dbg.h"
|
||||||
#include "cw/cw.h"
|
#include "cw/cw.h"
|
||||||
|
|
||||||
#include "cw/kvstore.h"
|
#include "cw/kvt.h"
|
||||||
#include "cw/cw_types.h"
|
|
||||||
#include "cw/keys.h"
|
#include "cw/keys.h"
|
||||||
|
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ static void readsubelems_wtp_board_data(mavl_t cfg, uint8_t * msgelem,
|
|||||||
if (key){
|
if (key){
|
||||||
char add_key[256];
|
char add_key[256];
|
||||||
sprintf(add_key,"wtp_board_data/%s",key);
|
sprintf(add_key,"wtp_board_data/%s",key);
|
||||||
cw_kvstore_add(cfg,add_key,CW_TYPE_BSTR16,msgelem+i,sublen);
|
cw_kvt_add(cfg,add_key,CW_TYPE_BSTR16,msgelem+i,sublen);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ int capwap_in_wtp_board_data(struct cw_ElemHandler *eh, struct cw_ElemHandlerPar
|
|||||||
|
|
||||||
sprintf(vendor_key,"%s/%s",eh->key,CW_KEY_VENDOR);
|
sprintf(vendor_key,"%s/%s",eh->key,CW_KEY_VENDOR);
|
||||||
|
|
||||||
cw_kvstore_add(cfg,vendor_key,CW_TYPE_DWORD,data,len);
|
cw_kvt_add(cfg,vendor_key,CW_TYPE_DWORD,data,len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mbag_t itemstore = conn->incomming;
|
mbag_t itemstore = conn->incomming;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
struct cw_Mod *mod_capwap_ac();
|
struct cw_Mod *mod_capwap_ac();
|
||||||
struct cw_Mod *mod_capwap_wtp();
|
struct cw_Mod *mod_capwap_wtp();
|
||||||
|
|
||||||
#include "cw/message_set.h"
|
#include "cw/msget.h"
|
||||||
#include "cw/conn.h"
|
#include "cw/conn.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
|
|
||||||
#include "include/cipwap_items.h"
|
#include "include/cipwap_items.h"
|
||||||
|
|
||||||
#include "cw/message_set.h"
|
#include "cw/msget.h"
|
||||||
#include "cw/cw_types.h"
|
#include "cw/kvt.h"
|
||||||
|
|
||||||
|
|
||||||
static struct cw_ElemHandler handlers[] = {
|
static struct cw_ElemHandler handlers[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user