// Init BSP-core int core_init() { if (!core_settings.initialized) { init_core_setting(); } if (core_settings.is_daemonize) { proc_daemonize(); } fd_init(0); log_init(); load_runtime_setting(); status_op_core(STATUS_OP_INSTANCE_ID, (size_t) core_settings.instance_id); thread_init(); save_pid(); signal_init(); socket_init(); memdb_init(); online_init(); // Load modules BSP_VALUE *val = object_get_hash_str(runtime_settings, "modules"); BSP_OBJECT *vobj = value_get_object(val); BSP_STRING *vstr = NULL; if (vobj && OBJECT_TYPE_ARRAY == vobj->type) { size_t varr_size = object_size(vobj), i; if (varr_size > MAX_MODULES) { varr_size = MAX_MODULES; } reset_object(vobj); for (i = 0; i < varr_size; i ++) { val = object_get_array(vobj, i); vstr = value_get_string(val); if (vstr) { script_load_module(vstr, 1); } } } return BSP_RTN_SUCCESS; }
void db_initialize() { GMSTATUS status = STATUS_SUCCESS; if (kSupportsTierGamesman && gTierGamesman) { tierdb_init(db_functions); } else if (gBitPerfectDB) { if (gSymmetries) status = symdb_init(db_functions); else status = bpdb_init(db_functions); if(!GMSUCCESS(status)) { BPDB_TRACE("db_initialize()", "Attempt to initialize the bpdb by calling bpdb_init failed", status); goto _bailout; } } else if(gTwoBits) { twobitdb_init(db_functions); } else if(gCollDB) { colldb_init(db_functions); } #ifdef HAVE_GMP else if(gUnivDB) { db_functions = univdb_init(); } #endif else if(gNetworkDB) { netdb_init(db_functions); } else if(gFileDB) { filedb_init(db_functions); } else { memdb_init(db_functions); } //printf("\nCalling hooking function\n"); //db_analysis_hook(); _bailout: return; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+32+1+256)]; char json_buffer[4096]; char print_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; pthread_t cube_thread; char * baseconfig[] = { "typelist.json", "subtypelist.json", "msghead.json", "login_struct.json", "headrecord.json", NULL }; alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0; baseconfig[i]!=NULL; i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start msgfunc_init(); void * message; void * policy; dispatch_init(NULL); policy=dispatch_policy_create(); if(policy==NULL) { printf("create policy failed!\n"); return -EINVAL; } ret=read_dispatch_file("dispatch_policy.json"); // routine_start(); // sleep(100000); return 0; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; char json_buffer[4096]; char print_buffer[4096]; BYTE bin_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; char * baseconfig[] = { "namelist.json", "typelist.json", "subtypelist.json", "msghead.json", "base_msg.json", "expandrecord.json", NULL }; // alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start int msg_type = memdb_get_typeno("MESSAGE"); if(msg_type<=0) return -EINVAL; int subtype=memdb_get_subtypeno(msg_type,"HEAD"); if(subtype<=0) return -EINVAL; record=memdb_get_first(msg_type,subtype); while(record!=NULL) { ret=memdb_print(record,print_buffer); if(ret<0) return -EINVAL; printf("%s\n",print_buffer); record=memdb_get_next(msg_type,subtype); } msgfunc_init(); void * message; struct basic_message base_msg; struct expand_flow_trace flow_trace; message=message_create(DTYPE_MESSAGE,SUBTYPE_BASE_MSG,NULL); base_msg.message=dup_str("Hello,World!",0); flow_trace.record_num=1; flow_trace.trace_record=Talloc0(DIGEST_SIZE*flow_trace.record_num); Strncpy(flow_trace.trace_record,"test_port",DIGEST_SIZE/4*3); ret=message_add_record(message,&base_msg); if(ret<0) { printf("add message record failed!\n"); return ret; } ret=message_add_expand_data(message,DTYPE_MSG_EXPAND,SUBTYPE_FLOW_TRACE,&flow_trace); if(ret<0) { printf("add message expand failed!\n"); return ret; } ret=message_record_struct2blob(message); if(ret<0) { printf("message struct2blob failed!\n"); return ret; } BYTE * blob; ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); ret=message_output_blob(message,&blob); if(ret<0) return ret; printf ("output %d data to bin_buffer\n",ret); void * new_msg; ret=message_read_from_blob(&new_msg,blob,ret); printf ("read %d from bin_buffer\n",ret); ret=message_load_record(new_msg); if(ret<0) { printf("load record failed!\n"); return ret; } ret=message_load_expand(new_msg); if(ret<0) { printf("load expand failed!\n"); return ret; } printf("%s\n",json_buffer); ret=json_2_message(json_buffer,&new_msg); if(ret<0) return ret; printf ("read %d from json_buffer\n",ret); ret=message_output_json(new_msg,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); ret=message_output_blob(message,bin_buffer); return 0; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+32+1+256)]; char json_buffer[4096]; char print_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; pthread_t cube_thread; char * baseconfig[] = { "namelist.json", "dispatchnamelist.json", "typelist.json", "subtypelist.json", "msghead.json", "msgrecord.json", "expandrecord.json", "base_msg.json", "dispatchrecord.json", NULL }; // alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start msgfunc_init(); dispatch_init(); void * message; void * policy; ret=read_dispatch_file("dispatch_policy.json"); message=message_create(DTYPE_MESSAGE,SUBTYPE_BASE_MSG,NULL); struct basic_message * base_msg; base_msg=Talloc0(sizeof(*base_msg)); if(base_msg==NULL) return -ENOMEM; base_msg->message=dup_str("hello",0); message_add_record(message,base_msg); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); ret=dispatch_policy_getfirst(&policy); while(policy!=NULL) { ret=dispatch_match_message(policy,message); if(ret==0) { printf("this message match the policy!\n"); break; } ret=dispatch_policy_getnext(&policy); } if(policy!=NULL) { router_set_local_route(message,policy); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); } // routine_start(); // sleep(100000); return 0; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; char json_buffer[4096]; char print_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; char * baseconfig[] = { "typelist.json", "subtypelist.json", "msghead.json", "headrecord.json", NULL }; alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start int msg_type = memdb_get_typeno("MESSAGE"); if(msg_type<=0) return -EINVAL; int subtype=memdb_get_subtypeno(msg_type,"HEAD"); if(subtype<=0) return -EINVAL; record=memdb_get_first(msg_type,subtype); while(record!=NULL) { ret=memdb_print(record,print_buffer); if(ret<0) return -EINVAL; printf("%s\n",print_buffer); record=memdb_get_next(msg_type,subtype); } msgfunc_init(); void * message; message=message_create(512,1,NULL); ret=Galloc0(&msg_head,sizeof(MSG_HEAD)); if(msg_head==NULL) return -EINVAL; Strcpy(msg_head->sender_uuid,"Test sender"); Strcpy(msg_head->receiver_uuid,"Test receiver"); ret=message_add_record(message,msg_head); if(ret<0) { printf("add message head record failed!\n"); return ret; } ret=message_record_struct2blob(message); if(ret<0) { printf("message struct2blob failed!\n"); return ret; } BYTE * blob; message_output_blob(message,&blob); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); void * new_msg; ret=json_2_message(json_buffer,&new_msg); if(ret<0) return ret; printf ("read % from json_buffer\n",ret); ret=message_output_json(message,json_buffer); if(ret<0) { printf("message output json failed!\n"); return ret; } printf("%s\n",json_buffer); return 0; }
int main(int argc,char **argv) { struct tcloud_connector_hub * hub; struct tcloud_connector * temp_conn; int ret; int retval; void * message_box; int i,j; int argv_offset; char namebuffer[DIGEST_SIZE*4]; char * sys_plugin; char * app_plugin; char * base_define; char * cube_output; char json_buffer[4096]; char print_buffer[4096]; int readlen; int json_offset; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; void * main_proc; // point to the main proc's subject struct void * conn_proc; // point to the conn proc's subject struct void * router_proc; // point to the conn proc's subject struct char local_uuid[DIGEST_SIZE*2]; FILE * fp; char audit_text[4096]; char buffer[4096]; void * root_node; void * temp_node; PROC_INIT plugin_proc; char * baseconfig[] = { "namelist.json", "dispatchnamelist.json", "typelist.json", "subtypelist.json", "baseflag.json", "memdb.json", "msghead.json", "msgrecord.json", "expandrecord.json", "base_msg.json", "dispatchrecord.json", "exmoduledefine.json", "sys_conn.json", NULL }; struct start_para start_para; start_para.argc=argc; start_para.argv=argv; int fd =open(msgaudit_file,O_CREAT|O_RDWR|O_TRUNC,0666); close(fd); audit_file_init(); sys_plugin=getenv("CUBE_SYS_PLUGIN"); // alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); base_define=getenv("CUBE_BASE_DEFINE"); for(i=0;baseconfig[i]!=NULL;i++) { Strcpy(namebuffer,base_define); Strcat(namebuffer,"/"); Strcat(namebuffer,baseconfig[i]); ret=read_json_file(namebuffer); if(ret<0) return ret; print_cubeaudit("read %d elem from file %s!\n",ret,namebuffer); } msgfunc_init(); dispatch_init(); channel_init(); ex_module_list_init(); // init system system("mkdir lib"); // init the main proc struct struct lib_para_struct * lib_para=NULL; fd=open(sys_config_file,O_RDONLY); if(fd>0) { ret=read_json_node(fd,&root_node); if(ret<0) return ret; close(fd); ret=read_sys_cfg(&lib_para,root_node,NULL); if(ret<0) return ret; } fd=open(main_config_file,O_RDONLY); if(fd<0) return -EINVAL; ret=read_json_node(fd,&root_node); if(ret<0) return ret; close(fd); ret=read_main_cfg(lib_para,root_node); if(ret<0) return ret; ret=get_local_uuid(local_uuid); digest_to_uuid(local_uuid,buffer); buffer[64]=0; print_cubeaudit("this machine's local uuid is %s\n",buffer); proc_share_data_setvalue("uuid",local_uuid); // init all the proc database usleep(time_val.tv_usec); // init the connect proc Strcpy(namebuffer,sys_plugin); Strcat(namebuffer,"/"); Strcat(namebuffer,connector_plugin_file); plugin_proc.init =main_read_func(namebuffer,"proc_conn_init"); if(plugin_proc.init==NULL) return -EINVAL; plugin_proc.start =main_read_func(namebuffer,"proc_conn_start"); if(plugin_proc.start==NULL) return -EINVAL; plugin_proc.name=dup_str("connector_proc",0); plugin_proc.type=MOD_TYPE_CONN; ret=ex_module_create("connector_proc",MOD_TYPE_CONN,NULL,&conn_proc); if(ret<0) return ret; ex_module_setinitfunc(conn_proc,plugin_proc.init); ex_module_setstartfunc(conn_proc,plugin_proc.start); ex_module_init(conn_proc,connector_config_file); add_ex_module(conn_proc); // init the router proc Strcpy(namebuffer,sys_plugin); Strcat(namebuffer,"/"); Strcat(namebuffer,router_plugin_file); plugin_proc.init =main_read_func(namebuffer,"proc_router_init"); if(plugin_proc.init==NULL) return -EINVAL; plugin_proc.start =main_read_func(namebuffer,"proc_router_start"); if(plugin_proc.start==NULL) return -EINVAL; plugin_proc.name=dup_str("router_proc",0); plugin_proc.type=MOD_TYPE_ROUTER; ret=ex_module_create("router_proc",MOD_TYPE_MONITOR,NULL,&router_proc); if(ret<0) return ret; ex_module_setinitfunc(router_proc,plugin_proc.init); ex_module_setstartfunc(router_proc,plugin_proc.start); struct router_init_para { char * router_file; char * aspect_file; } router_init; router_init.router_file=router_config_file; router_init.aspect_file=aspect_config_file; ex_module_init(router_proc,&router_init); print_cubeaudit("prepare the router proc\n"); ret=add_ex_module(router_proc); if(ret<0) return ret; // loop to init all the plugin's void * ex_module; fd=open(plugin_config_file,O_RDONLY); if(fd>0) { while(read_json_node(fd,&root_node)>0) { ret=read_plugin_cfg(&ex_module,root_node); if(ret>=0) add_ex_module(ex_module); } } /* } */ usleep(time_val.tv_usec); print_cubeaudit("prepare the conn proc\n"); ret=ex_module_start(conn_proc,NULL); if(ret<0) return ret; // second loop: start all the monitor process ret=get_first_ex_module(&ex_module); if(ret<0) return ret; int active_module_no=0; while(ex_module!=NULL) { if((ex_module_gettype(ex_module) == MOD_TYPE_MONITOR) ||(ex_module_gettype(ex_module) == MOD_TYPE_PORT)) { ret=ex_module_start(ex_module,NULL); if(ret<0) return ret; print_cubeaudit("monitor ex_modulec %s started successfully!\n",ex_module_getname(ex_module)); } else if(ex_module_gettype(ex_module) == MOD_TYPE_START) { ret=ex_module_start(ex_module,&start_para); if(ret<0) return ret; print_cubeaudit("start ex_module %s started successfully!\n",ex_module_getname(ex_module)); } ret= get_next_ex_module(&ex_module); active_module_no++; if(ret<0) return ret; } if(active_module_no==0) return 0; proc_share_data_setstate(PROC_LOCAL_START); // third loop: test if any module exit int * thread_retval; thread_retval=malloc(sizeof(int)*active_module_no); if(thread_retval==NULL) return NULL; /* i=0; while(1) { usleep(time_val.tv_usec); ret=get_first_ex_module(&ex_module); if(ret<0) return ret; while(ex_module!=NULL) { if(ex_module_tryjoin(ex_module,&thread_retval[i++])==0) { print_cubeaudit("monitor ex_modulec %s exited successfully!\n",ex_module_getname(ex_module)); return thread_retval[i-1]; } ret= get_next_ex_module(&ex_module); } i=0; } */ // third loop: join all the non_system module ret=get_first_ex_module(&ex_module); if(ret<0) return ret; i=0; while(ex_module!=NULL) { if((ex_module_gettype(ex_module) == MOD_TYPE_MONITOR) ||(ex_module_gettype(ex_module) == MOD_TYPE_PORT) ||(ex_module_gettype(ex_module) == MOD_TYPE_START)) { if(Strcmp(ex_module_getname(ex_module),"router_proc")!=0) { ret=ex_module_join(ex_module,&thread_retval[i++]); if(ret<0) { print_cubeerr("%s module exit!\n",ex_module_getname(ex_module)); return ret; } print_cubeaudit("%s module exit!\n",ex_module_getname(ex_module)); } } ret= get_next_ex_module(&ex_module); if(ret<0) return ret; } printf("thread return value %d!\n",thread_retval[0]); return ret; }
int main() { static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; char json_buffer[4096]; char print_buffer[4096]; int ret; int readlen; int json_offset; void * root_node; void * findlist; void * memdb_template ; BYTE uuid[DIGEST_SIZE]; int i; MSG_HEAD * msg_head; pthread_t cube_thread; char * baseconfig[] = { "typelist.json", "subtypelist.json", "msghead.json", "headrecord.json", NULL }; alloc_init(alloc_buffer); struct_deal_init(); memdb_init(); // test namelist reading start for(i=0;baseconfig[i]!=NULL;i++) { ret=read_json_file(baseconfig[i]); if(ret<0) return ret; printf("read %d elem from file %s!\n",ret,baseconfig[i]); } void * record; // test struct desc reading start msgfunc_init(); void * message; routine_init(NULL); routine_register("sub1",ROUTINE_SOURCE,&sub1_ops,NULL); routine_register("sub2",ROUTINE_SOURCE,&sub2_ops,NULL); pthread_create(&cube_thread,NULL,routine_start,NULL); int * thread_return; ret=pthread_join(cube_thread,&thread_return); printf("return value is %d\n",thread_return); // routine_start(); // sleep(100000); return 0; }