const char *cpiPython::GetConf(const char *conf, const char *var) { if (!conf || !var) { log2("PY: GetConf wrong parameters\n"); return NULL; } // first let's check hub's internal config: if(!strcmp(conf, "config")) { static string res, file(server->mDBConf.config_name); cConfigItemBase *ci = NULL; if(file == server->mDBConf.config_name) { ci = server->mC[var]; if (ci) { ci->ConvertTo(res); log3("PY: GetConf got result from mDBConf: %s\n", res.c_str()); return strdup(res.c_str()); } } return NULL; /*char *s = (char*) calloc(1000, sizeof(char)); int size = GetConfig((char*)conf, (char*)var, (char*)s, 999); if (size < 0) { log("PY: GetConf: error in script_api's GetConfig"); return NULL; } if (size > 999) { free(s); s = (char*) calloc(size+1, sizeof(char)); GetConfig((char*)conf, (char*)var, s, 999); return s; }*/ } // let's try searching the database directly: if (!lib_begin || !lib_pack || !lib_unpack || !lib_packprint) return NULL; log3("PY: GetConf file != 'config'... calling SQL\n"); string query = string() + "select val from SetupList where file='" + conf + "' and var='" + var + "'"; w_Targs *a = lib_pack( "sl", query.c_str(), (long)1 ); log3("PY: GetConf calling SQL with params: %s\n", lib_packprint(a)); w_Targs *ret = SQL (-2, a); freee(a); if (!ret) return NULL; long res, rows, cols; char **list; log3("PY: GetConf SQL returned %s\n", lib_packprint(ret)); if (!lib_unpack( ret, "lllp", &res, &rows, &cols, (void**) &list )) { log3("PY: GetConf call to SQL function failed\n"); freee(ret); return NULL; } freee(ret); if (!res || !rows || !cols || !list || !list[0]) return NULL; log3("PY: GetConf returning value: %s\n", list[0]); const char * result = list[0]; free(list); return result; }
int32_t gf_timer_call_cancel (glusterfs_ctx_t *ctx, gf_timer_t *event) { if (!ctx || !event) { gf_log ("timer", GF_LOG_ERROR, "!ctx || !event"); return 0; } gf_timer_registry_t *reg = gf_timer_registry_init (ctx); if (!reg) { gf_log ("timer", GF_LOG_ERROR, "!reg"); return 0; } pthread_mutex_lock (®->lock); { event->next->prev = event->prev; event->prev->next = event->next; } pthread_mutex_unlock (®->lock); freee (event); return 0; }
bool cpiPython::SetConf(const char *conf, const char *var, const char *val) { if (!conf || !var || !val) { log2("PY: SetConf: wrong parameters\n"); return false; } // first let's check hub's internal config: if(!strcmp(conf, "config")) { string file(server->mDBConf.config_name); cConfigItemBase *ci = NULL; if(file == server->mDBConf.config_name) { ci = server->mC[var]; if (ci) { ci->ConvertFrom(val); log3("PY: SetConf set the value directly in mDBConf to: %s\n", val); return true; } } return false; /*if (SetConfig((char*)conf, (char*)var, (char*)val)) return true; return false;*/ } // let's try searching the database directly: if (!lib_begin || !lib_pack || !lib_unpack || !lib_packprint) return false; log3("PY: SetConf file != 'config', file == '%s'\n", conf); string query = string() + "delete from SetupList where file='" + conf + "' and var='" + var + "'"; w_Targs *a = lib_pack( "sl", query.c_str(), (long)1 ); log3("PY: SetConf calling SQL with params: %s\n", lib_packprint(a)); w_Targs *ret = SQL (-2, a); if (a) free(a); long res, rows, cols; char **list; log3("PY: SetConf SQL returned %s\n", lib_packprint(ret)); if (!lib_unpack( ret, "lllp", &res, &rows, &cols, (void**) &list )) { log3("PY: SetConf call to SQL function failed\n"); freee(ret); return false; } freee(ret->args[3].p); freee(ret); if (!res) { log2("requested config variable ( %s in %s ) does not exist\n", var, conf); }; query = string("") + "insert into SetupList (file, var, val) values ('" + conf + "', '" + var + "', '" + val + "')"; a = lib_pack( "sl", query.c_str(), (long)1 ); log3("PY: SetConf calling SQL with params: %s\n", lib_packprint(a)); ret = SQL (-2, a); freee(a); log3("PY: SetConf SQL returned %s\n", lib_packprint(ret)); if (!lib_unpack( ret, "lllp", &res, &rows, &cols, (void**) &list )) { log3("PY: SetConf call to SQL function failed\n"); freee(ret); return false; } freee(ret->args[3].p); freee(ret); if (!res) return false; return true; }
transport_t * transport_load (dict_t *options, xlator_t *xl, event_notify_fn_t notify) { struct transport *trans = calloc (1, sizeof (struct transport)); data_t *type_data; char *name = NULL; void *handle = NULL; char *type = "ERROR"; if (!options) { freee (trans); gf_log ("transport", GF_LOG_ERROR, "options is NULL"); return NULL; } if (!xl) { freee (trans); gf_log ("transport", GF_LOG_ERROR, "xl is NULL"); return NULL; } if (!notify) { freee (trans); gf_log ("transport", GF_LOG_ERROR, "notify is NULL"); return NULL; } type_data = dict_get (options, "transport-type"); // transport type, e.g., "tcp" trans->xl = xl; trans->notify = notify; if (type_data) { type = data_to_str (type_data); } else { freee (trans); gf_log ("transport", GF_LOG_ERROR, "'option transport-type <xxxx/_____>' missing in specification"); return NULL; } asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); gf_log ("transport", GF_LOG_DEBUG, "attempt to load file %s", name); handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); if (!handle) { gf_log ("transport", GF_LOG_ERROR, "dlopen (%s): %s", name, dlerror ()); freee (name); freee (trans); return NULL; }; freee (name); if (!(trans->ops = dlsym (handle, "transport_ops"))) { gf_log ("transport", GF_LOG_ERROR, "dlsym (transport_ops) on %s", dlerror ()); freee (trans); return NULL; } if (!(trans->init = dlsym (handle, "gf_transport_init"))) { gf_log ("transport", GF_LOG_ERROR, "dlsym (gf_transport_init) on %s", dlerror ()); freee (trans); return NULL; } if (!(trans->fini = dlsym (handle, "gf_transport_fini"))) { gf_log ("transport", GF_LOG_ERROR, "dlsym (gf_transport_fini) on %s", dlerror ()); freee (trans); return NULL; } if (trans->init (trans, options, notify) != 0) { gf_log ("transport", GF_LOG_ERROR, "'%s' initialization failed", type); freee (trans); return NULL; } pthread_mutex_init (&trans->lock, NULL); return trans; }
bool cpiPython::OnFirstMyINFO(cConnDC *conn, cMessageDC *msg) { if (!online) return true; if((conn != NULL) && (conn->mpUser != NULL) && (msg != NULL)) { int func = W_OnFirstMyINFO; const char *original = msg->mStr.c_str(); const char *origdesc = NULL, *origtag = NULL, *origspeed = NULL, *origmail = NULL, *origsize = NULL; const char *n, *desc, *tag, *speed, *mail, *size; // will be assigned by SplitMyINFO (even with NULL values) const char *nick = conn->mpUser->mNick.c_str(); if (!SplitMyINFO(original, &n, &origdesc, &origtag, &origspeed, &origmail, &origsize)) { log1("PY: Call OnFirstMyINFO: malformed myinfo message: %s\n", original); return true; } w_Targs* args = lib_pack( "ssssss", n, origdesc, origtag, origspeed, origmail, origsize); log2("PY: Call %s: parameters %s\n", lib_hookname(func), lib_packprint(args)); bool ret = true; w_Targs *result; long l; if(Size()) { tvPythonInterpreter::iterator it; for(it = mPython.begin(); it != mPython.end(); ++it) { result = (*it)->CallFunction(func, args); if(!result) { log3("PY: Call %s: returned NULL\n", lib_hookname(func)); continue; } if(lib_unpack(result, "l", &l)) // default return value is 1L meaning: further processing, { log3("PY: Call %s: returned l:%ld\n", lib_hookname(func), l); if (!l) ret = false; // 0L means no more processing outside this plugin } else if (lib_unpack(result, "sssss", &desc, &tag, &speed, &mail, &size)) // script wants to change the contents of myinfo { log2("PY: modifying message - Call %s: returned %s\n", lib_hookname(func), lib_packprint(result)); if (desc || tag || speed || mail || size) { // message chunks need updating to new MyINFO // $MyINFO $ALL <nick> <interest>$ $<speed\x01>$<e-mail>$<sharesize>$ // $MyINFO $ALL nick <++ V:0.668,M:P,H:39/0/0,S:1>$ $DSL$$74894830123$ string newinfo = "$MyINFO $ALL "; newinfo += nick; newinfo += " "; newinfo += (desc) ? desc : origdesc; newinfo += (tag) ? tag : origtag; newinfo += "$ $"; newinfo += (speed) ? speed : origspeed; newinfo += "$"; newinfo += (mail) ? mail : origmail; newinfo += "$"; newinfo += (size) ? size : origsize; newinfo += "$"; log3("myinfo: [ %s ] will become: [ %s ]\n", original, newinfo.c_str()); msg->ReInit(); msg->mStr = newinfo; //msg->mType = eDC_MYINFO; msg->Parse(); if (msg->SplitChunks()) log1("cpiPython::OnFirstMyINFO: failed to split new MyINFO into chunks\n"); conn->mpUser->mEmail = msg->ChunkString(eCH_MI_MAIL); } ret = true; // we've changed myinfo so we want the hub to store it now } else // something unknown was returned... we will let the hub call other plugins log1("PY: Call %s: unexpected return value: %s\n", lib_hookname(func), lib_packprint(result)); free(result); } } freee(args); freee(n); freee(origdesc); freee(origtag); freee(origspeed); freee(origmail); freee(origsize); return ret; } return true; // true means further processing }