static int pv_get_from_tag_initial(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { struct to_body *xto; if(msg==NULL) return -1; if(parse_from_header(msg)<0) { LM_ERR("cannot parse From header\n"); return pv_get_null(msg, param, res); } if(msg->from==NULL || get_from(msg)==NULL) { LM_DBG("no From header\n"); return pv_get_null(msg, param, res); } xto = get_from(msg); if(is_direction(msg, RR_FLOW_UPSTREAM)==0) { if(msg->to==NULL && parse_headers(msg, HDR_TO_F, 0)==-1) { LM_ERR("cannot parse To header\n"); return pv_get_null(msg, param, res); } if(msg->to==NULL || get_to(msg)==NULL) { LM_DBG("no To header\n"); return pv_get_null(msg, param, res); } xto = get_to(msg); } if (xto->tag_value.s==NULL || xto->tag_value.len<=0) { LM_DBG("no Tag parameter\n"); return pv_get_null(msg, param, res); } return pv_get_strval(msg, param, res, &xto->tag_value); }
void id_trap(void) { short dir, row, col, d, t; messagef(0, "direction? "); while (!is_direction(dir = rgetchar(), &d)) { beep(); } check_message(); if (dir == CANCEL) { return; } row = rogue.row; col = rogue.col; get_dir_rc(d, &row, &col, 0); if ((dungeon[row][col] & TRAP) && (!(dungeon[row][col] & HIDDEN))) { t = trap_at(row, col); messagef(0, "%s", trap_strings[t*2]); } else { messagef(0, "no trap there"); } }
static int pv_get_rdir(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) { if(msg==NULL || param==NULL) return -1; switch(param->pvn.u.isname.name.n) { case 1: if(is_direction(msg, RR_FLOW_UPSTREAM)==0) return pv_get_strval(msg, param, res, &pv_rr_flow_list[1]); return pv_get_strval(msg, param, res, &pv_rr_flow_list[0]); default: if(is_direction(msg, RR_FLOW_UPSTREAM)==0) return pv_get_uintval(msg, param, res, RR_FLOW_UPSTREAM); return pv_get_uintval(msg, param, res, RR_FLOW_DOWNSTREAM); } }
int get_direction(void) { int dir; message(mesg[55], 0); while (!is_direction(dir = rgetchar())) { sound_bell(); } check_message(); return dir; }
void fight(boolean to_the_death) { short ch, c, d; short row, col; boolean first_miss = 1; short possible_damage; object *monster; while (!is_direction(ch = rgetchar(), &d)) { sound_bell(); if (first_miss) { message("direction?", 0); first_miss = 0; } } check_message(); if (ch == CANCEL) { return; } row = rogue.row; col = rogue.col; get_dir_rc(d, &row, &col, 0); c = mvinch(row, col); if (((c < 'A') || (c > 'Z')) || (!can_move(rogue.row, rogue.col, row, col))) { message("I see no monster there", 0); return; } if (!(fight_monster = object_at(&level_monsters, row, col))) { return; } if (!(fight_monster->m_flags & STATIONARY)) { possible_damage = ((get_damage(fight_monster->m_damage, 0) * 2) / 3); } else { possible_damage = fight_monster->stationary_damage - 1; } while (fight_monster) { one_move_rogue(ch, 0); if (((!to_the_death) && (rogue.hp_current <= possible_damage)) || interrupted || (!(dungeon[row][col] & MONSTER))) { fight_monster = NULL; } else { monster = object_at(&level_monsters, row, col); if (monster != fight_monster) { fight_monster = NULL; } } } }
static int w_is_direction(struct sip_msg *msg,char *dir, char *foo) { return ((is_direction(msg,(int)(long)dir)==0)?1:-1); }
int record_route_advertised_address(struct sip_msg* _m, str* _data) { str user = {NULL, 0}; str *tag = NULL; struct lump* l; struct lump* l2; int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0; int sips; int ret = 0; user.len = 0; user.s = 0; if (add_username) { if (get_username(_m, &user) < 0) { LM_ERR("failed to extract username\n"); return -1; } } else if (use_ob == 1) { if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } } else if (use_ob == 2) { if (copy_flow_token(&user, _m) != 0) { LM_ERR("copying outbound flow-token\n"); return -1; } } if (append_fromtag) { if (is_direction(_m, RR_FLOW_UPSTREAM) == 0) { if (parse_to_header(_m) < 0) { LM_ERR("To parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->to->parsed)->tag_value; } else { if (parse_from_header(_m) < 0) { LM_ERR("From parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->from->parsed)->tag_value; } } else { tag = 0; } sips = rr_is_sips(_m); if (enable_double_rr) { l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -3; goto error; } l = insert_cond_lump_after(l, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_PROTO, 0); l2 = insert_cond_lump_before(l2, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_PROTO, 0); if (!l || !l2) { LM_ERR("failed to insert conditional lump\n"); ret = -4; goto error; } if (build_advertised_rr(l, l2, _data, &user, tag, OUTBOUND, sips) < 0) { LM_ERR("failed to insert outbound Record-Route\n"); ret = -5; goto error; } } l = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -6; goto error; } if (build_advertised_rr(l, l2, _data, &user, tag, INBOUND, sips) < 0) { LM_ERR("failed to insert outbound Record-Route\n"); ret = -7; goto error; } ret = 1; error: if ((use_ob == 1) || (use_ob == 2)) if (user.s != NULL) pkg_free(user.s); return ret; }
/*! * \brief Insert a new Record-Route header field with lr parameter * * Insert a new Record-Route header field and also 2nd one if it is enabled * and the realm changed so the 2nd record-route header will be necessary. * \param _m SIP message * \param params RR parameter * \return 0 on success, negative on failure */ int record_route(struct sip_msg* _m, str *params) { struct lump* l, *l2; str user = {NULL, 0}; str* tag; int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0; int sips; int ret = 0; user.len = 0; if (add_username) { /* check if there is a custom user set */ if (get_custom_user(_m, &user) < 0) { if (get_username(_m, &user) < 0) { LM_ERR("failed to extract username\n"); return -1; } } } else if (use_ob == 1) { if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } } else if (use_ob == 2) { if (copy_flow_token(&user, _m) != 0) { LM_ERR("copying outbound flow-token\n"); return -1; } } if (append_fromtag) { if (is_direction(_m, RR_FLOW_UPSTREAM) == 0) { if (parse_to_header(_m) < 0) { LM_ERR("To parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->to->parsed)->tag_value; } else { if (parse_from_header(_m) < 0) { LM_ERR("From parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->from->parsed)->tag_value; } } else { tag = 0; } if (rr_param_buf.len && rr_param_msg!=_m->id) { /* rr_params were set for a different message -> reset buffer */ rr_param_buf.len = 0; } sips = rr_is_sips(_m); if (enable_double_rr) { l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -5; goto error; } l = insert_cond_lump_after(l, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_REALMS, 0); l2 = insert_cond_lump_before(l2, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_REALMS, 0); if (!l || !l2) { LM_ERR("failed to insert conditional lump\n"); ret = -6; goto error; } if (build_rr(l, l2, &user, tag, params, OUTBOUND, sips) < 0) { LM_ERR("failed to insert outbound Record-Route\n"); ret = -7; goto error; } } l = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -3; goto error; } if (build_rr(l, l2, &user, tag, params, INBOUND, sips) < 0) { LM_ERR("failed to insert inbound Record-Route\n"); ret = -4; goto error; } /* reset the rr_param buffer */ rr_param_buf.len = 0; ret = 0; error: if ((use_ob == 1) || (use_ob == 2)) if (user.s != NULL) pkg_free(user.s); return ret; }