Compare commits
5 Commits
1616d77a0f
...
156466eab9
Author | SHA1 | Date | |
---|---|---|---|
156466eab9 | |||
04d469b970 | |||
0e07e42167 | |||
4c37d89f03 | |||
6d9da94863 |
@ -48,7 +48,8 @@
|
|||||||
|
|
||||||
#include "cw/cfg.h"
|
#include "cw/cfg.h"
|
||||||
|
|
||||||
int ac_run();
|
int ac_run(cw_Cfg_t * cfg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@ -64,7 +65,7 @@ static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
|
|||||||
int c;
|
int c;
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
|
|
||||||
bootcfg->cfgfilename = "config.atv";
|
bootcfg->cfgfilename = "config.ckv";
|
||||||
|
|
||||||
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
|
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
|
||||||
|
|
||||||
@ -175,7 +176,7 @@ int main (int argc, char *argv[])
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct bootcfg bootcfg;
|
struct bootcfg bootcfg;
|
||||||
FILE * file;
|
FILE * file;
|
||||||
mavl_t types_tree, acglobal_cfg;
|
mavl_t types_tree;
|
||||||
const cw_Type_t **ti;
|
const cw_Type_t **ti;
|
||||||
|
|
||||||
|
|
||||||
@ -193,13 +194,11 @@ int main (int argc, char *argv[])
|
|||||||
rc = cw_cfg_load(bootcfg.cfgfilename,global_cfg);
|
rc = cw_cfg_load(bootcfg.cfgfilename,global_cfg);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
if (rc<0)
|
if (rc)
|
||||||
fprintf(stderr,"Can't load cfg '%s': %s\n",bootcfg.cfgfilename,strerror(errno));
|
fprintf(stderr,"Can't load cfg '%s': %s\n",bootcfg.cfgfilename,strerror(errno));
|
||||||
goto errX;
|
goto errX;
|
||||||
};
|
};
|
||||||
|
|
||||||
actube_global_cfg = acglobal_cfg;
|
|
||||||
|
|
||||||
|
|
||||||
cw_log_name = "AC-Tube";
|
cw_log_name = "AC-Tube";
|
||||||
|
|
||||||
@ -219,9 +218,13 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
if (!dataman_list_init())
|
if (!dataman_list_init())
|
||||||
goto errX;
|
goto errX;
|
||||||
|
|
||||||
|
ac_conf_init(global_cfg);
|
||||||
|
|
||||||
|
cw_cfg_dump(global_cfg);
|
||||||
|
|
||||||
cw_log (LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
|
cw_log (LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
|
||||||
rc = ac_run();
|
rc = ac_run(global_cfg);
|
||||||
|
|
||||||
errX:
|
errX:
|
||||||
if (global_cfg)
|
if (global_cfg)
|
||||||
@ -243,15 +246,18 @@ void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, in
|
|||||||
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
|
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
|
||||||
|
|
||||||
|
|
||||||
int ac_run()
|
int ac_run(cw_Cfg_t * cfg)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!conf_listen_addrs_len) {
|
if (1 /*!conf_listen_addrs_len*/) {
|
||||||
cw_log (LOG_ERR, "Fatal error: No listen addresses found.");
|
cw_log (LOG_ERR, "Fatal error: No listen addresses found.");
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void cw_cfg_iterate(cw_Cfg_t *);
|
||||||
|
cw_cfg_iterate(cfg);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
/* it is important to create the unicast sockets first,
|
/* it is important to create the unicast sockets first,
|
||||||
* because when we create the mcast an bcast sockets next
|
* because when we create the mcast an bcast sockets next
|
||||||
@ -260,7 +266,7 @@ int ac_run()
|
|||||||
|
|
||||||
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];
|
||||||
int proto;
|
int proto;
|
||||||
@ -269,7 +275,8 @@ int ac_run()
|
|||||||
|
|
||||||
socklist_add_unicast (addr, port, proto);
|
socklist_add_unicast (addr, port, proto);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (socklist_len == 0) {
|
if (socklist_len == 0) {
|
||||||
cw_log (LOG_ERR, "Fatal error: Could not setup any listen socket");
|
cw_log (LOG_ERR, "Fatal error: Could not setup any listen socket");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "ac.h"
|
#include "ac.h"
|
||||||
|
#include "cw/cfg.h"
|
||||||
|
|
||||||
#include "cw/mavltypes.h"
|
#include "cw/mavltypes.h"
|
||||||
|
|
||||||
@ -60,8 +61,6 @@ long conf_max_wtps = CONF_DEFAULT_MAXWTPS;
|
|||||||
char *conf_logfilename = CONF_DEFAULT_LOGFILENAME;
|
char *conf_logfilename = CONF_DEFAULT_LOGFILENAME;
|
||||||
struct sockaddr_storage *conf_salist = NULL;
|
struct sockaddr_storage *conf_salist = NULL;
|
||||||
|
|
||||||
char **conf_listen_addrs;
|
|
||||||
int conf_listen_addrs_len = 0;
|
|
||||||
|
|
||||||
|
|
||||||
char **conf_mcast_groups = 0;
|
char **conf_mcast_groups = 0;
|
||||||
@ -215,41 +214,23 @@ static int init_control_port()
|
|||||||
|
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
static int init_listen_addrs()
|
static int init_listen_addrs(cw_Cfg_t * cfg)
|
||||||
{
|
{
|
||||||
|
char key[CW_CFG_MAX_KEY_LEN];
|
||||||
|
|
||||||
struct ifaddrs *ifap, *ifa;
|
struct ifaddrs *ifap, *ifa;
|
||||||
int rc;
|
int rc;
|
||||||
int ctr;
|
int ctr;
|
||||||
|
const char * a0;
|
||||||
|
|
||||||
if (conf_listen_addrs != 0)
|
a0 = cw_cfg_get(cfg,"actube/listen.0",NULL);
|
||||||
|
if (a0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rc = getifaddrs(&ifap);
|
rc = getifaddrs(&ifap);
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* count the addresses */
|
|
||||||
ctr = 0;
|
|
||||||
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
|
|
||||||
if (!ifa->ifa_addr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET && conf_ipv4)
|
|
||||||
ctr++;
|
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6)
|
|
||||||
ctr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
conf_listen_addrs = malloc(sizeof(char *) * ctr);
|
|
||||||
if (!conf_listen_addrs) {
|
|
||||||
rc = 0;
|
|
||||||
goto errX;
|
|
||||||
}
|
|
||||||
memset(conf_listen_addrs, 0, sizeof(char *) * ctr);
|
|
||||||
|
|
||||||
|
|
||||||
ctr = 0;
|
ctr = 0;
|
||||||
/* get the addresses */
|
/* get the addresses */
|
||||||
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
|
for (ifa = ifap; ifa != 0; ifa = ifa->ifa_next) {
|
||||||
@ -267,12 +248,9 @@ 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);
|
||||||
|
|
||||||
conf_listen_addrs[ctr] =
|
|
||||||
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
|
|
||||||
(uint8_t *) str, strlen(str));
|
|
||||||
if (conf_listen_addrs[ctr])
|
|
||||||
ctr++;
|
|
||||||
|
|
||||||
|
sprintf(key,"actube/listen.%d",ctr++);
|
||||||
|
cw_cfg_set(cfg,key,str);
|
||||||
}
|
}
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6) {
|
if (ifa->ifa_addr->sa_family == AF_INET6 && conf_ipv6) {
|
||||||
sock_addrtostr(ifa->ifa_addr, str, 100,0);
|
sock_addrtostr(ifa->ifa_addr, str, 100,0);
|
||||||
@ -281,14 +259,10 @@ static int init_listen_addrs()
|
|||||||
strcat(str, "%");
|
strcat(str, "%");
|
||||||
strcat(str, ifa->ifa_name);
|
strcat(str, ifa->ifa_name);
|
||||||
}
|
}
|
||||||
conf_listen_addrs[ctr] =
|
sprintf(key,"actube/listen.%d",ctr++);
|
||||||
(char *) cw_setstr((uint8_t **) & conf_listen_addrs[ctr],
|
cw_cfg_set(cfg,key,str);
|
||||||
(uint8_t *) str, strlen(str));
|
|
||||||
if (conf_listen_addrs[ctr])
|
|
||||||
ctr++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conf_listen_addrs_len = ctr;
|
|
||||||
rc = 1;
|
rc = 1;
|
||||||
errX:
|
errX:
|
||||||
freeifaddrs(ifap);
|
freeifaddrs(ifap);
|
||||||
@ -703,9 +677,6 @@ int read_config(const char *filename)
|
|||||||
/* read debug options */
|
/* read debug options */
|
||||||
conf_read_dbg_level(cfg);
|
conf_read_dbg_level(cfg);
|
||||||
|
|
||||||
/* read the listen addresses */
|
|
||||||
conf_read_strings(cfg, "listen", &conf_listen_addrs, &conf_listen_addrs_len);
|
|
||||||
|
|
||||||
/* read multi cast groups */
|
/* read multi cast groups */
|
||||||
conf_read_strings(cfg, "mcast_groups", &conf_mcast_groups,
|
conf_read_strings(cfg, "mcast_groups", &conf_mcast_groups,
|
||||||
&conf_mcast_groups_len);
|
&conf_mcast_groups_len);
|
||||||
@ -763,7 +734,6 @@ int read_config(const char *filename)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
init_listen_addrs();
|
|
||||||
init_mcast_groups();
|
init_mcast_groups();
|
||||||
init_bcast_addrs();
|
init_bcast_addrs();
|
||||||
|
|
||||||
@ -775,3 +745,13 @@ void free_config()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ac_conf_init(cw_Cfg_t *cfg)
|
||||||
|
{
|
||||||
|
printf("ac conf\n");
|
||||||
|
init_listen_addrs(cfg);
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include "cw/bstr.h"
|
#include "cw/bstr.h"
|
||||||
#include "cw/mod.h"
|
#include "cw/mod.h"
|
||||||
#include "cw/vendors.h"
|
#include "cw/vendors.h"
|
||||||
|
#include "cw/cfg.h"
|
||||||
|
|
||||||
extern struct cw_Mod ** conf_mods;
|
extern struct cw_Mod ** conf_mods;
|
||||||
|
|
||||||
@ -94,8 +94,6 @@ extern bstr_t conf_cisco_software_version;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern char **conf_listen_addrs;
|
|
||||||
extern int conf_listen_addrs_len;
|
|
||||||
|
|
||||||
extern struct sockaddr *conf_ac_ips;
|
extern struct sockaddr *conf_ac_ips;
|
||||||
extern int conf_ac_ips_len;
|
extern int conf_ac_ips_len;
|
||||||
@ -141,5 +139,8 @@ extern int conf_parse_listen_addr(const char *addr, char *saddr, char *port, int
|
|||||||
|
|
||||||
#define CFG_ENTRY_MODS "mods"
|
#define CFG_ENTRY_MODS "mods"
|
||||||
|
|
||||||
|
#define CONF_PREFIX "actube"
|
||||||
|
|
||||||
|
void ac_conf_init(cw_Cfg_t *cfg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "cw/mod.h"
|
||||||
|
|
||||||
|
|
||||||
struct cw_DiscoveryCache * discovery_cache_create(int len);
|
struct cw_DiscoveryCache * discovery_cache_create(int len);
|
||||||
@ -14,4 +14,5 @@ void discovery_cache_add(struct cw_DiscoveryCache *cache,
|
|||||||
int discovery_cache_get(struct cw_DiscoveryCache * cache,struct sockaddr *addr,
|
int discovery_cache_get(struct cw_DiscoveryCache * cache,struct sockaddr *addr,
|
||||||
struct cw_Mod ** modcapwap, struct cw_Mod **modbindings);
|
struct cw_Mod ** modcapwap, struct cw_Mod **modbindings);
|
||||||
|
|
||||||
#endif
|
void discovery_cache_destroy(struct cw_DiscoveryCache * c);
|
||||||
|
#endif
|
||||||
|
87
src/cw/cfg.c
87
src/cw/cfg.c
@ -52,13 +52,13 @@ int cw_cfg_set(cw_Cfg_t * cfg,const char *key, const char *val)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * cw_cfg_get(cw_Cfg_t * cfg, char *key)
|
const char * cw_cfg_get(cw_Cfg_t * cfg, char *key, const char *def)
|
||||||
{
|
{
|
||||||
struct cw_Cfg_entry e,*r;
|
struct cw_Cfg_entry e,*r;
|
||||||
e.key = key;
|
e.key = key;
|
||||||
r = mavl_get(cfg,&e);
|
r = mavl_get(cfg,&e);
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return def;
|
||||||
return r->val;
|
return r->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,5 +368,86 @@ int cw_cfg_load(const char *filename,cw_Cfg_t * cfg)
|
|||||||
return errno;
|
return errno;
|
||||||
errs = cw_cfg_read_from_file(f,cfg);
|
errs = cw_cfg_read_from_file(f,cfg);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return errs;
|
|
||||||
|
if (errs)
|
||||||
|
errno = EINVAL;
|
||||||
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int cw_cfg_get_next_idx(cw_Cfg_t * cfg, const char *key, int n)
|
||||||
|
{
|
||||||
|
char ikey[CW_CFG_MAX_KEY_LEN];
|
||||||
|
struct cw_Cfg_entry search, * result;
|
||||||
|
char *d;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
sprintf(ikey,"%s.%d",key,n);
|
||||||
|
|
||||||
|
search.key=ikey;
|
||||||
|
result = mavl_get_first(cfg,&search);
|
||||||
|
|
||||||
|
printf("KEY: %s\n",search.key);
|
||||||
|
printf("NNNNN: %s\n",result->key);
|
||||||
|
|
||||||
|
|
||||||
|
if (result==NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
d=NULL;
|
||||||
|
for (i = strlen(ikey); i>=0; i--){
|
||||||
|
|
||||||
|
if (ikey[i]=='.'){
|
||||||
|
d = result->key+i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d==NULL){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result->key[i]!='.'){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(result->key,ikey,i)!=0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
printf("TRANSFER %s\n",result->key+i+1);
|
||||||
|
return atoi(result->key+i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cw_cfg_iterate(cw_Cfg_t * cfg)
|
||||||
|
{
|
||||||
|
printf("Iterate\n");
|
||||||
|
struct cw_Cfg_entry *e;
|
||||||
|
struct cw_Cfg_entry search;
|
||||||
|
search.key="actube/listen";
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
i = cw_cfg_get_next_idx(cfg,"actube/listen",i);
|
||||||
|
|
||||||
|
printf("This i %d\n",i);
|
||||||
|
|
||||||
|
while ( (i = cw_cfg_get_next_idx(cfg,"actube/listen",i))!=-1) {
|
||||||
|
|
||||||
|
printf("Here i %d\n",i);
|
||||||
|
printf("we have key: %s.%d\n","actube/listen",i);
|
||||||
|
printf("Next=%d\n",i);
|
||||||
|
i++;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
e = mavl_get_first(cfg,&search);
|
||||||
|
if (!e){
|
||||||
|
printf("NULL\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("%s : %s\n",e->key,e->val);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ struct cw_Cfg_entry{
|
|||||||
char *val;
|
char *val;
|
||||||
};
|
};
|
||||||
|
|
||||||
char * cw_cfg_get(cw_Cfg_t * cfg, char *key);
|
const char * cw_cfg_get(cw_Cfg_t * cfg, char *key, const char *def);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user