static void warn_arguments(const attribute_t *attribute) { if (attribute->a.arguments == NULL) return; position_t const *const pos = &attribute->pos; char const *const what = get_attribute_name(attribute->kind); warningf(WARN_OTHER, pos, "attribute '%s' needs no arguments", what); }
QHash<QString,QString> GumboInterface::get_attributes_of_node(GumboNode* node) { QHash<QString,QString> node_atts; if (node->type != GUMBO_NODE_ELEMENT) { return node_atts; } const GumboVector * attribs = &node->v.element.attributes; for (unsigned int i=0; i< attribs->length; ++i) { GumboAttribute* attr = static_cast<GumboAttribute*>(attribs->data[i]); QString key = QString::fromStdString(get_attribute_name(attr)); QString val = QString::fromUtf8(attr->value); node_atts[key] = val; } return node_atts; }
std::string GumboInterface::build_attributes(GumboAttribute * at, bool no_entities, bool run_src_updates, bool run_style_updates) { std::string atts = " "; std::string name = get_attribute_name(at); std::string local_name = at->name; atts.append(name); std::string attvalue = at->value; if (run_src_updates && (local_name == aHREF || local_name == aSRC || local_name == aPOSTER || local_name == aDATA)) { attvalue = update_attribute_value(attvalue); } if (run_style_updates && (local_name == "style")) { attvalue = update_style_urls(attvalue); } // we handle empty attribute values like so: alt="" char quote = '"'; std::string qs="\""; // verify an original value existed since we create our own attributes // and if so determine the original quote character used if any if (at->original_value.data) { if ( (!attvalue.empty()) || (at->original_value.data[0] == '"') || (at->original_value.data[0] == '\'') ) { quote = at->original_value.data[0]; if (quote == '\'') qs = std::string("'"); if (quote == '"') qs = std::string("\""); } } atts.append("="); atts.append(qs); if (no_entities) { atts.append(attvalue); } else { atts.append(substitute_xml_entities_into_attributes(quote, attvalue)); } atts.append(qs); return atts; }
std::string GumboInterface::build_attributes(GumboAttribute * at, bool no_entities, bool runupdates) { std::string atts = " "; std::string name = get_attribute_name(at); std::string local_name = at->name; atts.append(name); std::string attvalue = at->value; if (runupdates && (local_name == HREF || local_name == SRC)) { attvalue = update_attribute_value(attvalue); } // we handle empty attribute values like so: alt="" char quote = '"'; std::string qs="\""; if ( (!attvalue.empty()) || (at->original_value.data[0] == '"') || (at->original_value.data[0] == '\'') ) { // determine original quote character used if it exists quote = at->original_value.data[0]; if (quote == '\'') qs = std::string("'"); if (quote == '"') qs = std::string("\""); } atts.append("="); atts.append(qs); if (no_entities) { atts.append(attvalue); } else { atts.append(substitute_xml_entities_into_attributes(quote, attvalue)); } atts.append(qs); return atts; }
tree decl_attributes (tree *node, tree attributes, int flags) { tree a; tree returned_attrs = NULL_TREE; if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node) return NULL_TREE; if (!attributes_initialized) init_attributes (); /* If this is a function and the user used #pragma GCC optimize, add the options to the attribute((optimize(...))) list. */ if (TREE_CODE (*node) == FUNCTION_DECL && current_optimize_pragma) { tree cur_attr = lookup_attribute ("optimize", attributes); tree opts = copy_list (current_optimize_pragma); if (! cur_attr) attributes = tree_cons (get_identifier ("optimize"), opts, attributes); else TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr)); } if (TREE_CODE (*node) == FUNCTION_DECL && optimization_current_node != optimization_default_node && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)) DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node; /* If this is a function and the user used #pragma GCC target, add the options to the attribute((target(...))) list. */ if (TREE_CODE (*node) == FUNCTION_DECL && current_target_pragma && targetm.target_option.valid_attribute_p (*node, NULL_TREE, current_target_pragma, 0)) { tree cur_attr = lookup_attribute ("target", attributes); tree opts = copy_list (current_target_pragma); if (! cur_attr) attributes = tree_cons (get_identifier ("target"), opts, attributes); else TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr)); } /* A "naked" function attribute implies "noinline" and "noclone" for those targets that support it. */ if (TREE_CODE (*node) == FUNCTION_DECL && attributes && lookup_attribute_spec (get_identifier ("naked")) && lookup_attribute ("naked", attributes) != NULL) { if (lookup_attribute ("noinline", attributes) == NULL) attributes = tree_cons (get_identifier ("noinline"), NULL, attributes); if (lookup_attribute ("noclone", attributes) == NULL) attributes = tree_cons (get_identifier ("noclone"), NULL, attributes); } targetm.insert_attributes (*node, &attributes); for (a = attributes; a; a = TREE_CHAIN (a)) { tree ns = get_attribute_namespace (a); tree name = get_attribute_name (a); tree args = TREE_VALUE (a); tree *anode = node; const struct attribute_spec *spec = lookup_scoped_attribute_spec (ns, name); bool no_add_attrs = 0; int fn_ptr_quals = 0; tree fn_ptr_tmp = NULL_TREE; if (spec == NULL) { if (!(flags & (int) ATTR_FLAG_BUILT_IN)) { if (ns == NULL_TREE || !cxx11_attribute_p (a)) warning (OPT_Wattributes, "%qE attribute directive ignored", name); else warning (OPT_Wattributes, "%<%E::%E%> scoped attribute directive ignored", ns, name); } continue; } else if (list_length (args) < spec->min_length || (spec->max_length >= 0 && list_length (args) > spec->max_length)) { error ("wrong number of arguments specified for %qE attribute", name); continue; } gcc_assert (is_attribute_p (spec->name, name)); if (TYPE_P (*node) && cxx11_attribute_p (a) && !(flags & ATTR_FLAG_TYPE_IN_PLACE)) { /* This is a c++11 attribute that appertains to a type-specifier, outside of the definition of, a class type. Ignore it. */ warning (OPT_Wattributes, "attribute ignored"); inform (input_location, "an attribute that appertains to a type-specifier " "is ignored"); continue; } if (spec->decl_required && !DECL_P (*anode)) { if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT | (int) ATTR_FLAG_ARRAY_NEXT)) { /* Pass on this attribute to be tried again. */ returned_attrs = tree_cons (name, args, returned_attrs); continue; } else { warning (OPT_Wattributes, "%qE attribute does not apply to types", name); continue; } } /* If we require a type, but were passed a decl, set up to make a new type and update the one in the decl. ATTR_FLAG_TYPE_IN_PLACE would have applied if we'd been passed a type, but we cannot modify the decl's type in place here. */ if (spec->type_required && DECL_P (*anode)) { anode = &TREE_TYPE (*anode); flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE; } if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE && TREE_CODE (*anode) != METHOD_TYPE) { if (TREE_CODE (*anode) == POINTER_TYPE && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE)) { /* OK, this is a bit convoluted. We can't just make a copy of the pointer type and modify its TREE_TYPE, because if we change the attributes of the target type the pointer type needs to have a different TYPE_MAIN_VARIANT. So we pull out the target type now, frob it as appropriate, and rebuild the pointer type later. This would all be simpler if attributes were part of the declarator, grumble grumble. */ fn_ptr_tmp = TREE_TYPE (*anode); fn_ptr_quals = TYPE_QUALS (*anode); anode = &fn_ptr_tmp; flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE; } else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT) { /* Pass on this attribute to be tried again. */ returned_attrs = tree_cons (name, args, returned_attrs); continue; } if (TREE_CODE (*anode) != FUNCTION_TYPE && TREE_CODE (*anode) != METHOD_TYPE) { warning (OPT_Wattributes, "%qE attribute only applies to function types", name); continue; } } if (TYPE_P (*anode) && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE) && TYPE_SIZE (*anode) != NULL_TREE) { warning (OPT_Wattributes, "type attributes ignored after type is already defined"); continue; } if (spec->handler != NULL) { int cxx11_flag = cxx11_attribute_p (a) ? ATTR_FLAG_CXX11 : 0; returned_attrs = chainon ((*spec->handler) (anode, name, args, flags|cxx11_flag, &no_add_attrs), returned_attrs); } /* Layout the decl in case anything changed. */ if (spec->type_required && DECL_P (*node) && (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == PARM_DECL || TREE_CODE (*node) == RESULT_DECL)) relayout_decl (*node); if (!no_add_attrs) { tree old_attrs; tree a; if (DECL_P (*anode)) old_attrs = DECL_ATTRIBUTES (*anode); else old_attrs = TYPE_ATTRIBUTES (*anode); for (a = lookup_attribute (spec->name, old_attrs); a != NULL_TREE; a = lookup_attribute (spec->name, TREE_CHAIN (a))) { if (simple_cst_equal (TREE_VALUE (a), args) == 1) break; } if (a == NULL_TREE) { /* This attribute isn't already in the list. */ if (DECL_P (*anode)) DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs); else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE) { TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs); /* If this is the main variant, also push the attributes out to the other variants. */ if (*anode == TYPE_MAIN_VARIANT (*anode)) { tree variant; for (variant = *anode; variant; variant = TYPE_NEXT_VARIANT (variant)) { if (TYPE_ATTRIBUTES (variant) == old_attrs) TYPE_ATTRIBUTES (variant) = TYPE_ATTRIBUTES (*anode); else if (!lookup_attribute (spec->name, TYPE_ATTRIBUTES (variant))) TYPE_ATTRIBUTES (variant) = tree_cons (name, args, TYPE_ATTRIBUTES (variant)); } } } else *anode = build_type_attribute_variant (*anode, tree_cons (name, args, old_attrs)); } } if (fn_ptr_tmp) { /* Rebuild the function pointer type and put it in the appropriate place. */ fn_ptr_tmp = build_pointer_type (fn_ptr_tmp); if (fn_ptr_quals) fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals); if (DECL_P (*node)) TREE_TYPE (*node) = fn_ptr_tmp; else { gcc_assert (TREE_CODE (*node) == POINTER_TYPE); *node = fn_ptr_tmp; } } } return returned_attrs; }
static void process_radius(uint8_t *payload, uint32_t remaining) { radius_t *radius = (void*)payload; if (remaining < sizeof(radius_t)) { printf("Runt packet\n"); return; } if (ntohs(radius->length) > remaining) { printf("Runt packet\n"); return; } if (ntohs(radius->length) != remaining) { printf("Packet too big, truncating to %d bytes\n", ntohs(radius->length)); remaining = radius->length; } printf("Code: %d", radius->code); if (radius->code < sizeof(radius_code_name) / sizeof(radius_code_name[0])) { printf(" (%s)\n", radius_code_name[radius->code]); } else printf("\n"); printf("Identifier: %d\n", radius->identifier); printf("Length: %d\n", radius->length); printf("Authenticator:"); for(int i=0; i<sizeof(radius->authenticator); ++i) { printf(" %02x", radius->authenticator[i]); } printf("\n"); uint8_t *data = payload + sizeof(radius_t); remaining -= sizeof(radius_t); uint8_t *eap = NULL; size_t eaplen = 0; while (remaining > 2) { uint8_t type = data[0]; uint8_t length = data[1]; printf("Attribute %d", type); if (get_attribute_name(type)) printf(" [%s]", get_attribute_name(type)); printf(" (%d bytes): ", length); if (length < 2) { printf("Invalid length\n"); return; } if (remaining < length) { printf("TRUNCATED\n"); break; } data += 2; remaining -= 2; dump_bytes(data, length-2); switch (type) { case 79: /* EAP Message */ eap = realloc(eap, eaplen + length); memcpy(&eap[eaplen], data, length); eaplen += length; } data += (length-2); remaining -= (length-2); printf("\n"); } if (remaining != 0) printf("Data left over?\n"); if (eap) { decode_eap(eap, eaplen); } printf("\n"); }