static struct mi_root *mi_reset_stats(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *arg; stat_var *stat; int found; if (cmd->node.kids==NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; found = 0; for( arg=cmd->node.kids ; arg ; arg=arg->next) { if (arg->value.len==0) continue; stat = get_stat( &arg->value ); if (stat==0) continue; reset_stat( stat ); found = 1; } if (!found) { free_mi_tree(rpl_tree); return init_mi_tree( 404, "Statistics Not Found", 20); } return rpl_tree; }
/** * All statistic getter RPC callback. */ static void stats_get_all(rpc_t* rpc, void* ctx, char* stat) { int len = strlen(stat); struct rpc_list_params packed_params; str s_statistic; stat_var *s_stat; if (len==3 && strcmp("all", stat)==0) { packed_params.rpc = rpc; packed_params.ctx = ctx; counter_iterate_grp_names(rpc_get_all_grps_cbk, &packed_params); } else if (stat[len-1]==':') { packed_params.rpc = rpc; packed_params.ctx = ctx; stat[len-1] = '\0'; counter_iterate_grp_vars(stat, rpc_get_grp_vars_cbk, &packed_params); stat[len-1] = ':'; } else { s_statistic.s = stat; s_statistic.len = strlen(stat); s_stat = get_stat(&s_statistic); if (s_stat) { rpc->rpl_printf(ctx, "%s:%s = %lu", ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)), get_stat_val(s_stat)); } } }
/** * Satistic reset/clear-er RPC callback.. */ static void rpc_reset_or_clear_grp_vars_cbk(void* p, str* g, str* n, counter_handle_t h) { struct rpc_list_params *packed_params; rpc_t* rpc; void* ctx; int clear; stat_var *s_stat; long old_val, new_val; packed_params = p; rpc = packed_params->rpc; ctx = packed_params->ctx; clear = packed_params->clear; s_stat = get_stat(n); if (s_stat) { if (clear) { old_val=get_stat_val(s_stat); reset_stat(s_stat); new_val=get_stat_val(s_stat); if (old_val==new_val) { rpc->rpl_printf(ctx, "%s:%s = %lu", ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)), new_val); } else { rpc->rpl_printf(ctx, "%s:%s = %lu (%lu)", ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)), new_val, old_val); } } else { reset_stat(s_stat); } } }
/* Do we meet the requirements */ bool can_learn_ability(s32b ab) { ability_type *ab_ptr = &ab_info[ab]; s32b i; if (ab_ptr->acquired) return FALSE; if (p_ptr->skill_points < ab_info[ab].cost) return FALSE; for (i = 0; i < 10; i++) { /* Must have skill level */ if (ab_ptr->skills[i] > -1) { if (get_skill(ab_ptr->skills[i]) < ab_ptr->skill_levels[i]) return FALSE; } /* Must have ability */ if (ab_ptr->need_abilities[i] > -1) { if (!ab_info[ab_ptr->need_abilities[i]].acquired) return FALSE; } /* Must not have ability */ if (ab_ptr->forbid_abilities[i] > -1) { if (ab_info[ab_ptr->forbid_abilities[i]].acquired) return FALSE; } } for (i = 0; i <= STATS_MAX; i++) { /* Must have stat */ if (ab_ptr->stat[i] > -1) { if (get_stat(i, ind) < ab_ptr->stat[i] - 3) return FALSE; } } if (ab_ptr->allow != -1) { s32b ret; open_lua_functions_registry(get_lua_functions_registry_domain("ab_info"), ab_ptr->allow); call_lua(NULL, "(d)", "d", ab, &ret); close_lua_functions_registry(); if (!ret) return FALSE; } /* Do the script allow us? */ if (process_hooks(HOOK_LEARN_ABILITY, "(d)", ab)) return FALSE; return TRUE; }
void uart_rx_process(void) { switch (g_uart_rx_buff[0]) { case 'r': get_stat(); break; case 'u': get_transmitter_uptime(); break; case 's': x_start(); break; case 'q': if (g_uart_rx_buff[1] == 'd') { x_get_page(); } else { x_get_status(); } break; case '?': get_help(); break; default: uart_printf("invalid command, send ? to get help" UART_EOL); uart_tx_flush(); } }
static inline void save_session(lua_State *L, int type, int session) { if (session > 0 && (type & 0xff) != PTYPE_RESPONSE) { struct stat * S = get_stat(L); tqueue_push(S->tq, session, current_time_tick(S)); } }
void init_netload(netdata* data, const char* device) { memset( data, 0, sizeof(netdata) ); strncpy( data->ifdata.if_name, device, 9 ); data->ifdata.if_name[9] = '\0'; init_osspecific( data ); if (checkinterface(data) != TRUE) { data->correct_interface = FALSE; return; } /* init in a sane state */ get_stat(data); data->backup_in = data->stats.rx_bytes; data->backup_out = data->stats.tx_bytes; data->correct_interface = TRUE; #ifdef DEBUG fprintf( stderr, "The netload plugin was initialized for '%s'.\n", device ); #endif /* DEBUG */ }
/* * FUSE : get attributes of a file. * * path (foo/bar) * stbuf attributes * return 0 for success */ static int fos_getattr (const char *path, struct stat *stbuf) { int ret = 0; char *location; struct stat *st; /* Root directory */ if (!strcmp (path, "/")) location = strdup ("/sys_list"); else location = trim_fosname (path); /* Get file stats */ st = get_stat (location); if (st) { memcpy (stbuf, st, sizeof (*stbuf)); free (st); } else ret = -ENOENT; if (location) free (location); return ret; }
static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo) { struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p; pv_value_t pv_val; stat_var *stat; if (sopv->stat) { reset_stat( sopv->stat ); } else { if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 || (pv_val.flags & PV_VAL_STR)==0 ) { LM_ERR("failed to get pv string value\n"); return -1; } stat = get_stat( &(pv_val.rs) ); if ( stat == 0 ) { LM_ERR("variable <%.*s> not defined\n", pv_val.rs.len, pv_val.rs.s); return -1; } reset_stat( stat ); } return 1; }
int file_server::file_mode(std::string const &file_name) { port_stat st; if(get_stat(file_name.c_str(),&st) < 0) return 0; return st.st_mode; }
static inline int get_stat_name(struct sip_msg* msg, pv_name_t *name, int create, stat_var **stat) { pv_value_t pv_val; /* is the statistic found ? */ if (name->type==PV_NAME_INTSTR) { LM_NOTICE("xXx stat with name %p still not found\n", name); /* not yet :( */ /* do we have at least the name ?? */ if (name->u.isname.type==0) { /* name is FMT */ if (pv_printf_s( msg, (pv_elem_t *)name->u.isname.name.s.s, &(pv_val.rs) )!=0 || (pv_val.flags&PV_VAL_NULL) ) { LM_ERR("failed to get format string value\n"); return -1; } } else { /* name is string */ pv_val.rs = name->u.isname.name.s; } /* lookup for the statistic */ *stat = get_stat( &pv_val.rs ); LM_NOTICE("xXx stat name %p (%.*s) after lookup is %p\n", name, pv_val.rs.len, pv_val.rs.s, *stat); if (*stat==NULL) { if (!create) return 0; LM_DBG("creating dynamic statistic <%.*s>\n", pv_val.rs.len, pv_val.rs.s); /* stats not found -> create it */ if (register_dynamic_stat( &pv_val.rs, stat )!=0) { LM_ERR("failed to create dynamic statistic <%.*s>\n", pv_val.rs.len, pv_val.rs.s); return -1; } } /* if name is static string, better link the stat directly * and discard name */ if (name->u.isname.type==AVP_NAME_STR) { LM_NOTICE("xXx name %p freeing %p\n",name,name->u.isname.name.s.s); /* it is totally unsafe to free this shm block here, as it is * referred by the spec from all the processess. Even if we create * here a small leak (one time only), we do not have a better fix * until a final review of the specs in pkg and shm mem - bogdan */ //shm_free(name->u.isname.name.s.s); name->u.isname.name.s.s = NULL; name->u.isname.name.s.len = 0; name->type = PV_NAME_PVAR; name->u.dname = (void*)*stat; } } else { /* stat already found ! */ *stat = (stat_var*)name->u.dname; LM_NOTICE("xXx stat name %p is founded\n",name); } return 0; }
static int fixup_stat(void** param, int param_no) { struct stat_or_pv *sopv; str s; long n; int err; s.s = (char*)*param; s.len = strlen(s.s); if (param_no==1) { /* var name - string or pv */ sopv = (struct stat_or_pv *)pkg_malloc(sizeof(struct stat_or_pv)); if (sopv==NULL) { LM_ERR("no more pkg mem\n"); return E_OUT_OF_MEM; } memset( sopv, 0 , sizeof(struct stat_or_pv) ); /* is it pv? */ if (s.s[0]=='$') { if (fixup_pvar(param)!=0) { LM_ERR("invalid pv %.s as parameter\n",s.s); return E_CFG; } sopv->pv = (pv_spec_t*)(*param); } else { /* it is string */ sopv->stat = get_stat( &s ); if (sopv->stat==0) { LM_ERR("variable <%s> not defined\n", s.s); return E_CFG; } } pkg_free(s.s); *param=(void*)sopv; return 0; } else if (param_no==2) { /* update value - integer */ if (s.s[0]=='-' || s.s[0]=='+') { n = str2s( s.s+1, s.len-1, &err); if (s.s[0]=='-') n = -n; } else { n = str2s( s.s, s.len, &err); } if (err==0){ if (n==0) { LM_ERR("update with 0 has no sense\n"); return E_CFG; } pkg_free(*param); *param=(void*)n; return 0; }else{ LM_ERR("bad update number <%s>\n",(char*)(*param)); return E_CFG; } } return 0; }
gpointer mwChannel_getStatistic(struct mwChannel *chan, enum mwChannelStatField stat) { g_return_val_if_fail(chan != NULL, 0); g_return_val_if_fail(chan->stats != NULL, 0); return get_stat(chan, stat); }
static struct mi_root *mi_clear_stats(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *arg; stat_var *stat; str val; if(stats_support()==0) return init_mi_tree( 404, "Statistics Not Found", 20); if (cmd->node.kids==NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for( arg=cmd->node.kids ; arg ; arg=arg->next) { if (arg->value.len==0) continue; val = arg->value; if ( val.len==3 && memcmp(val.s,"all",3)==0) { /* add all statistic variables */ /* use direct counters access for that */ counter_iterate_grp_names(mi_add_all_grps_cbk2, rpl); } else if ( val.len>1 && val.s[val.len-1]==':') { /* add module statistics */ val.len--; val.s[val.len]=0; /* zero term. */ /* use direct counters access for that */ counter_iterate_grp_vars(val.s, mi_add_grp_vars_cbk2, rpl); val.s[val.len]=':' /* restore */; } else { /* reset & return only one statistic */ stat = get_stat( &val ); if (stat==0) continue; if (mi_reset_and_add_stat(rpl,stat)!=0) goto error; } } if (rpl->kids==0) { free_mi_tree(rpl_tree); return init_mi_tree( 404, "Statistics Not Found", 20); } return rpl_tree; error: free_mi_tree(rpl_tree); return 0; }
static struct mi_root *mi_get_stats(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *arg; module_stats *mods; stat_var *stat; str val; int i; if (cmd->node.kids==NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for( arg=cmd->node.kids ; arg ; arg=arg->next) { if (arg->value.len==0) continue; val = arg->value; if ( val.len==3 && memcmp(val.s,"all",3)==0) { /* add all statistic variables */ for( i=0 ; i<collector->mod_no ;i++ ) { if (mi_add_module_stats( rpl, &collector->amodules[i] )!=0) goto error; } } else if ( val.len>1 && val.s[val.len-1]==':') { /* add module statistics */ val.len--; mods = get_stat_module( &val ); if (mods==0) continue; if (mi_add_module_stats( rpl, mods )!=0) goto error; } else { /* add only one statistic */ stat = get_stat( &val ); if (stat==0) continue; if (mi_add_stat(rpl,stat)!=0) goto error; } } if (rpl->kids==0) { free_mi_tree(rpl_tree); return init_mi_tree( 404, "Statistics Not Found", 20); } return rpl_tree; error: free_mi_tree(rpl_tree); return 0; }
/** * Gets the current netload. * @param in Will be filled with the "in"-load. * @param out Will be filled with the "out"-load. * @param tot Will be filled with the "total"-load. */ void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot) { struct timeval curr_time; double delta_t; if( ! data->correct_interface ) { if( in != NULL && out != NULL && tot != NULL ) { *in = *out = *tot = 0; } } gettimeofday(&curr_time, NULL); delta_t = (double) ((curr_time.tv_sec - data->prev_time.tv_sec) * 1000000L + (curr_time.tv_usec - data->prev_time.tv_usec)) / 1000000.0; /* update */ get_stat(data); if (data->backup_in > data->stats.rx_bytes) { data->cur_in = (int) data->stats.rx_bytes / delta_t; } else { data->cur_in = (int) (data->stats.rx_bytes - data->backup_in) / delta_t; } if (data->backup_out > data->stats.tx_bytes) { data->cur_out = (int) data->stats.tx_bytes / delta_t; } else { data->cur_out = (int) (data->stats.tx_bytes - data->backup_out) / delta_t; } if( in != NULL && out != NULL && tot != NULL ) { *in = data->cur_in; *out = data->cur_out; *tot = *in + *out; } /* save 'new old' values */ data->backup_in = data->stats.rx_bytes; data->backup_out = data->stats.tx_bytes; /* do the same with time */ data->prev_time.tv_sec = curr_time.tv_sec; data->prev_time.tv_usec = curr_time.tv_usec; }
static int _timing(lua_State *L) { int session = luaL_checkinteger(L,1); struct stat * S = get_stat(L); double t = tqueue_pop(S->tq, session); if (t != 0) { t = current_time_tick(S) - t; } lua_pushnumber(L, t); return 1; }
int send_options_reply(RTSP_buffer * rtsp, long cseq) { char r[1024]; sprintf(r, "%s %d %s"RTSP_EL"CSeq: %ld"RTSP_EL, RTSP_VER, 200, get_stat(200), cseq); strcat(r, "Public: OPTIONS,DESCRIBE,SETUP,PLAY,PAUSE,TEARDOWN"RTSP_EL); strcat(r, RTSP_EL); bwrite(r, (unsigned short) strlen(r), rtsp); fnc_log(FNC_LOG_CLIENT,"200 - - "); return ERR_NOERROR; }
static int w_update_stat(struct sip_msg *msg, char *stat_p, char *n) { struct stat_param *sp = (struct stat_param *)stat_p; pv_value_t pv_val; stat_var *stat; if (sp->type==STAT_PARAM_TYPE_STAT) { /* we have the statistic */ update_stat( sp->u.stat, (long)n); return 1; } if (sp->type==STAT_PARAM_TYPE_PVAR) { /* take name from PVAR */ if (pv_get_spec_value(msg, sp->u.pvar, &pv_val)!=0 || (pv_val.flags & PV_VAL_STR)==0 ) { LM_ERR("failed to get pv string value\n"); return -1; } } else if (sp->type==STAT_PARAM_TYPE_FMT) { /* take name from FMT */ if (pv_printf_s( msg, sp->u.format, &(pv_val.rs) )!=0 ) { LM_ERR("failed to get format string value\n"); return -1; } } else if (sp->type==STAT_PARAM_TYPE_NAME) { /* take name from STRING */ pv_val.rs = *sp->u.name; } LM_DBG("needed statistic is <%.*s>\n", pv_val.rs.len, pv_val.rs.s); /* name is in pv_val.rs -> look for it */ stat = get_stat( &(pv_val.rs) ); if ( stat==NULL ) { /* stats not found -> create it */ LM_DBG("creating dynamic statistic <%.*s>\n", pv_val.rs.len, pv_val.rs.s); if (register_dynamic_stat( &(pv_val.rs), &stat )!=0) { LM_ERR("failed to create dynamic statistic <%.*s>\n", pv_val.rs.len, pv_val.rs.s); return -1; } if (sp->type==STAT_PARAM_TYPE_NAME) { sp->u.stat = stat; sp->type=STAT_PARAM_TYPE_STAT; } } /* statistic exists ! */ update_stat( stat, (long)n); return 1; }
void file_server::list_dir(std::string const &url,std::string const &path) { cppcms::impl::directory d; if(!d.open(path)) { show404(); return; } #ifdef CPPCMS_WIN_NATIVE response().content_type("text/html; charset=UTF-8"); #endif std::ostream &out = response().out(); out << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" " \"http://www.w3.org/TR/html4/loose.dtd\">\n"; out << "<html><head><title>Directory Listing</title></head>\n" "<body><h1>Index of " << util::escape(url) << "</h1>\n"; out << booster::locale::as::gmt; //out <<"<table cellpadding='0' cellspacing='2' border='0' >\n"; out <<"<table>\n"; out <<"<thead><tr><td width='60%'>File</td><td width='20%' >Date</td><td width='5%'> </td><td width='15%'>Size</td></tr></thead>\n" "<tbody>\n"; if(url!="/" && !url.empty()) { out << "<tr><td><code><a href='../' >..</a></code></td><td> </td><td> </td><td> </td></tr>\n"; } out << booster::locale::as::ftime("%Y-%m-%d %H:%M:%S"); while(d.next()) { if(memcmp(d.name(),".",1) == 0) continue; port_stat st; if(get_stat((path + "/" + d.name()).c_str(),&st) < 0) continue; char const *add=""; if(st.st_mode & S_IFDIR) add="/"; else if(st.st_mode & S_IFREG) ; else continue; out << "<tr>"; out << "<td><code><a href='" << util::urlencode(d.name()) << add << "'>" << util::escape(d.name()) << add << "</a></code></td>"; out << "<td>" << booster::locale::as::strftime << st.st_mtime <<"</td><td> </td>"; if(st.st_mode & S_IFREG) out << "<td>" << booster::locale::as::number << st.st_size <<"</td>"; else out << "<td> <strong>-</strong> </td>"; out <<"</tr>\n"; } out <<"</tbody>\n</table>\n"; out <<"<p>CppCMS-Embedded/" CPPCMS_PACKAGE_VERSION "</p>\n"; out <<"</body>\n"; }
void CharStats::init_totalstats() { totalstats.clear(); buffdeltas.clear(); percentages.clear(); totalstats[Equipstat::HP] = get_stat(Maplestat::MAXHP); totalstats[Equipstat::MP] = get_stat(Maplestat::MAXMP); totalstats[Equipstat::STR] = get_stat(Maplestat::STR); totalstats[Equipstat::DEX] = get_stat(Maplestat::DEX); totalstats[Equipstat::INT] = get_stat(Maplestat::INT); totalstats[Equipstat::LUK] = get_stat(Maplestat::LUK); totalstats[Equipstat::SPEED] = 100; totalstats[Equipstat::JUMP] = 100; maxdamage = 0; mindamage = 0; honor = 0; attackspeed = 0; projectilerange = 400; mastery = 0.0f; critical = 0.05f; mincrit = 0.5f; maxcrit = 0.75f; damagepercent = 0.0f; bossdmg = 0.0f; ignoredef = 0.0f; stance = 0.0f; resiststatus = 0.0f; reducedamage = 0.0f; }
void gear_stats_t::print( FILE* file ) { for ( int i=0; i < STAT_MAX; i++ ) { double value = get_stat( i ); if ( value != 0 ) { util_t::fprintf( file, " %s=%.*f", util_t::stat_type_abbrev( i ), ( ( ( value - ( int ) value ) > 0 ) ? 3 : 0 ), value ); } } util_t::fprintf( file, "\n" ); }
int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { stat_var *stat; stat = get_stat(¶m->pvn.u.isname.name.s); if (stat == NULL) { LM_WARN("No stat variable ``%.*s''\n", param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s); return pv_get_null(msg, param, res); } return pv_get_uintval(msg, param, res, (unsigned int)get_stat_val(stat)); }
// y is the y coordinate, the row number, and x is the x coordinate, the col number void drunken_walk (int y, int x, struct room rooms[ROWS*COLS]){ rooms[get_index(y, x)].visited = 1; int x_offset = 0; int y_offset = 0; int array[4] = {0, 1, 2, 3}; shuffle_array(array, 4); for (int i = 0; i < 4; i++) { if (array[i] == 0){ y_offset = 0; x_offset = 1; } else if (array[i] == 1){ y_offset = 0; x_offset = -1; } else if (array[i] == 2){ y_offset = 1; x_offset = 0; } else{ y_offset = -1; x_offset = 0; } if (out_of_bound(y + y_offset, x + x_offset)) set_stat(x_offset, y_offset, &rooms[get_index(y, x)], 1); else{ struct room *neighbor = &rooms[get_index(y + y_offset, x + x_offset)]; if (neighbor->visited == -1){ set_stat(x_offset, y_offset, &rooms[get_index(y, x)], 0); drunken_walk(y + y_offset, x + x_offset, rooms); } else if (get_stat(-x_offset, -y_offset, neighbor) != -1) set_stat(x_offset, y_offset, &rooms[get_index(y, x)], get_stat(-x_offset, -y_offset, neighbor)); else set_stat(x_offset, y_offset, &rooms[get_index(y, x)], 1); } } }
int statsc_svalue(str *name, int64_t *res) { stat_var *stat; stat = get_stat(name); if(stat==NULL) { LM_ERR("statistic %.*s not found\n", name->len, name->s); return -1; } *res = (int64_t)get_stat_val(stat); return 0; }
int send_play_reply(RTSP_buffer * rtsp, char *object, RTSP_session * rtsp_session) { char r[1024]; char temp[30]; RTP_session *p = rtsp_session->rtp_session; TRACE_FUNC(); /* build a reply message */ sprintf(r, "%s %d %s" RTSP_EL "CSeq: %d" RTSP_EL "Server: %s/%s" RTSP_EL, RTSP_VER, 200, get_stat(200), rtsp->rtsp_cseq, PACKAGE, VERSION); add_time_stamp(r, 0); strcat(r, "Session: "); sprintf(temp, "%d", rtsp_session->session_id); strcat(r, temp); strcat(r, RTSP_EL); // strcat(r, "RTP-info: url="); strcat(r, "RTP-info: "); // strcat(r, object); // strcat(r, ";"); do { strcat(r, "url="); // strcat(r, object); // TODO: we MUST be sure to send the correct url sprintf(r + strlen(r), "rtsp://%s/%s/%s!%s", prefs_get_hostname(), p->sd_filename, p->sd_filename, p->current_media->filename); strcat(r, ";"); sprintf(r + strlen(r), "seq=%u;rtptime=%u", p->start_seq, p->start_rtptime); if (p->next != NULL) { strcat(r, ","); } else { // strcat(r, "\r\n\r\n"); strcat(r, RTSP_EL); } p = p->next; } while (p != NULL); // end of message strcat(r, RTSP_EL); bwrite(r, (unsigned short) strlen(r), rtsp); // INFOLOGG("200 - %s ", object); return ERR_NOERROR; }
int pv_parse_name(pv_spec_p sp, str *in) { stat_var *stat; pv_elem_t *format; if(in==NULL || in->s==NULL || sp==NULL) return -1; LM_NOTICE("xXx name %p with name <%.*s>\n", &sp->pvp.pvn, in->len, in->s); if (pv_parse_format( in, &format)!=0) { LM_ERR("failed to parse statistic name format <%.*s> \n", in->len,in->s); return -1; } /* text only ? */ if (format->next==NULL && format->spec.type==PVT_NONE) { /* search for the statistic */ stat = get_stat( &format->text ); if (stat==NULL) { /* statistic does not exist (yet) -> fill in the string name */ sp->pvp.pvn.type = PV_NAME_INTSTR; sp->pvp.pvn.u.isname.type = AVP_NAME_STR; if (clone_pv_stat_name( in, &sp->pvp.pvn.u.isname.name.s )!=0) { LM_ERR("failed to clone name of statistic \n"); return -1; } LM_NOTICE("xXx name %p, name cloned (in=%p, out=%p)\n", &sp->pvp.pvn, in->s, sp->pvp.pvn.u.isname.name.s.s); } else { /* link the stat pointer directly as dynamic name */ sp->pvp.pvn.type = PV_NAME_PVAR; sp->pvp.pvn.u.dname = (void*)stat; LM_NOTICE("xXx name %p, stat found\n", &sp->pvp.pvn); } } else { sp->pvp.pvn.type = PV_NAME_INTSTR; sp->pvp.pvn.u.isname.type = 0; /* not string */ sp->pvp.pvn.u.isname.name.s.s = (char*)(void*)format; sp->pvp.pvn.u.isname.name.s.len = 0; LM_NOTICE("xXx name %p, stat name is FMT\n", &sp->pvp.pvn); } return 0; }
int depth_search (int x, int y, struct room **rooms, int goal_x, int goal_y, FILE *file){ if (x == goal_x && y == goal_y) return 1; (*rooms+get_index(x, y))->visited = 1; // x_offset is the offset on cols int x_offset = 0; // y_offset is the offset on rows int y_offset = 0; for (int i = 0; i < 4; i++) { // print the full path traveld #ifdef FULL if (fprintf(file, "%d, %d\n", i%COLS, i/COLS) < 0){ fprintf(stderr, "There is an error with the output file"); return 1; } #endif if (i == 0){ y_offset = 0; x_offset = 1; } else if (i == 1){ y_offset = 0; x_offset = -1; } else if (i == 2){ y_offset = 1; x_offset = 0; } else{ y_offset = -1; x_offset = 0; } // proceed if neighbor is in the maze other wise return to the for loop if (out_of_bound(x + x_offset, y + y_offset)==0){ struct room *neighbor = *rooms+get_index(x + x_offset, y + y_offset); if (get_stat(x_offset, y_offset, (*rooms+get_index(x, y))) == 0 && neighbor->visited == 0){ // if the current room is connected with the neighbor and the neighbor has not been visited // recurse on neighbor if (depth_search(x + x_offset, y + y_offset, rooms, goal_x, goal_y, file)){ // set the next pointer in the current room to the neighbor to complete the path, a list of // rooms (*rooms+get_index(x, y))->next = neighbor; //printf("next"); return 1; } } } } return 0; }
//发送options处理后的响应 int send_options_reply(RTSP_buffer * pRtsp, long cseq) { char r[1024]; sprintf(r, "%s %d %s"RTSP_EL"CSeq: %ld"RTSP_EL, RTSP_VER, 200, get_stat(200), cseq); strcat(r, "Public: OPTIONS,DESCRIBE,SETUP,PLAY,PAUSE,TEARDOWN"RTSP_EL); strcat(r, RTSP_EL); bwrite(r, (unsigned short) strlen(r), pRtsp); #ifdef RTSP_DEBUG // fprintf(stderr ,"SERVER SEND Option Replay: %s\n", r); #endif return ERR_NOERROR; }
/** * All statistics reset/clear-er RPC callback. */ static void stats_reset_or_clear_all(rpc_t* rpc, void* ctx, char* stat, int clear) { int len = strlen(stat); struct rpc_list_params packed_params; str s_statistic; stat_var *s_stat; long old_val, new_val; if (len==3 && strcmp("all", stat)==0) { packed_params.rpc = rpc; packed_params.ctx = ctx; packed_params.clear = clear; counter_iterate_grp_names(rpc_reset_or_clear_all_grps_cbk, &packed_params); } else if (stat[len-1]==':') { packed_params.rpc = rpc; packed_params.ctx = ctx; packed_params.clear = clear; stat[len-1] = '\0'; counter_iterate_grp_vars(stat, rpc_reset_or_clear_grp_vars_cbk, &packed_params); stat[len-1] = ':'; } else { s_statistic.s = stat; s_statistic.len = strlen(stat); s_stat = get_stat(&s_statistic); if (s_stat) { if (clear) { old_val=get_stat_val(s_stat); reset_stat(s_stat); new_val=get_stat_val(s_stat); if (old_val==new_val) { rpc->rpl_printf(ctx, "%s:%s = %lu", ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)), new_val); } else { rpc->rpl_printf(ctx, "%s:%s = %lu (%lu)", ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)), new_val, old_val); } } else { reset_stat(s_stat); } } } }