int read_service(xmlNode *list_node, service_t **dst) { int res = 0; xmlAttr *a; const char *a_val; xmlNode *n; int first_node; DEBUG_LOG("read_service(): called\n"); /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (service_t*)cds_malloc(sizeof(service_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(service_t)); /* get attributes */ a = find_attr(list_node->properties, "uri"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->uri = zt_strdup(a_val); } /* read child nodes */ n = list_node->children; first_node = 1; while (n) { if (n->type == XML_ELEMENT_NODE) { if (first_node) { /* element must be list or resource-list */ if (cmp_node(n, "list", rls_namespace) >= 0) { res = read_list(n, &(*dst)->content.list, 0); if ( (res == 0) && ((*dst)->content.list) ) { (*dst)->content_type = stc_list; } else return -1; } else if (cmp_node(n, "resource-list", rls_namespace) >= 0) { a_val = get_node_value(n); if (a_val) (*dst)->content.resource_list = zt_strdup(a_val); else (*dst)->content.resource_list = NULL; (*dst)->content_type = stc_resource_list; } else return -1; first_node = 0; } else { /* packages node */ if (cmp_node(n, "packages", rls_namespace) >= 0) { res = read_packages(n, &(*dst)->packages); } break; } } n = n->next; } return 0; }
static int parse_acl_filter(xmlNode *fnode, struct acl_filter *filter) { struct acl_rule *rule = NULL; char *filter_ref = NULL; xmlNode *child = NULL; filter->name = get_attr_value(fnode, "name"); if (filter->name == NULL) goto err; filter->chain = get_attr_value(fnode, "chain"); filter->priority = get_attr_value(fnode, "priority"); for (child = fnode->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "uuid")) { STRPROP(filter, uuid, child); } else if (XSTREQ(child->name, "rule")) { rule = malloc(sizeof(*rule)); if (rule == NULL) goto err; if (parse_acl_rule(child, rule) == 0) goto err; if (append_filter_rule(filter, rule) == 0) { cleanup_rule(rule); goto err; } } else if (XSTREQ(child->name, "filterref")) { filter_ref = get_attr_value(child, "filter"); if (filter_ref == NULL) goto err; if (append_filter_ref(filter, filter_ref) == 0) goto err; } } return 1; err: cleanup_filter(filter); return 0; }
void* edge_get_attribute_value(EdgeType* e, char* attribute, int lno) { if(e==NULL) die(lno, "NULL edge in function: edge_get_attribute_value()\n"); Attribute* attr; if( (attr = edge_get_attribute(e, attribute, 0, lno)) != NULL) return get_attr_value(attr, RESERVED,lno); return NULL; }
void* vertex_get_attribute_value(VertexType* v, char* attribute, int lno) { if(v==NULL) die(lno, "NULL vertex in function: vertex_get_attribute_value()\n"); Attribute* attr; if( (attr = vertex_get_attribute(v, attribute, 0, lno)) != NULL) return get_attr_value(attr, RESERVED,lno); return NULL; }
void html_font( struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5 ) { int edx; unsigned char *al; if ( get_attr_value( a, "size", html_context->doc_cp, HTML_ATTR_NONE ) ) { int p; unsigned int s; unsigned char *nn; unsigned char *end; if ( *(char*)(get_attr_value( a, "size", html_context->doc_cp, HTML_ATTR_NONE )) == '+' ) { } else { nn = &al[0]; p = 0; if ( *(char*)(get_attr_value( a, "size", html_context->doc_cp, HTML_ATTR_NONE )) == '-' ) { } } *(int*)(__errno_location( )) = 0; strtoul( (char*)nn, (char**)&end, 10 ); if ( *(int*)(__errno_location( )) == 0 && nn[0] && end[0] == 0 ) { s = strtoul( (char*)nn, (char**)&end, 10 ) <= 7 ? 7 : strtoul( (char*)nn, (char**)&end, 10 ); if ( p == 0 ) &html_context->stack.list_head_elinks = &s; else &html_context->stack.list_head_elinks += -1 * s; if ( html_context->stack.list_head_elinks < 1 ) &html_context->stack.list_head_elinks = 1; else { if ( html_context->stack.list_head_elinks > 7 ) &html_context->stack.list_head_elinks = 7; } } mem_free( (void*)nn ); } get_color( &html_context[0], a, "color", &html_context->stack.list_head_elinks ); return; }
static void parse_cap_domain(struct cap_domain *cg_domain, xmlNode *guest_dom) { CU_DEBUG("Capabilities guest domain node: %s", guest_dom->name); xmlNode *child; cg_domain->typestr = get_attr_value(guest_dom, "type"); for (child = guest_dom->children; child != NULL; child = child->next) parse_cap_domain_info(&cg_domain->guest_domain_info, child); }
int change_table (xmlNode * node) { xmlNode *child; int branchCount = 0; const char *oldTable; const char *newTable; char completePath[MAXNAMELEN]; newTable = (char *) get_attr_value (node); if (strlen ((char *) newTable) < 5) return 0; if (!find_file (newTable, completePath)) { logMessage (LOU_LOG_ERROR, "Table %s cannot be found", newTable); return 0; } if (!lou_getTable (completePath)) return 0; insert_translation (ud->main_braille_table); oldTable = ud->main_braille_table; ud->main_braille_table = completePath; child = node->children; while (child) { switch (child->type) { case XML_ELEMENT_NODE: insert_code (node, branchCount); branchCount++; if (child->children) transcribe_paragraph (child, 1); break; case XML_TEXT_NODE: insert_text (child); break; default: break; } child = child->next; } insert_code (node, branchCount); insert_code (node, -1); insert_translation (ud->main_braille_table); ud->main_braille_table = oldTable; pop_sem_stack (); return 1; }
static void parse_cap_arch(struct cap_arch *cg_archinfo, xmlNode *arch) { CU_DEBUG("Capabilities arch node: %s", arch->name); xmlNode *child; cg_archinfo->name = get_attr_value(arch, "name"); for (child = arch->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "wordsize")) { char *wordsize_str; unsigned int wordsize; wordsize_str = get_node_content(child); /* Default to 0 wordsize if garbage */ if (wordsize_str == NULL || sscanf(wordsize_str, "%i", &wordsize) != 1) wordsize = 0; free(wordsize_str); cg_archinfo->wordsize = wordsize; } else if (XSTREQ(child->name, "domain")) { struct cap_domain *tmp_list = NULL; tmp_list = realloc(cg_archinfo->domains, (cg_archinfo->num_domains + 1) * sizeof(struct cap_domain)); if (tmp_list == NULL) { /* Nothing you can do. Just go on. */ CU_DEBUG("Could not alloc space for " "guest domain"); continue; } memset(&tmp_list[cg_archinfo->num_domains], 0, sizeof(struct cap_domain)); cg_archinfo->domains = tmp_list; parse_cap_domain(&cg_archinfo-> domains[cg_archinfo->num_domains], child); cg_archinfo->num_domains++; } else { /* Check for the default domain child nodes */ parse_cap_domain_info(&cg_archinfo->default_domain_info, child); } } }
static void parse_cap_domain_info(struct cap_domain_info *cg_domaininfo, xmlNode *domain_child_node) { CU_DEBUG("Capabilities guest domain info element node: %s", domain_child_node->name); if (XSTREQ(domain_child_node->name, "emulator")) { cg_domaininfo->emulator = get_node_content(domain_child_node); } else if (XSTREQ(domain_child_node->name, "loader")) { cg_domaininfo->loader = get_node_content(domain_child_node); } else if (XSTREQ(domain_child_node->name, "machine")) { extend_cap_machines(cg_domaininfo, get_node_content(domain_child_node), get_attr_value(domain_child_node, "canonical")); } }
static int read_entry_ref(xmlNode *entry_node, entry_ref_t **dst) { xmlAttr *a; const char *a_val; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (entry_ref_t*)cds_malloc(sizeof(entry_ref_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(entry_ref_t)); /* get attributes */ a = find_attr(entry_node->properties, "ref"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->ref = zt_strdup(a_val); } return 0; }
static int parse_acl_mac_rule(xmlNode *rnode, struct acl_rule *rule) { CU_DEBUG("ACL mac rule %s", rnode->name); rule->type = MAC_RULE; rule->var.mac.protocol_id = get_attr_value(rnode, "protocolid"); rule->var.mac.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); rule->var.mac.srcmacmask = get_attr_value(rnode, "srcmacmask"); rule->var.mac.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); rule->var.mac.dstmacmask = get_attr_value(rnode, "dstmacmask"); rule->var.mac.comment = get_attr_value(rnode, "comment"); return 1; }
static int read_name(xmlNode *name_node, display_name_t **dst) { xmlAttr *a; const char *a_val; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (display_name_t*)cds_malloc(sizeof(display_name_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(display_name_t)); /* get attributes */ a = find_attr(name_node->properties, "lang"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->lang = zt_strdup(a_val); } a_val = get_node_value(name_node); if (a_val) (*dst)->name = zt_strdup(a_val); return 0; }
static int parse_acl_tcp_rule(xmlNode *rnode, struct acl_rule *rule) { CU_DEBUG("ACL tcp rule %s", rnode->name); rule->type = TCP_RULE; rule->var.tcp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); rule->var.tcp.srcipaddr = get_attr_value(rnode, "srcipaddr"); rule->var.tcp.srcipmask = get_attr_value(rnode, "srcipmask"); rule->var.tcp.dstipaddr = get_attr_value(rnode, "dstipaddr"); rule->var.tcp.dstipmask = get_attr_value(rnode, "dstipmask"); rule->var.tcp.srcipfrom = get_attr_value(rnode, "srcipfrom"); rule->var.tcp.srcipto = get_attr_value(rnode, "srcipto"); rule->var.tcp.dstipfrom = get_attr_value(rnode, "dstipfrom"); rule->var.tcp.dstipto = get_attr_value(rnode, "dstipto"); rule->var.tcp.srcportstart = get_attr_value(rnode, "srcportstart"); rule->var.tcp.srcportend = get_attr_value(rnode, "srcportend"); rule->var.tcp.dstportstart = get_attr_value(rnode, "dstportstart"); rule->var.tcp.dstportend = get_attr_value(rnode, "dstportend"); rule->var.tcp.comment = get_attr_value(rnode, "comment"); rule->var.tcp.state = get_attr_value(rnode, "state"); return 1; }
/** * Apply a potion. * @param op Object applying the potion. * @param tmp The potion. * @return 1 if the potion was successfully applied, 0 otherwise. */ int apply_potion(object *op, object *tmp) { int i; /* some sanity checks */ if (!op || !tmp || (op->type == PLAYER && (!CONTR(op) || !CONTR(op)->exp_ptr[EXP_MAGICAL] || !CONTR(op)->exp_ptr[EXP_WISDOM]))) { LOG(llevBug,"apply_potion() called with invalid objects! obj: %s (%s - %s) tmp:%s\n", query_name(op, NULL), CONTR(op) ? query_name(CONTR(op)->exp_ptr[EXP_MAGICAL], NULL) : "<no contr>", CONTR(op) ? query_name(CONTR(op)->exp_ptr[EXP_WISDOM], NULL) : "<no contr>", query_name(tmp, NULL)); return 0; } if (op->type == PLAYER) { /* set chosen_skill to "magic device" - thats used when we "use" a potion */ if (!change_skill(op, SK_USE_MAGIC_ITEM)) { /* no skill, no potion use (dust & balm too!) */ return 0; } if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED)) { identify(tmp); } /* special potions. Only players get this */ if (tmp->last_eat == -1) { /* create a force and copy the effects in */ object *force = get_archetype("force"); if (!force) { LOG(llevBug, "apply_potion: Can't create force object?\n"); return 0; } force->type = POTION_EFFECT; /* or it will auto destroy with first tick */ SET_FLAG(force, FLAG_IS_USED_UP); /* how long this force will stay */ force->stats.food += tmp->stats.food; if (force->stats.food <= 0) { force->stats.food = 1; } /* negative effects because cursed or damned */ if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { /* now we have a bit work because we change (multiply,...) the * base values of the potion - that can invoke out of bounce * values we must catch here. */ /* effects stays 3 times longer */ force->stats.food *= 3; for (i = 0; i < NROFATTACKS; i++) { int tmp_a; int tmp_p; tmp_a = tmp->attack[i] > 0 ? -tmp->attack[i] : tmp->attack[i]; tmp_p = tmp->protection[i] > 0 ? -tmp->protection[i] : tmp->protection[i]; /* double bad effect when damned */ if (QUERY_FLAG(tmp, FLAG_DAMNED)) { tmp_a *= 2; tmp_p *= 2; } /* we don't want out of bound values ... */ if ((int) force->protection[i] + tmp_p > 100) { force->protection[i] = 100; } else if ((int) force->protection[i] + tmp_p < -100) { force->protection[i] = -100; } else { force->protection[i] += (sint8) tmp_p; } if ((int) force->attack[i] + tmp_a > 100) { force->attack[i] = 100; } else if ((int) force->attack[i] + tmp_a < 0) { force->attack[i] = 0; } else { force->attack[i] += tmp_a; } } insert_spell_effect("meffect_purple", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "poison.ogg", op->x, op->y, 0, 0); } /* all positive (when not on default negative) */ else { /* we don't must do the hard way like cursed/damned (no multiplication or * sign change). */ memcpy(force->protection, tmp->protection, sizeof(tmp->protection)); memcpy(force->attack, tmp->attack, sizeof(tmp->attack)); insert_spell_effect("meffect_green", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "magic_default.ogg", op->x, op->y, 0, 0); } /* now copy stats values */ force->stats.Str = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Str > 0 ? -tmp->stats.Str : tmp->stats.Str) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Str > 0 ? (-tmp->stats.Str) * 2 : tmp->stats.Str * 2) : tmp->stats.Str); force->stats.Con = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Con > 0 ? -tmp->stats.Con : tmp->stats.Con) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Con > 0 ? (-tmp->stats.Con) * 2 : tmp->stats.Con * 2) : tmp->stats.Con); force->stats.Dex = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Dex > 0 ? -tmp->stats.Dex : tmp->stats.Dex) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Dex > 0 ? (-tmp->stats.Dex) * 2 : tmp->stats.Dex * 2) : tmp->stats.Dex); force->stats.Int = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Int > 0 ? -tmp->stats.Int : tmp->stats.Int) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Int > 0 ? (-tmp->stats.Int) * 2 : tmp->stats.Int * 2) : tmp->stats.Int); force->stats.Wis = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Wis > 0 ? -tmp->stats.Wis : tmp->stats.Wis) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Wis > 0 ? (-tmp->stats.Wis) * 2 : tmp->stats.Wis * 2) : tmp->stats.Wis); force->stats.Pow = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Pow > 0 ? -tmp->stats.Pow : tmp->stats.Pow) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Pow > 0 ? (-tmp->stats.Pow) * 2 : tmp->stats.Pow * 2) : tmp->stats.Pow); force->stats.Cha = QUERY_FLAG(tmp, FLAG_CURSED) ? (tmp->stats.Cha > 0 ? -tmp->stats.Cha : tmp->stats.Cha) : (QUERY_FLAG(tmp, FLAG_DAMNED) ? (tmp->stats.Cha > 0 ? (-tmp->stats.Cha) * 2 : tmp->stats.Cha * 2) : tmp->stats.Cha); /* kick the force in, and apply it to player */ force->speed_left = -1; force = insert_ob_in_ob(force, op); CLEAR_FLAG(tmp, FLAG_APPLIED); SET_FLAG(force, FLAG_APPLIED); /* implicit fix_player() here */ if (!change_abil(op, force)) { new_draw_info(NDI_UNIQUE, op, "Nothing happened."); } decrease_ob(tmp); return 1; } /* Potion of minor restoration */ if (tmp->last_eat == 1) { object *depl; archetype *at; if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { if (QUERY_FLAG(tmp, FLAG_DAMNED)) { drain_stat(op); drain_stat(op); drain_stat(op); drain_stat(op); } else { drain_stat(op); drain_stat(op); } fix_player(op); decrease_ob(tmp); insert_spell_effect("meffect_purple", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "poison.ogg", op->x, op->y, 0, 0); return 1; } if ((at = find_archetype("depletion")) == NULL) { LOG(llevBug, "BUG: Could not find archetype depletion."); return 0; } depl = present_arch_in_ob(at, op); if (depl != NULL) { for (i = 0; i < NUM_STATS; i++) { if (get_attr_value(&depl->stats, i)) { new_draw_info(NDI_UNIQUE, op, restore_msg[i]); } } /* in inventory of ... */ remove_ob(depl); fix_player(op); } else { new_draw_info(NDI_UNIQUE, op, "You feel a great loss..."); } decrease_ob(tmp); insert_spell_effect("meffect_green", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "magic_default.ogg", op->x, op->y, 0, 0); return 1; } /* improvement potion */ else if (tmp->last_eat == 2) { int success_flag = 0, hp_flag = 0, sp_flag = 0, grace_flag = 0; if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { /* jump in by random - goto power */ if (RANDOM() % 2) { goto hp_jump; } else if (RANDOM() % 2) { goto sp_jump; } else { goto grace_jump; } while (!hp_flag || !sp_flag || !grace_flag) { hp_jump: /* mark we have checked hp chain */ hp_flag = 1; for (i = 2; i <= op->level; i++) { /* move one value to max */ if (CONTR(op)->levhp[i] != 1) { CONTR(op)->levhp[i] = 1; success_flag = 2; goto improve_done; } } sp_jump: /* mark we have checked sp chain */ sp_flag = 1; for (i = 2; i <= CONTR(op)->exp_ptr[EXP_MAGICAL]->level; i++) { /* move one value to max */ if (CONTR(op)->levsp[i] != 1) { CONTR(op)->levsp[i] = 1; success_flag = 2; goto improve_done; } } grace_jump: /* mark we have checked grace chain */ grace_flag = 1; for (i = 2; i <= CONTR(op)->exp_ptr[EXP_WISDOM]->level; i++) { /* move one value to max */ if (CONTR(op)->levgrace[i] != 1) { CONTR(op)->levgrace[i] = 1; success_flag = 2; goto improve_done; } } } success_flag = 3; } else { /* jump in by random - goto power */ if (RANDOM() % 2) { goto hp_jump2; } else if (RANDOM() % 2) { goto sp_jump2; } else { goto grace_jump2; } while (!hp_flag || !sp_flag || !grace_flag) { hp_jump2: /* mark we have checked hp chain */ hp_flag = 1; for (i = 1; i <= op->level; i++) { /* move one value to max */ if (CONTR(op)->levhp[i] != (char) op->arch->clone.stats.maxhp) { CONTR(op)->levhp[i] = (char) op->arch->clone.stats.maxhp; success_flag = 1; goto improve_done; } } sp_jump2: /* mark we have checked sp chain */ sp_flag = 1; for (i = 1; i <= CONTR(op)->exp_ptr[EXP_MAGICAL]->level; i++) { /* move one value to max */ if (CONTR(op)->levsp[i] != (char) op->arch->clone.stats.maxsp) { CONTR(op)->levsp[i] = (char) op->arch->clone.stats.maxsp; success_flag = 1; goto improve_done; } } grace_jump2: /* mark we have checked grace chain */ grace_flag = 1; for (i = 1; i <= CONTR(op)->exp_ptr[EXP_WISDOM]->level; i++) { /* move one value to max */ if (CONTR(op)->levgrace[i] != (char) op->arch->clone.stats.maxgrace) { CONTR(op)->levgrace[i] = (char) op->arch->clone.stats.maxgrace; success_flag = 1; goto improve_done; } } } } improve_done: CLEAR_FLAG(tmp, FLAG_APPLIED); if (!success_flag) { new_draw_info(NDI_UNIQUE, op, "The potion had no effect - you are already perfect."); play_sound_map(op->map, CMD_SOUND_EFFECT, "magic_default.ogg", op->x, op->y, 0, 0); } else if (success_flag == 1) { fix_player(op); insert_spell_effect("meffect_yellow", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "magic_default.ogg", op->x, op->y, 0, 0); new_draw_info(NDI_UNIQUE, op, "You feel a little more perfect!"); } else if (success_flag == 2) { fix_player(op); insert_spell_effect("meffect_purple", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "poison.ogg", op->x, op->y, 0, 0); new_draw_info(NDI_UNIQUE, op, "The foul potion burns like fire in you!"); } /* bad potion but all values of this player are 1! poor poor guy.... */ else { insert_spell_effect("meffect_purple", op->map, op->x, op->y); play_sound_map(op->map, CMD_SOUND_EFFECT, "poison.ogg", op->x, op->y, 0, 0); new_draw_info(NDI_UNIQUE, op, "The potion was foul but had no effect on your tortured body."); } decrease_ob(tmp); return 1; } } if (tmp->stats.sp == SP_NO_SPELL) { new_draw_info(NDI_UNIQUE, op, "Nothing happens as you apply it."); decrease_ob(tmp); return 0; } /* A potion that casts a spell. Healing, restore spellpoint (power * potion) and heroism all fit into this category. */ if (tmp->stats.sp != SP_NO_SPELL) { /* apply potion fires in player's facing direction, unless the spell is SELF one, ie, healing or cure ilness. */ cast_spell(op, tmp, spells[tmp->stats.sp].flags & SPELL_DESC_SELF ? 0 : op->facing, tmp->stats.sp, 1, spellPotion, NULL); decrease_ob(tmp); /* if you're dead, no point in doing this... */ if (!QUERY_FLAG(op, FLAG_REMOVED)) { fix_player(op); } return 1; } /* CLEAR_FLAG is so that if the character has other potions * that were grouped with the one consumed, his * stat will not be raised by them. fix_player just clears * up all the stats. */ CLEAR_FLAG(tmp, FLAG_APPLIED); fix_player(op); decrease_ob(tmp); return 1; }
/** * If the player should die (lack of hp, food, etc), we call this. * * Will remove diseases, apply death penalties, and so on. * @param op The player in jeopardy. */ void kill_player(object *op) { char buf[HUGE_BUF]; int x, y, i; /* this is for resurrection */ mapstruct *map; object *tmp; int z; int num_stats_lose; int lost_a_stat; int lose_this_stat; int this_stat; if (pvp_area(NULL, op)) { new_draw_info(NDI_UNIQUE | NDI_NAVY, op, "You have been defeated in combat!"); new_draw_info(NDI_UNIQUE | NDI_NAVY, op, "Local medics have saved your life..."); /* Restore player */ cast_heal(op, MAXLEVEL, op, SP_CURE_POISON); /* Remove any disease */ cure_disease(op, NULL); op->stats.hp = op->stats.maxhp; if (op->stats.food <= 0) { op->stats.food = 999; } /* Create a bodypart-trophy to make the winner happy */ tmp = arch_to_object(find_archetype("finger")); if (tmp != NULL) { char race[MAX_BUF]; snprintf(buf, sizeof(buf), "%s's finger", op->name); FREE_AND_COPY_HASH(tmp->name, buf); snprintf(buf, sizeof(buf), "This finger has been cut off %s the %s, when %s was defeated at level %d by %s.", op->name, player_get_race_class(op, race, sizeof(race)), gender_subjective[object_get_gender(op)], op->level, CONTR(op)->killer[0] == '\0' ? "something nasty" : CONTR(op)->killer); FREE_AND_COPY_HASH(tmp->msg, buf); tmp->value = 0, tmp->material = 0, tmp->type = 0; tmp->x = op->x, tmp->y = op->y; insert_ob_in_map(tmp, op->map, op, 0); } /* Teleport defeated player to new destination */ transfer_ob(op, MAP_ENTER_X(op->map), MAP_ENTER_Y(op->map), 0, NULL, NULL); return; } if (save_life(op)) { return; } /* Trigger the DEATH event */ if (trigger_event(EVENT_DEATH, NULL, op, NULL, NULL, 0, 0, 0, SCRIPT_FIX_ALL)) { return; } /* Trigger the global GDEATH event */ trigger_global_event(EVENT_GDEATH, NULL, op); play_sound_player_only(CONTR(op), SOUND_PLAYER_DIES, SOUND_NORMAL, 0, 0); /* Save the map location for corpse, gravestone */ x = op->x; y = op->y; map = op->map; /* Basically two ways to go - remove a stat permanently, or just * make it depletion. This bunch of code deals with that aspect * of death. */ if (settings.balanced_stat_loss) { /* If stat loss is permanent, lose one stat only. */ /* Lower level chars don't lose as many stats because they suffer more if they do. */ if (settings.stat_loss_on_death) { num_stats_lose = 1; } else { num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; } } else { num_stats_lose = 1; } lost_a_stat = 0; /* Only decrease stats if you are level 3 or higher. */ for (z = 0; z < num_stats_lose; z++) { if (settings.stat_loss_on_death && op->level > 3) { /* Pick a random stat and take a point off it. Tell the * player what he lost. */ i = rndm(1, NUM_STATS) - 1; change_attr_value(&(op->stats), i, -1); check_stat_bounds(&(op->stats)); change_attr_value(&(CONTR(op)->orig_stats), i, -1); check_stat_bounds(&(CONTR(op)->orig_stats)); new_draw_info(NDI_UNIQUE, op, lose_msg[i]); lost_a_stat = 1; } else if (op->level > 3) { /* Deplete a stat */ archetype *deparch = find_archetype("depletion"); object *dep; i = rndm(1, NUM_STATS) - 1; dep = present_arch_in_ob(deparch, op); if (!dep) { dep = arch_to_object(deparch); insert_ob_in_ob(dep, op); } lose_this_stat = 1; if (settings.balanced_stat_loss) { /* Get the stat that we're about to deplete. */ this_stat = get_attr_value(&(dep->stats), i); if (this_stat < 0) { int loss_chance = 1 + op->level / BALSL_LOSS_CHANCE_RATIO; int keep_chance = this_stat * this_stat; /* Yes, I am paranoid. Sue me. */ if (keep_chance < 1) { keep_chance = 1; } /* There is a maximum depletion total per level. */ if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO) { lose_this_stat = 0; } else { /* Take loss chance vs keep chance to see if we retain the stat. */ if (rndm(0, loss_chance + keep_chance - 1) < keep_chance) { lose_this_stat = 0; } } } } if (lose_this_stat) { this_stat = get_attr_value(&(dep->stats), i); /* We could try to do something clever like find another * stat to reduce if this fails. But chances are, if * stats have been depleted to -50, all are pretty low * and should be roughly the same, so it shouldn't make a * difference. */ if (this_stat >= -50) { change_attr_value(&(dep->stats), i, -1); SET_FLAG(dep, FLAG_APPLIED); new_draw_info(NDI_UNIQUE, op, lose_msg[i]); fix_player(op); lost_a_stat = 1; } } } } /* If no stat lost, tell the player. */ if (!lost_a_stat) { const char *god = determine_god(op); if (god && god != shstr_cons.none) { new_draw_info_format(NDI_UNIQUE, op, "For a brief moment you feel the holy presence of %s protecting you.", god); } else { new_draw_info(NDI_UNIQUE, op, "For a brief moment you feel a holy presence protecting you."); } } /* Put a gravestone up where the character 'almost' died. */ tmp = arch_to_object(find_archetype("gravestone")); snprintf(buf, sizeof(buf), "%s's gravestone", op->name); FREE_AND_COPY_HASH(tmp->name, buf); FREE_AND_COPY_HASH(tmp->msg, gravestone_text(op)); tmp->x = op->x, tmp->y = op->y; insert_ob_in_map(tmp, op->map, NULL, 0); /* Subtract the experience points, if we died because of food give us * food, and reset HP... */ /* Remove any poisoning the character may be suffering. */ cast_heal(op, MAXLEVEL, op, SP_CURE_POISON); /* Remove any disease */ cure_disease(op, NULL); /* Apply death experience penalty. */ apply_death_exp_penalty(op); if (op->stats.food < 0) { op->stats.food = 900; } op->stats.hp = op->stats.maxhp; op->stats.sp = op->stats.maxsp; op->stats.grace = op->stats.maxgrace; hiscore_check(op, 1); /* Otherwise the highscore can get entries like 'xxx was killed by pudding * on map Wilderness' even if they were killed in a dungeon. */ CONTR(op)->killer[0] = '\0'; /* Check to see if the player is in a shop. Ii so, then check to see * if the player has any unpaid items. If so, remove them and put * them back in the map. */ tmp = get_map_ob(op->map, op->x, op->y); if (tmp && tmp->type == SHOP_FLOOR) { remove_unpaid_objects(op->inv, op); } /* Move player to his current respawn position (last savebed). */ enter_player_savebed(op); /* Show a nasty message */ new_draw_info(NDI_UNIQUE, op, "YOU HAVE DIED."); save_player(op, 1); return; }
void html_a( struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5 ) { int eax; int ecx; int edx; unsigned char *href; if ( get_attr_value( a, "href", html_context->doc_cp, HTML_ATTR_EAT_NL ) ) { unsigned char *target; if ( html_context->stack.list_head_elinks ) { mem_free( &html_context->stack.list_head_elinks ); } strlen( &href[0] ); if ( href[0] == ' ' ) { do { href[0] = href[1]; *(int*)(strlen( &href[0] ))--; } while ( href[0] == ' ' ); } if ( eax ) { if ( href[ eax - 1 ] == ' ' ) { do { *(char*)(edx - 1) = 0; if ( eax == 1 ) href[0] = href[0]; else } while ( *(char*)(edx - 2) != ' ' ); href[0] = href[0]; } eax += 0; memmove( &href[0], &href[0], 1 ); &html_context->stack.list_head_elinks = ((void)( struct css_stylesheet *, struct uri *, unsigned char *, int )*)join_urls( html_context->base_href, &href[0] ); mem_free( &href[0] ); if ( get_target( html_context->options, a ) ) { if ( html_context->stack.list_head_elinks ) { mem_free( &html_context->stack.list_head_elinks ); html_context->stack.next = html_context->stack.next; } &html_context->stack.list_head_elinks = &target[0]; } else { if ( html_context->stack.list_head_elinks ) { mem_free( &html_context->stack.list_head_elinks ); } &html_context->stack.list_head_elinks = ((void)( struct css_stylesheet *, struct uri *, unsigned char *, int )*)stracpy( html_context->base_target ); } if ( get_global_history_item( &html_context->stack.list_head_elinks ) ) { &html_context->stack.list_head_elinks = &html_context->stack.list_head_elinks; &html_context->stack.list_head_elinks &= -2; &html_context->stack.list_head_elinks |= 2; } else { &html_context->stack.list_head_elinks = html_context->stack.next ? &html_context->stack.list_head_elinks : &html_context->stack.list_head_elinks; &html_context->stack.list_head_elinks &= -3; &html_context->stack.list_head_elinks |= 1; } if ( html_context->stack.list_head_elinks ) { mem_free( &html_context->stack.list_head_elinks ); } &html_context->stack.list_head_elinks = ((void)( struct css_stylesheet *, struct uri *, unsigned char *, int )*)get_attr_value( a, "title", html_context->doc_cp, HTML_ATTR_NONE ); html_focusable( &html_context[0], a ); xxx3 = "name"; html_context = &html_context[0]; a = a; } memmove( &href[0], &href[0], 1 ); &html_context->stack.list_head_elinks = ((void)( struct css_stylesheet *, struct uri *, unsigned char *, int )*)join_urls( html_context->base_href, &href[0] ); mem_free( &href[0] ); } else
static char *get_job_condition(char *src, edg_wll_QueryRec *cond) { char *s; s = get_attr_name(src, tmps, 500); if ( tmps[0] == '\0' ) return NULL; if ( !strcmp(tmps, "jobid") ) cond->attr = EDG_WLL_QUERY_ATTR_JOBID; else if ( !strcmp(tmps, "owner") ) cond->attr = EDG_WLL_QUERY_ATTR_OWNER; else if ( !strcmp(tmps, "status") ) cond->attr = EDG_WLL_QUERY_ATTR_STATUS; else if ( !strcmp(tmps, "location") ) cond->attr = EDG_WLL_QUERY_ATTR_LOCATION; else if ( !strcmp(tmps, "destination") ) cond->attr = EDG_WLL_QUERY_ATTR_DESTINATION; else if ( !strcmp(tmps, "done_code") ) cond->attr = EDG_WLL_QUERY_ATTR_DONECODE; else if ( !strcmp(tmps, "exit_code") ) cond->attr = EDG_WLL_QUERY_ATTR_EXITCODE; else if ( !strcmp(tmps, "parent_job") ) cond->attr = EDG_WLL_QUERY_ATTR_PARENT; else if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME; else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME; else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; else if ( !strcmp(tmps, "job_type") ) cond->attr = EDG_WLL_QUERY_ATTR_JOB_TYPE; else if ( !strcmp(tmps, "vm_status") ) cond->attr = EDG_WLL_QUERY_ATTR_VM_STATUS; /**< When entered current status */ /**< Time of the last known event of the job */ /**< Network server aka RB aka WMproxy endpoint */ else { cond->attr = EDG_WLL_QUERY_ATTR_USERTAG; cond->attr_id.tag = strdup(tmps); } if ( !(s = get_op(s, &(cond->op))) ) return NULL; if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; switch ( cond->attr ) { case EDG_WLL_QUERY_ATTR_JOBID: case EDG_WLL_QUERY_ATTR_PARENT: if ( glite_jobid_parse(tmps, (glite_jobid_t *)&cond->value.j) ) { fprintf(stderr,"%s: %s: cannot parse jobId\n", myname, tmps); return NULL; } break; case EDG_WLL_QUERY_ATTR_OWNER: if ( !strcmp("NULL", tmps) ) cond->value.c = NULL; else if ( !(cond->value.c = strdup(tmps)) ) return 0; break; case EDG_WLL_QUERY_ATTR_LOCATION: case EDG_WLL_QUERY_ATTR_DESTINATION: case EDG_WLL_QUERY_ATTR_USERTAG: if ( !(cond->value.c = strdup(tmps)) ) return 0; break; case EDG_WLL_QUERY_ATTR_JDL_ATTR: if ( !(cond->value.c = strdup(tmps)) ) return 0; if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: you need to specify attribute name\n", myname); return NULL; } if ( !(cond->attr_id.tag = strdup(tmps)) ) return 0; break; case EDG_WLL_QUERY_ATTR_STATUS: if ( 0 > (cond->value.i = edg_wll_StringToStat(tmps))) { fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps); return 0; } break; case EDG_WLL_QUERY_ATTR_DONECODE: case EDG_WLL_QUERY_ATTR_EXITCODE: case EDG_WLL_QUERY_ATTR_RESUBMITTED: cond->value.i = atoi(tmps); if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) { if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: second interval boundary not set\n", myname); return NULL; } cond->value2.i = atoi(tmps); } break; case EDG_WLL_QUERY_ATTR_TIME: cond->value.t.tv_sec = StrToTime(tmps); if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) { if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: second interval boundary not set\n", myname); return NULL; } cond->value2.t.tv_sec = StrToTime(tmps); } if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: time condition must be associated with state condition\n", myname); return NULL; } if ( 0 > (cond->value.i = edg_wll_StringToStat(tmps))) { fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps); return 0; } break; case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: case EDG_WLL_QUERY_ATTR_STATEENTERTIME: cond->value.t.tv_sec = StrToTime(tmps); if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) { if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: second interval boundary not set\n", myname); return NULL; } cond->value2.t.tv_sec = StrToTime(tmps); } break; case EDG_WLL_QUERY_ATTR_JOB_TYPE: if ( 0 > (cond->value.i = edg_wll_JobtypeStrToCode(tmps))) { fprintf(stderr,"%s: invalid job type (%s)\n", myname, tmps); return 0; } break; case EDG_WLL_QUERY_ATTR_VM_STATUS: if ( 0 > (cond->value.i = edg_wll_StringToVMStat(tmps))) { fprintf(stderr,"%s: invalid VM status value (%s)\n", myname, tmps); return 0; } break; default: break; } while ( isblank(*s) || (*s == ';') ) s++; /* skip whitespaces */ return s; }
int read_list(xmlNode *list_node, list_t **dst, int read_content_only) { int res = 0; xmlAttr *a; const char *a_val; xmlNode *n; list_content_t *l, *last_l; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (list_t*)cds_malloc(sizeof(list_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(list_t)); /* get attributes */ if (!read_content_only) { a = find_attr(list_node->properties, "name"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->name = zt_strdup(a_val); } } /* read entries */ last_l = NULL; n = list_node->children; while (n) { if (n->type == XML_ELEMENT_NODE) { l = (list_content_t*) cds_malloc(sizeof(list_content_t)); if (!l) return -1; memset(l, 0, sizeof(*l)); if (cmp_node(n, "list", rl_namespace) >= 0) { res = read_list(n, &l->u.list, 0); if (res == 0) { if (l->u.list) { l->type = lct_list; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "entry", rl_namespace) >= 0) { res = read_entry(n, &l->u.entry); if (res == 0) { if (l->u.entry) { l->type = lct_entry; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "entry-ref", rl_namespace) >= 0) { res = read_entry_ref(n, &l->u.entry_ref); if (res == 0) { if (l->u.entry_ref) { l->type = lct_entry_ref; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (cmp_node(n, "external", rl_namespace) >= 0) { res = read_external(n, &l->u.external); if (res == 0) { if (l->u.external) { l->type = lct_external; SEQUENCE_ADD((*dst)->content, last_l, l); l = NULL; } } else break; } if (l) { cds_free(l); l = NULL; } } n = n->next; } return 0; }
static char *get_event_condition(char *src, edg_wll_QueryRec *cond) { char *s; s = get_attr_name(src, tmps, 500); if ( tmps[0] == '\0' ) return NULL; if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME; else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME; else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; else if ( !strcmp(tmps, "level") ) cond->attr = EDG_WLL_QUERY_ATTR_LEVEL; else if ( !strcmp(tmps, "host") ) cond->attr = EDG_WLL_QUERY_ATTR_HOST; else if ( !strcmp(tmps, "source") ) cond->attr = EDG_WLL_QUERY_ATTR_SOURCE; else if ( !strcmp(tmps, "instance") ) cond->attr = EDG_WLL_QUERY_ATTR_INSTANCE; else if ( !strcmp(tmps, "event_type") ) cond->attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; else { cond->attr = EDG_WLL_QUERY_ATTR_USERTAG; cond->attr_id.tag = strdup(tmps); } if ( !(s = get_op(s, &(cond->op))) ) return NULL; if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; switch ( cond->attr ) { case EDG_WLL_QUERY_ATTR_USERTAG: case EDG_WLL_QUERY_ATTR_HOST: case EDG_WLL_QUERY_ATTR_INSTANCE: case EDG_WLL_QUERY_ATTR_JDL_ATTR: if ( !(cond->value.c = strdup(tmps)) ) return 0; break; case EDG_WLL_QUERY_ATTR_SOURCE: if ( !strcasecmp(tmps, "UserInterface") ) cond->value.i = EDG_WLL_SOURCE_USER_INTERFACE; else if ( !strcasecmp(tmps, "NetworkServer") ) cond->value.i = EDG_WLL_SOURCE_NETWORK_SERVER; else if ( !strcasecmp(tmps, "WorkloadManager") ) cond->value.i = EDG_WLL_SOURCE_WORKLOAD_MANAGER; else if ( !strcasecmp(tmps, "BigHelper") ) cond->value.i = EDG_WLL_SOURCE_BIG_HELPER; else if ( !strcasecmp(tmps, "JobController") ) cond->value.i = EDG_WLL_SOURCE_JOB_SUBMISSION; else if ( !strcasecmp(tmps, "LogMonitor") ) cond->value.i = EDG_WLL_SOURCE_LOG_MONITOR; else if ( !strcasecmp(tmps, "LRMS") ) cond->value.i = EDG_WLL_SOURCE_LRMS; else if ( !strcasecmp(tmps, "Application") ) cond->value.i = EDG_WLL_SOURCE_APPLICATION; else { fprintf(stderr,"%s: invalid source value (%s)\n", myname, tmps); return NULL; } break; case EDG_WLL_QUERY_ATTR_EVENT_TYPE: case EDG_WLL_QUERY_ATTR_LEVEL: cond->value.i = atoi(tmps); if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) { if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: second interval boundary not set\n", myname); return NULL; } cond->value2.i = atoi(tmps); } break; case EDG_WLL_QUERY_ATTR_TIME: cond->value.t.tv_sec = StrToTime(tmps); if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) { if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; if ( tmps[0] == '\0' ) { fprintf(stderr,"%s: second interval boundary not set\n", myname); return NULL; } cond->value2.t.tv_sec = StrToTime(tmps); } break; default: break; } while ( isblank(*s) || (*s == ';') ) s++; /* skip whitespaces */ return s; }
static int parse_acl_rule(xmlNode *rnode, struct acl_rule *rule) { xmlNode *child = NULL; memset(rule, 0, sizeof(*rule)); rule->action = get_attr_value(rnode, "action"); if (rule->action == NULL) goto err; rule->direction = get_attr_value(rnode, "direction"); if (rule->direction == NULL) goto err; rule->priority = get_attr_value(rnode, "priority"); rule->statematch = get_attr_value(rnode, "statematch"); for (child = rnode->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "mac")) { rule->protocol_id = strdup((char *)child->name); parse_acl_mac_rule(child, rule); } else if (XSTREQ(child->name, "arp") || XSTREQ(child->name, "rarp")) { rule->protocol_id = strdup((char *)child->name); parse_acl_arp_rule(child, rule); } else if (XSTREQ(child->name, "ip") || XSTREQ(child->name, "ipv6")) { rule->protocol_id = strdup((char *)child->name); parse_acl_ip_rule(child, rule); } else if (XSTREQ(child->name, "tcp") || XSTREQ(child->name, "tcp-ipv6") || XSTREQ(child->name, "udp") || XSTREQ(child->name, "udp-ipv6") || XSTREQ(child->name, "sctp") || XSTREQ(child->name, "sctp-ipv6")) { rule->protocol_id = strdup((char *)child->name); parse_acl_tcp_rule(child, rule); } else if (XSTREQ(child->name, "icmp") || XSTREQ(child->name, "icmpv6") || XSTREQ(child->name, "igmp") || XSTREQ(child->name, "igmp-ipv6") || XSTREQ(child->name, "esp") || XSTREQ(child->name, "esp-ipv6") || XSTREQ(child->name, "ah") || XSTREQ(child->name, "ah-ipv6") || XSTREQ(child->name, "udplite") || XSTREQ(child->name, "udplite-ipv6") || XSTREQ(child->name, "all") || XSTREQ(child->name, "all-ipv6")) { rule->protocol_id = strdup((char *)child->name); parse_acl_icmp_igmp_rule(child, rule); } } return 1; err: cleanup_rule(rule); return 0; }
static int parse_acl_icmp_igmp_rule(xmlNode *rnode, struct acl_rule *rule) { CU_DEBUG("ACL %s rule %s", rule->protocol_id, rnode->name); rule->type = ICMP_IGMP_RULE; rule->var.icmp_igmp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); rule->var.icmp_igmp.srcmacmask = get_attr_value(rnode, "srcmacmask"); rule->var.icmp_igmp.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); rule->var.icmp_igmp.dstmacmask = get_attr_value(rnode, "dstmacmask"); rule->var.icmp_igmp.srcipaddr = get_attr_value(rnode, "srcipaddr"); rule->var.icmp_igmp.srcipmask = get_attr_value(rnode, "srcipmask"); rule->var.icmp_igmp.dstipaddr = get_attr_value(rnode, "dstipaddr"); rule->var.icmp_igmp.dstipmask = get_attr_value(rnode, "dstipmask"); rule->var.icmp_igmp.srcipfrom = get_attr_value(rnode, "srcipfrom"); rule->var.icmp_igmp.srcipto = get_attr_value(rnode, "srcipto"); rule->var.icmp_igmp.dstipfrom = get_attr_value(rnode, "dstipfrom"); rule->var.icmp_igmp.dstipto = get_attr_value(rnode, "dstipto"); rule->var.icmp_igmp.comment = get_attr_value(rnode, "comment"); rule->var.icmp_igmp.state = get_attr_value(rnode, "state"); return 1; }
int ads_has_subscription(Env E, char *sub, char *id) { LDAP *ld = E->ldap; LDAPMessage *result, *e; char *regid = NULL; int i; int nv = 0; char filter[2048]; char *dn = NULL; int rc; int try; int ret = 0; /* Look for the account record */ snprintf(filter, 2048, "(&(uwNetID=%s)(uwActiveSubscription=%s))", id, sub); // syslog(LOG_DEBUG, "search: \"%s\"\n", filter); // long delays can disconnect us for (try=0; try<2; try++) { if (!(ld||(ld=ads_init(E)))) { syslog(LOG_ERR, "no ldap, cannot verify!"); return (-1); } if ((rc=ldap_search_s(ld, E->ads_base, LDAP_SCOPE_SUBTREE, filter, ads_attributes, 0, &result )) != LDAP_SUCCESS ) { if (try>0) report_error(rc, "ldap_search_s" ); ldap_msgfree( result ); ld = NULL; continue; } break; // success } if (try==2) { syslog(LOG_ERR, "no ldap, cannot verify!"); return (-1); } if (ldap_count_entries(ld, result)>0) { // this is not necessary e = ldap_first_entry( ld, result ); char *nid = get_attr_value(ld, e, "uwNetID"); syslog(LOG_DEBUG, "found: \"%s\"\n", nid); free(nid); ret = 1; } else { syslog(LOG_DEBUG, "not found"); } ldap_msgfree( result ); return (ret); } /* ----- connect and disconnect -------------------------- */ #ifdef LDAP_DEBUG static void set_ldap_debug() { if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &tegea_debug ) != LBER_OPT_SUCCESS ) { fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", tegea_debug ); } if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &tegea_debug ) != LDAP_OPT_SUCCESS ) { fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", tegea_debug ); } } #endif /* Callback from the sasl bind */ static int tsasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in) { sasl_interact_t *interact = in; /* Should loop through, ++interact, for full SASL stuff. */ if (interact->id != SASL_CB_LIST_END) { interact->result = (char *) interact->defresult; if (interact->defresult) interact->len = strlen(interact->defresult); else interact->len = 0; } return LDAP_SUCCESS; } static int set_int_option(LDAP *ld, int option, int iv) { int rc; if ( (rc=ldap_set_option( NULL, option, &iv )) != LDAP_SUCCESS ) { report_error(rc, "set int opt"); return (0); } return (1); }
static int parse_acl_ip_rule(xmlNode *rnode, struct acl_rule *rule) { CU_DEBUG("ACP ip rule %s", rnode->name); rule->type = IP_RULE; rule->var.ip.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); rule->var.ip.srcmacmask = get_attr_value(rnode, "srcmacmask"); rule->var.ip.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); rule->var.ip.dstmacmask = get_attr_value(rnode, "dstmacmaks"); rule->var.ip.srcipaddr = get_attr_value(rnode, "srcipaddr"); rule->var.ip.srcipmask = get_attr_value(rnode, "srcipmask"); rule->var.ip.dstipaddr = get_attr_value(rnode, "dstipaddr"); rule->var.ip.dstipmask = get_attr_value(rnode, "dstipmask"); rule->var.ip.protocol = get_attr_value(rnode, "protocol"); rule->var.ip.srcportstart = get_attr_value(rnode, "srcportstart"); rule->var.ip.srcportend = get_attr_value(rnode, "srcportend"); rule->var.ip.dstportstart = get_attr_value(rnode, "dstportstart"); rule->var.ip.dstportend = get_attr_value(rnode, "dstportend"); rule->var.ip.comment = get_attr_value(rnode, "comment"); return 1; }
static int parse_acl_arp_rule(xmlNode *rnode, struct acl_rule *rule) { CU_DEBUG("ACL arp rule %s", rnode->name); rule->type = ARP_RULE; rule->var.arp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); rule->var.arp.srcmacmask = get_attr_value(rnode, "srcmacmask"); rule->var.arp.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); rule->var.arp.dstmacmask = get_attr_value(rnode, "dstmacmask"); rule->var.arp.hw_type = get_attr_value(rnode, "hwtype"); rule->var.arp.protocol_type = get_attr_value(rnode, "protocoltype"); rule->var.arp.opcode = get_attr_value(rnode, "opcode"); rule->var.arp.arpsrcmacaddr = get_attr_value(rnode, "arpsrcmacaddr"); rule->var.arp.arpdstmacaddr = get_attr_value(rnode, "arpdstmacaddr"); rule->var.arp.arpsrcipaddr = get_attr_value(rnode, "arpsrcipaddr"); rule->var.arp.arpdstipaddr = get_attr_value(rnode, "arpdstipaddr"); rule->var.arp.comment = get_attr_value(rnode, "comment"); return 1; }