unsigned char* var_alarmService(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { prop_data properties[KEYS_MAX]; int prop_count=0; static char ap_parameter[256]; static u_long ulong_ret; static long long_ret; if( header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED ) { return NULL; } /* * this is where we do the value assignments for the mib results. */ switch(vp->magic) { case WAPIALARMTIMES: *write_method = write_wapialarmtimes; memset(ap_parameter,0,256); prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties); get_prop("ALARM_TIMES",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; long_ret=atoi(ap_parameter); //printf("alarm times=%d\n",long_ret); return (u_char*) &long_ret ; case WAPIALARMFLAG: *write_method = write_wapialarmflag; prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties); get_prop("ALARM_FLAG",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; long_ret=atoi(ap_parameter); //printf("alarm flag = %d \n ",long_ret); return (u_char*) &long_ret ; case WAPISTARTSCANAPENABLED: *write_method = write_wapiStartScanApEnabled; long_ret=temp_start_scan_ap_enabled; return (u_char*) &long_ret ; case WAPIADDNEIGHBORHOODAPMACADDR: *write_method = write_wapiAddNeighborhoodApMacAddr; memset(ap_parameter,0,256); strcpy(ap_parameter,"00:00:00:00:00:00"); *var_len = strlen(ap_parameter); ap_parameter[*var_len]='\0'; return (u_char*) ap_parameter ; default: ERROR_MSG(""); } return NULL; }
// add by piyp 2008-12-1 int get_Mac_list(int index,char *mac) { prop_data properties[KEYS_MAX]; int prop_count=0; char macAddrName[25],temp[5]; char mac_addr[32]; memset(mac_addr,0,32); memset(macAddrName,0,25); memset(temp,0,5); strcpy(macAddrName,"NEIGHBORHOOD_AP_MAC_"); sprintf(temp,"%d",index); strcat(macAddrName,temp); prop_count=load_prop(SEP_EQUAL,WIRELESS_CONF,properties); if(get_prop(macAddrName,mac_addr,properties,prop_count)==NULL){ /*ljy--test start*/ printf("%s: prop_count %d.\n", __func__, prop_count); /*ljy--test end*/ return 0; } free_prop(properties,prop_count); //printf("%s: mac_addr = %s.\n", __func__, mac_addr); memcpy(mac,mac_addr,32); //sprintf(mac,"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",mac_addr[0],mac_addr[1],\ // mac_addr[2],mac_addr[3],\ // mac_addr[4],mac_addr[5]); return 1; }
void free_prop(struct kv *h){ if(h!=0){ free_item(&h->key); free_item(&h->value); struct kv * next = h->next; free(h); free_prop(next); } }
V7_PRIVATE void v7_freeval(struct v7 *v7, struct v7_val *v) { assert(v->ref_count > 0); if (--v->ref_count > 0) return; if (v->type == V7_TYPE_OBJ) { struct v7_prop *p, *tmp; for (p = v->props; p != NULL; p = tmp) { tmp = p->next; free_prop(v7, p); } v->props = NULL; } if (v7_is_class(v, V7_CLASS_ARRAY)) { struct v7_prop *p, *tmp; for (p = v->v.array; p != NULL; p = tmp) { tmp = p->next; free_prop(v7, p); } v->v.array = NULL; } else if (v->type == V7_TYPE_STR && (v->flags & V7_STR_ALLOCATED)) { free(v->v.str.buf); } else if (v7_is_class(v, V7_CLASS_REGEXP) && (v->flags & V7_STR_ALLOCATED)) { free(v->v.regex); } else if (v7_is_class(v, V7_CLASS_FUNCTION)) { if ((v->flags & V7_STR_ALLOCATED) && (v->flags & V7_JS_FUNC)) { free(v->v.func.source_code); v7_freeval(v7, v->v.func.var_obj); } } if (v->flags & V7_VAL_ALLOCATED) { v->flags &= ~V7_VAL_ALLOCATED; v->flags |= ~V7_VAL_DEALLOCATED; memset(v, 0, sizeof(*v)); #ifdef V7_CACHE_OBJS v->next = v7->free_values; v7->free_values = v; #else free(v); #endif } }
V7_PRIVATE enum v7_err v7_del2(struct v7 *v7, struct v7_val *obj, const char *key, unsigned long n) { struct v7_val k = str_to_val(key, n); struct v7_prop **p; CHECK(obj->type == V7_TYPE_OBJ, V7_TYPE_ERROR); for (p = &obj->props; *p != NULL; p = &p[0]->next) { if (cmp(&k, p[0]->key) == 0) { struct v7_prop *next = p[0]->next; free_prop(v7, p[0]); p[0] = next; break; } } return V7_OK; }
void session_clean(struct session *s){ debug("session_clean"); free_item(&s->path); free_item(&s->host); free_item(&s->cookie); free_item(&s->referer); free_item(&s->ua); free_item(&s->post_buf); free_item(&s->last_request_header); free_item(&s->last_response_header); free_prop(s->proplist); s->proplist = NULL; free_buf(s->response_body_first); s->response_body_first = NULL; }
/*更新AP证书的状态*/ int update_cert_status(char *fileconfig) { prop_data properties[KEYS_MAX]; int prop_count=0; char get_cert_status[255] ={0,}; int res = 0; /*从配置文件中读取证书状态*/ prop_count=load_prop(SEP_EQUAL,fileconfig,properties); get_prop("CERT_STATUS", get_cert_status, properties, prop_count); free_prop(properties,prop_count); /*判断证书状态是否是无效*/ if(atoi(get_cert_status) != 1) { /*将状态修改为有效*/ res = !save_cert_status(fileconfig, "1"); } return res; }
void init_alarmService(void) { prop_data properties[KEYS_MAX]; int prop_count=0; char ap_parameter[256]; long int ret ; /* get basic info */ prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties); memset(ap_parameter,0,256); get_prop("ALARM_TIMES",ap_parameter,properties,prop_count); alarmTimes = atoi(ap_parameter); memset(ap_parameter,0,256); get_prop("ALARM_FLAG",ap_parameter,properties,prop_count); if( strcmp(ap_parameter,"")==0 ){ strcpy(ap_parameter,"0"); } alarmFlag= atoi(ap_parameter); free_prop(properties,prop_count); if( alarmFlag != 0 ){ if(alarmTimes>0) alarmId=snmp_alarm_register(alarmTimes, //10 /* seconds */ SA_REPEAT, /* repeat (every 30 seconds). */ register_callback, /* our callback */ NULL ); /* no callback data needed */ else alarmId=snmp_alarm_register(ALARM_TET_FREQUENCY, //10 /* seconds */ SA_REPEAT, /* repeat (every 30 seconds). */ register_callback, /* our callback */ NULL ); /* no callback data needed */ } REGISTER_MIB("autelan-mib/autelan-sourceFile/wapi/alarm", alarm_variables, variable4, alarm_variables_oid); }
/* * var_apGeneralInfo(): * This function is called every time the agent gets a request for * a scalar variable that might be found within your mib section * registered above. It is up to you to do the right thing and * return the correct value. * You should also correct the value of "var_len" if necessary. * * Please see the documentation for more information about writing * module extensions, and check out the examples in the examples * and mibII directories. */ unsigned char * var_apGeneralInfo(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { /* variables we may use later */ static long long_ret; static u_long ulong_ret; static unsigned char string[256]; static unsigned char string1[2048]; char string2[2048]; static char str_tmp[1024]; static unsigned char ap_parameter[256]; static unsigned char para[256]; static unsigned char ipaddr[32]; prop_data properties[255]; int prop_count=0; static oid objid[128]; static struct counter64 c64; FILE *stream; static char buffer[4][32]; static char strBuf[2][32]; static char MACWork[17]; static char *token; static char *pos; static int retu_addr=0; int byte_read=0; int memTotal=0; int i=0; if (header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED ) return NULL; /* * this is where we do the value assignments for the mib results. */ switch(vp->magic) { case SYSTIME: *write_method = write_SysTime; stream=popen("date","r"); if(stream) { memset( string, 0, 256 ); fgets(string,sizeof(string),stream); string[strlen(string)-1] = '\0'; pclose(stream); *var_len = strlen (string ); return (u_char*)string; } case PRIMDNSSERVERIPADD: memset( string, 0, 256 ); *write_method = write_PrimDNSServerIPAdd; network_get_dns(string,1,20 ); retu_addr=inet_addr(string); *var_len = 4; return (u_char*)&retu_addr; case SECONDNSSERVERIPADD: memset( string, 0, 256 ); *write_method = write_SeconDNSServerIPAdd; network_get_dns(string,2,20 ); retu_addr=inet_addr(string); *var_len = 4; return (u_char*)&retu_addr; case SNMPPORT: ulong_ret =161; return (u_char*) &ulong_ret; case READCOMMUNITYNAME: *write_method = write_ReadCommunityName; memset(string,0,256); memset(para,0,256); memset(buffer[0],0,32); memset(buffer[1],0,32); memset(buffer[2],0,32); memset(buffer[3],0,32); stream=fopen("/etc/snmp/snmpd.conf","r"); if(stream) { fgets(string,64,stream); token=strtok(string," "); while(NULL!=token) { strcpy(buffer[i],token); token=strtok(NULL," "); i++; } strcpy(para,buffer[3]); para[strlen(para)-1] = '\0'; fclose(stream); } *var_len = strlen(para); return (u_char *) para; case WRITECOMMUNITYNAME: *write_method = write_WriteCommunityName; memset(string,0,256); memset(para,0,256); memset(buffer[0],0,32); memset(buffer[1],0,32); memset(buffer[2],0,32); memset(buffer[3],0,32); stream=fopen("/etc/snmp/snmpd.conf","r"); if(stream) { fgets(string,64,stream); fgets(string,64,stream); token=strtok(string," "); while(NULL!=token) { strcpy(buffer[i],token); token=strtok(NULL," "); i++; } strcpy(para,buffer[3]); para[strlen(para)-1] = '\0'; fclose(stream); } *var_len = strlen(para); return (u_char *) para; case STATWINDOWTIME: *write_method = write_StatWindowTime; memset(ap_parameter,0,256); prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("STAT_WINDOW_TIME",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; long_ret =atoi(ap_parameter); return (u_char*) &long_ret; case SAMPLETIME: memset(ap_parameter,0,256); *write_method = write_SampleTime; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("SAMPLE_TIME",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; ulong_ret =atoi(ap_parameter); return (u_char*) &ulong_ret; case HEARTBEATPERIOD: memset(ap_parameter,0,256); *write_method = write_HeartbeatPeriod; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("HEART_BEAT_PERIOD",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; ulong_ret =atoi(ap_parameter); return (u_char*) &ulong_ret; case SYSREMOTERESTART: *write_method = write_SysRemoteRestart; ulong_ret =1; return (u_char*) &ulong_ret; case SYSRESTART: *write_method = write_SysRestart; ulong_ret =1; return (u_char*) &ulong_ret; case SYSRESET: *write_method = write_SysReset; ulong_ret =1; return (u_char*) &ulong_ret; case SOFTWARENAME: memset(para,0,256); sprintf(para,"%s","/usr/sbin/showsysinfo |awk -F \":\" '/Device/{print $2}' "); stream=popen(para,"r"); if(stream) { memset(string,0,256); fgets(string,sizeof(string),stream); string[strlen(string)-1]='\0'; pclose(stream); } *var_len = strlen(string); return (u_char*) string; case SOFTWAREVERSION: memset(para,0,256); sprintf(para,"%s","/usr/sbin/showsysinfo |awk -F \":\" '/Software/{print $2}'"); stream=popen(para,"r"); if(stream) { memset(string,0,256); fgets(string,sizeof(string),stream); string[strlen(string)-1]='\0'; pclose(stream); } *var_len = strlen(string); return (u_char*) string; case SOFTWAREVENDOR: memset(para,0,256); sprintf(para,"%s","/usr/sbin/showsysinfo |awk -F \":\" '/Company/{print $2}' "); stream=popen(para,"r"); if(stream) { memset(string,0,256); fgets(string,sizeof(string),stream); string[strlen(string)-1]='\0'; pclose(stream); } *var_len = strlen(string); return (u_char*) string; case CPUTYPE: stream = fopen("/proc/cpuinfo", "r"); if(stream) { fgets(string,64,stream); token=strtok(string,":"); while(NULL!=token) { strcpy(strBuf[i],token); token=strtok(NULL,":"); i++; } strcpy(para,strBuf[1]); para[strlen(para)-1] = '\0'; fclose(stream); } *var_len = strlen(para); return (u_char*) para; case CPUUSAGETHRESHHD: *write_method = write_CPUusageThreshhd; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("CPU_USAGE_THRESHHD",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; ulong_ret =atoi(ap_parameter); return (u_char*) &ulong_ret; case APMEMORYTYPE: memset(ap_parameter,0,256); prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("AP_MEMORY",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; *var_len = strlen(ap_parameter); return (u_char*) ap_parameter; case MEMORYSIZE: stream = fopen("/proc/meminfo", "r"); byte_read=fread(str_tmp, 1, sizeof(str_tmp), stream); fclose(stream); if (byte_read==0||byte_read==sizeof(str_tmp)) return -1; str_tmp[byte_read] = '\0'; pos = strstr(str_tmp, "MemTotal:"); if (NULL==pos) return -1; sscanf(pos, "MemTotal: %d kB", &memTotal); printf("memTotal:%d\n",memTotal); long_ret =memTotal*1024; return (u_char *) &long_ret; case MEMUSAGETHRESHHD: memset(ap_parameter,0,256); *write_method = write_MemUsageThreshhd; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("MEM_USAGE_THRESHHD",ap_parameter,properties,prop_count); free_prop(properties,prop_count) ; ulong_ret =atoi(ap_parameter); return (u_char*) &ulong_ret; case APFLASHSIZE: long_ret =32*1024*1024; return (u_char *) &long_ret; case ROGUEAPTRIGGER: *write_method = write_RogueApTrigger; memset(string,0,256); strcpy(string,"trigger rogue ap"); *var_len = strlen(string); return (u_char*) string; //heyanhua add for setPingIPaddr ---2010-4-23 case SETPINGIPADDR: memset(ipaddr,0,32); *write_method = write_setPingIPaddr; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("PING_ADDR",ipaddr,properties,prop_count); free_prop(properties,prop_count) ; printf("setPingIPaddr:%s\n",ipaddr); retu_addr=inet_addr(ipaddr); *var_len = 4; return ( UCHAR * )&retu_addr; //heyanhua add for ping testing ---2010-4-22 case SYSPINGTESTING: { FILE *fp; char cmd[128]; memset(cmd, 0, 128); memset(string1,0,2048); memset(string2,0,2048); prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("PING_ADDR",para,properties,prop_count); free_prop(properties,prop_count) ; printf("The PING_ADDR is :%s\n",para); // retu_addr=inet_addr(para); sprintf(cmd,"%s %s","/bin/ping -c 4",para); fp=popen(cmd,"r"); if(fp) { while(NULL!=fgets(string1,sizeof(string1),fp)) strcat(string2,string1); printf("heyanhua test! string1:%s\n",string1); pclose(fp); } *var_len=strlen(string2); printf("heyanhua test 1:string2:%s\n",string2); return (u_char *)string2; } case HARDWAREVERSION: //heyanhua add 2010-4-30 { FILE *fp; fp=popen("/usr/sbin/showsysinfo |awk -F : '/Hardware/ {print $2}'","r"); if(fp) { memset(string,0,256); fgets(string,sizeof(string),fp); pclose(fp); } *var_len=strlen(string); return (u_char *)string; } case SETPINGIPV6ADDR: memset(string,0,256); *write_method=write_setPingIPv6addr; prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("PING_IPv6_ADDR",string,properties,prop_count); free_prop(properties,prop_count) ; printf("setPingIPaddr:%s\n",string); *var_len = strlen(string); return ( UCHAR * )string; case SYSPINGIPV6TESTING: { FILE *fp; char cmd[128]; memset(cmd, 0, 128); memset(string1,0,2048); memset(string2,0,2048); prop_count=load_prop(SEP_EQUAL,SNMP_AGENT_CONF,properties); get_prop("PING_IPv6_ADDR",para,properties,prop_count); free_prop(properties,prop_count) ; printf("The PING_IPv6_ADDR is :%s\n",para); sprintf(cmd,"%s %s","/bin/ping6 -c 4",para); fp=popen(cmd,"r"); if(fp) { while(NULL!=fgets(string1,sizeof(string1),fp)) strcat(string2,string1); printf("heyanhua test! string1:%s\n",string1); pclose(fp); } *var_len=strlen(string2); printf("heyanhua test 1:string2:%s\n",string2); return (u_char *)string2; } default: ERROR_MSG(""); } return NULL; }