static int l_set_radio_info(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); int i; size_t len; const char *str, *band, *ifname; unsigned int tmp[6] = {0}; ifname = lua_tostring(L, 2); str = lua_tolstring(L, 3, &len); if (len != sizeof("00ffeeff00ff") - 1) { lua_pushnil(L); lua_pushfstring(L, "invalid str %s", str); return 2; } band = lua_tostring(L, 4); if (!(!strncmp(band, "2g", 2) || !strncmp(band, "5g", 2))) { lua_pushnil(L); lua_pushfstring(L, "invalid band %s", band); return 2; } ugw_ext_radio_info_t st; st.ap_devid = strtoull(str, NULL, 16); st.rf_type = (!strncmp(band, "2g", 2)) ? 0 : 1; int ret = set_radio_info(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }
int sa3adddecl (sa3cg cg, char* type, char* func, char* param) { uint32 size = 0; sa3decl* d = NULL; int saret = 0; uint16 keylen = 0; char* key = NULL; char* _func = NULL; CHK_CG (cg, saret); CHK_STR (type, saret); CHK_STR (func, saret); CHK_STR (param, saret); CALL_API (saret, getstruct (&size, (void**) &d, 3, type, func, param)); /* TODO: child thread start */ { _func = (char*) PI2PTR (d, d->func); // CALL_API (saret, getkey ("dl \0", (const char*) _func, &keylen, &key)); CALL_API (saret, put_ent (cg->pdb, _func, STRLEN(_func), (void*) d, size, DL)); } /* TODO: child thread end */ CLEANUP: if (NULL != d) { freestruct ((void**)&d); } if (NULL != key) { freekey (&key); } return saret; }
int sa3addcall (sa3cg cg, char* cr, char* cd) { /* Thread #0 parser */ uint32 size = 0; sa3call* c = NULL; int saret = 0; uint16 pklen = 0; uint16 fklen = 0; char* pk = NULL; char* tmpcr = NULL; CHK_CG (cg, saret); CHK_STR (cr, saret); CHK_STR (cd, saret); CALL_API (saret, getstruct (&size, (void**)&c, 2, cr, cd)); CALL_API (saret, put_ent (cg->pdb, NULL, 0, (void*) c, size, CR)); CLEANUP: if (NULL != pk) { freekey (&pk); } return saret; }
static int set_str_str_str(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_s_i)(int, char *, char *, char *); m_s_s_i func = (m_s_s_i)mode_ioctl->ioctl_func; assert(func); int ret = func(sock, lua_tostring(L, 2), lua_tostring(L, 3), lua_tostring(L, 4)); CHK_RET(ret, mode_ioctl); }
static int set_str_int_str(lua_State *L, void *param) { CHK_STR(L, 2);CHK_NUM(L, 3);CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl); typedef int (*m_s_i_i)(const char *, int, const char *); m_s_i_i func = (m_s_i_i)mode_ioctl->ioctl_func; int ret = func(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tostring(L, 4)); CHK_RET(ret, mode_ioctl); }
static void merge_list_set_val(struct obj_list_data *d, GtkTreeIter *iter, int row) { int cx; unsigned int i = 0; char *file, *bfile; for (i = 0; i < MERG_WIN_COL_NUM; i++) { switch (i) { case MERG_WIN_COL_FILE: getobj(d->obj, "file", row, 0, NULL, &file); bfile = getbasename(file); if (bfile) { list_store_set_string(GTK_WIDGET(d->text), iter, i, CHK_STR(bfile)); g_free(bfile); } else { list_store_set_string(GTK_WIDGET(d->text), iter, i, "...................."); } break; case MERG_WIN_COL_HIDDEN: getobj(d->obj, Mlist[i].name, row, 0, NULL, &cx); cx = ! cx; list_store_set_val(GTK_WIDGET(d->text), iter, i, Mlist[i].type, &cx); break; default: if (Mlist[i].type == G_TYPE_DOUBLE) { getobj(d->obj, Mlist[i].name, row, 0, NULL, &cx); list_store_set_double(GTK_WIDGET(d->text), iter, i, cx / 100.0); } else { getobj(d->obj, Mlist[i].name, row, 0, NULL, &cx); list_store_set_val(GTK_WIDGET(d->text), iter, i, Mlist[i].type, &cx); } } } }
std::string _nimble_exception::to_string( __in_opt bool verbose ) { std::stringstream result; SERIALIZE_CALL_RECUR(m_lock); result << what(); #ifndef NDEBUG if(verbose) { SET_TERM_ATTRIB(result, 1, COL_FORE_YELLOW); result << " ("; if(!m_source.empty()) { result << m_source << ":"; } result << m_line << ") "; CLEAR_TERM_ATTRIB(result); } #else REF_PARAM(verbose); #endif return CHK_STR(result.str()); }
/* mode,channel_arr,scantime */ static int l_start_scan(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); CHK_NUM(L, 4); CHK_TAB(L, 5); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_ext_scan_params_t st; st.scan_mode = lua_tointeger(L, 3); assert(st.scan_mode == 1 || st.scan_mode == 2); int i = 0; lua_pushnil(L); while (i < MAX_SCAN_CHAN_CNT && lua_next(L, -2)) { CHK_NUM(L, -1); st.scan_channel_list[i] = lua_tonumber(L, -1); lua_pop(L, 1); i++; } if (i == 0) { lua_pushboolean(L, 1); return 1; } st.channel_num = i; st.scan_per_channel_time = lua_tointeger(L, 4); int ret = start_scan(sock, lua_tostring(L, 2), &st); CHK_RET(ret, mode_ioctl); }
static void DriverDialogSelectCB(GtkWidget *wi, gpointer client_data) { int a, i, l, n; struct extprinter *pcur; struct DriverDialog *d; char *ptr, ngp_ext[] = ".ngp"; d = (struct DriverDialog *) client_data; a = combo_box_get_active(d->driver); if (a < 0) return; pcur = Menulocal.extprinterroot; i = 0; while (pcur) { if (i != a) { pcur = pcur->next; i++; continue; } if (pcur->ext && pcur->ext[0] != '\0') { if (NgraphApp.FileName) { l = strlen(NgraphApp.FileName); n = sizeof(ngp_ext) - 1; if (l > n && strcasecmp(NgraphApp.FileName + l - n, ngp_ext) == 0) { l -= n; } ptr = g_strdup_printf("%.*s.%s", l, NgraphApp.FileName, CHK_STR(pcur->ext)); gtk_entry_set_text(GTK_ENTRY(d->file), CHK_STR(ptr)); g_free(ptr); } d->ext = pcur->ext; } else { gtk_entry_set_text(GTK_ENTRY(d->file), ""); d->ext = NULL; } gtk_entry_set_text(GTK_ENTRY(d->option), CHK_STR(pcur->option)); break; } }
static struct fontmap * loadfont(char *fontalias, int font_style, int *symbol) { struct fontmap *fcur; PangoFontDescription *pfont; PangoStyle style; PangoWeight weight; *symbol = FALSE; if (nhash_get_ptr(Gra2cairoConf->fontmap, fontalias, (void *) &fcur)) { int i; if (nhash_get_int(CompatibleFontHash, fontalias, &i) == 0) { if (nhash_get_ptr(Gra2cairoConf->fontmap, CompatibleFont[i].name, (void *) &fcur) == 0) { font_style = CompatibleFont[i].style; *symbol = CompatibleFont[i].symbol; } } if (fcur == NULL && nhash_get_ptr(Gra2cairoConf->fontmap, DEFAULT_FONT, (void *) &fcur)) { return NULL; } } if (fcur->font) { pfont = fcur->font; } else { gchar *ptr; pfont = pango_font_description_new(); ptr = g_strdup_printf("%s%s%s", fcur->fontname, (fcur->alternative) ? "," : "", CHK_STR(fcur->alternative)); if (ptr) { pango_font_description_set_family(pfont, ptr); g_free(ptr); } else { return NULL; } } if (font_style > 0 && (font_style & GRA_FONT_STYLE_ITALIC)) { style = PANGO_STYLE_ITALIC; } else { style = PANGO_STYLE_NORMAL; } pango_font_description_set_style(pfont, style); if (font_style > 0 && (font_style & GRA_FONT_STYLE_BOLD)) { weight = PANGO_WEIGHT_BOLD; } else { weight = PANGO_WEIGHT_NORMAL; } pango_font_description_set_weight(pfont, weight); fcur->font = pfont; return fcur; }
static int set_str_int_p(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_i_s_i)(int, char *, int, char *, int); m_s_i_s_i func = (m_s_i_s_i)mode_ioctl->ioctl_func; assert(func); size_t len; char *data; data = lua_tolstring(L, 4, &len); if (!data) { lua_pushnil(L); lua_pushfstring(L, "invalid param 4"); return 2; } int ret = func(sock, lua_tostring(L, 2), lua_tointeger(L, 3), data, len); CHK_RET(ret, mode_ioctl); }
static void save_char_map_config(struct narray *conf) { char *title, *data, *buf; struct character_map_list *pcur; pcur = Menulocal.char_map; while (pcur) { title = CHK_STR(pcur->title); data = CHK_STR(pcur->data); buf = g_strdup_printf("character_map=%s,%s", title, data); if (buf) { arrayadd(conf, &buf); } pcur = pcur->next; } }
static void DriverDialogClose(GtkWidget *w, void *data) { int a, i; struct extprinter *pcur; struct DriverDialog *d; const char *s, *file; char *driver, *option; d = (struct DriverDialog *) data; if (d->ret == IDCANCEL) return; a = combo_box_get_active(d->driver); pcur = Menulocal.extprinterroot; i = 0; while (pcur != NULL) { if (i == a && pcur->driver) { driver = g_strdup(pcur->driver); if (driver) { putobj(d->Obj, "driver", d->Id, driver); } break; } pcur = pcur->next; i++; } s = gtk_entry_get_text(GTK_ENTRY(d->option)); file = gtk_entry_get_text(GTK_ENTRY(d->file)); option = NULL; if (s || file) { option = g_strdup_printf("%s%s%s%s", (file) ? "-o '" : "", CHK_STR(file), (file) ? "' " : "", CHK_STR(s)); } putobj(d->Obj, "option", d->Id, option); }
static void save_script_config(struct narray *conf) { char *buf, *script, *option, *description; struct script *scur; scur = Menulocal.scriptroot; while (scur) { script = CHK_STR(scur->script); option = CHK_STR(scur->option); description = CHK_STR(scur->description); buf = g_strdup_printf("script=%s,%s,%s,%s", scur->name, script, description, option); if (buf) { arrayadd(conf, &buf); } scur = scur->next; } }
static void save_ext_driver_config(struct narray *conf) { char *buf, *driver, *ext, *option; struct extprinter *pcur; pcur = Menulocal.extprinterroot; while (pcur) { driver = CHK_STR(pcur->driver); ext = CHK_STR(pcur->ext); option= CHK_STR(pcur->option); buf = g_strdup_printf("ext_driver=%s,%s,%s,%s", pcur->name, driver, ext, option); if (buf) { arrayadd(conf, &buf); } pcur = pcur->next; } }
/* ifname, wlanid */ static int l_set_vap_info(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_ext_vap_info_t st; const char *ifname = lua_tostring(L, 2); st.wlan_id = (uint32_t)lua_tointeger(L, 3); int ret = set_vap_info(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }
_nimble_exception::_nimble_exception( __in_opt const std::string &message, __in_opt const std::string &source, __in_opt size_t line ) : std::runtime_error(CHK_STR(message)), m_line(line), m_source(source) { return; }
int sa3open_p (sa3cg* cg, const char* name) { int saret = 0; CHK_PTR (cg, saret); CHK_STR (name, saret); CALL_API (saret, create_cg (cg, name)); CLEANUP: return saret; }
static void add_prm_str_to_array(struct menu_config *cfg, struct narray *conf) { char *buf, *prm; prm = CHK_STR(* (char **) cfg->data); buf = g_strdup_printf("%s=%s", cfg->name, prm); if (buf) { arrayadd(conf, &buf); } }
static int l_apctl(lua_State *L) { CHK_STR(L, 1); int i; const char *method = (const char *)lua_tostring(L, 1); mode_ioctl_st *mode_ioctl = find(method); if (!mode_ioctl) { lua_pushnil(L); lua_pushfstring(L, "invalid method %s", method); return 2; } return mode_ioctl->mode_func(L, mode_ioctl); }
/* ifname, wlanid */ static int l_vap_add_acl_mac(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); CHK_NUM(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_sta_acl_mac_t st; const char *ifname = lua_tostring(L, 2); st.seconds = (uint32_t)lua_tointeger(L, 4); // TODO unsigned char ? const char *mac = lua_tostring(L, 3); int ret = sscanf(mac, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", \ &st.mac[0], &st.mac[1], &st.mac[2], &st.mac[3], &st.mac[4], &st.mac[5]); if (ret != 6) { lua_pushnil(L); lua_pushfstring(L, "invalid mac %s", mac); return 2; } ret = vap_add_acl_mac(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }
static int check_overwrite(GtkWidget *parent, const char *filename) { int r; char *buf; if (filename == NULL || naccess(filename, W_OK)) return 0; buf = g_strdup_printf(_("`%s'\n\nOverwrite existing file?"), CHK_STR(filename)); r = message_box(parent, buf, "Driver", RESPONS_YESNO); g_free(buf); return r != IDYES; }
static int get_str_str(lua_State *L, void *param) { CHK_STR(L, 2); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_rs_i)(int, char *, char *, int); m_s_rs_i func = (m_s_rs_i)mode_ioctl->ioctl_func; assert(func); int max_size = 100 * 1024; char *buff = (char *)malloc(max_size); if (!buff) {fprintf(stderr, "malloc fail\n"); exit(-1);} int ret = func(sock, lua_tostring(L, 2), buff, max_size); if (ret) { free(buff); lua_pushnil(L); lua_pushfstring(L, "%s %d %s fail %s", __FILE__, __LINE__, (mode_ioctl)->method, strerror((ret))); return 2; } lua_pushstring(L, buff); free(buff); return 1; }
void gra2cairo_save_config(void) { char *buf; struct fontmap *fcur; struct narray conf; arrayinit(&conf, sizeof(char *)); if (gra2cairo_get_fontmap_num() == 0) { buf = g_strdup("font"); if (buf) { arrayadd(&conf, &buf); removeconfig(CAIROCONF, &conf); } } else { fcur = Gra2cairoConf->fontmap_list_root; while (fcur) { buf = g_strdup_printf("font=%s,%s%s%s", fcur->fontalias, fcur->fontname, (fcur->alternative) ? "," : "", CHK_STR(fcur->alternative)); if (buf) { arrayadd(&conf, &buf); } fcur = fcur->next; } replaceconfig(CAIROCONF, &conf); } /* for backward compatibility */ if (OldConfigExist) { buf = g_strdup("font_map"); if (buf) { arrayadd(&conf, &buf); removeconfig(CAIROCONF, &conf); } OldConfigExist = FALSE; } arraydel2(&conf); }
static int get_str_int(lua_State *L, void *param) { CHK_STR(L, 2); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_ri)(int, char *, int *); m_s_ri func = (m_s_ri)mode_ioctl->ioctl_func; assert(func); int val = 0; //fprintf(stderr, "%s %d %d %s %s\n", __FILE__, __LINE__, sock, lua_tostring(L, 2), mode_ioctl->method); int ret = func(sock, lua_tostring(L, 2), &val); if (ret) { lua_pushnil(L); lua_pushfstring(L, "%s fail %s", mode_ioctl->method, strerror(ret)); return 2; } lua_pushinteger(L, val); return 1; }
void _nimble_trace::generate( __in nimble_lvl_t level, __in const std::string &header, __in const std::string &funct, __in const std::string &source, __in size_t line, __in const char *format, ... ) { std::time_t tm; std::string buf, tmstr; std::stringstream result; SERIALIZE_CALL(m_lock); if(nimble_trace::m_started) { tm = std::time(NULL); tmstr = std::asctime(std::localtime(&tm)); result << "[" << tmstr.substr(0, tmstr.size() - 1) << "] "; if(!header.empty()) { result << CHK_STR(header); } if(!funct.empty()) { result << CHK_STR(funct); } if(format) { va_list lst; va_start(lst, format); int len = vsnprintf(NULL, 0, format, lst); if(len < 0) { buf = NIMBLE_TRACE_EXCEPTION_STRING( NIMBLE_TRACE_EXCEPTION_MALFORMED); } else if(!len) { buf = NIMBLE_TRACE_EXCEPTION_STRING( NIMBLE_TRACE_EXCEPTION_EMPTY); } else { va_end(lst); va_start(lst, format); buf.resize(++len, '\0'); len = vsnprintf((char *) &buf[0], len, format, lst); if(len < 0) { buf = NIMBLE_TRACE_EXCEPTION_STRING( NIMBLE_TRACE_EXCEPTION_MALFORMED); } else if(!len) { buf = NIMBLE_TRACE_EXCEPTION_STRING( NIMBLE_TRACE_EXCEPTION_EMPTY); } } va_end(lst); if(!buf.empty()) { result << ": " << CHK_STR(buf); } } result << " ("; if(!source.empty()) { result << source << ":"; } result << line << ")"; switch(level) { case TRACE_ERROR: SET_TERM_ATTRIB(nimble_trace::m_stream, 1, COL_FORE_RED); nimble_trace::m_stream << CHK_STR(result.str()) << std::endl; CLEAR_TERM_ATTRIB(nimble_trace::m_stream); break; case TRACE_WARNING: SET_TERM_ATTRIB(nimble_trace::m_stream, 1, COL_FORE_YELLOW); nimble_trace::m_stream << CHK_STR(result.str()) << std::endl; CLEAR_TERM_ATTRIB(nimble_trace::m_stream); break; default: nimble_trace::m_stream << CHK_STR(result.str()) << std::endl; break; } } }
void _nimble_exception::generate( __in const std::string &header, __in const std::string &message, __in const std::string &source, __in size_t line, __in const char *format, ... ) { std::string buf; std::stringstream result; if(!header.empty()) { SET_TERM_ATTRIB(result, 1, COL_FORE_RED); result << header << ": "; CLEAR_TERM_ATTRIB(result); } if(!message.empty()) { result << message; } if(format) { va_list lst; va_start(lst, format); int len = vsnprintf(NULL, 0, format, lst); if(len < 0) { buf = NIMBLE_EXCEPTION_EXCEPTION_STRING( NIMBLE_EXCEPTION_EXCEPTION_MALFORMED); } else if(!len) { buf = NIMBLE_EXCEPTION_EXCEPTION_STRING( NIMBLE_EXCEPTION_EXCEPTION_EMPTY); } else { va_end(lst); va_start(lst, format); buf.resize(++len, '\0'); len = vsnprintf((char *) &buf[0], len, format, lst); if(len < 0) { buf = NIMBLE_EXCEPTION_EXCEPTION_STRING( NIMBLE_EXCEPTION_EXCEPTION_MALFORMED); } else if(!len) { buf = NIMBLE_EXCEPTION_EXCEPTION_STRING( NIMBLE_EXCEPTION_EXCEPTION_EMPTY); } } if(!buf.empty()) { if(!message.empty()) { result << ": "; } result << CHK_STR(buf); } va_end(lst); } throw nimble_exception(CHK_STR(result.str()), source, line); }