예제 #1
0
파일: oids.c 프로젝트: vanviegen/wireshark
static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_type_t* type, oid_key_t* key, guint oid_len, guint32 *subids) {
	guint i = 0;
	oid_info_t* c = &oid_root;

	if (!oid_root.children) {
		char* debug_env = getenv("WIRESHARK_DEBUG_MIBS");
		guint32 subid;

		debuglevel = debug_env ? strtoul(debug_env,NULL,10) : 0;

		oid_root.children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_root");

		/*
		 * make sure we got strings at least in the three root-children oids
		 * that way oid_resolved() will always have a string to print
		 */
		subid = 0; oid_add("itu-t",1,&subid);
		subid = 1; oid_add("iso",1,&subid);
		subid = 2; oid_add("joint-iso-itu-t",1,&subid);
	}

	oid_len--;

	do {
		oid_info_t* n = emem_tree_lookup32(c->children,subids[i]);

		if(n) {
			if (i == oid_len) {
				if (n->name) {
					if (!g_str_equal(n->name,name)) {
						D(2,("Renaming Oid from: %s -> %s, this means the same oid is registered more than once",n->name,name));
					}
					/* There used to be a comment here that claimed we couldn't free
					 * n->name since it may be part of an hf_register_info struct
                                         * that has been appended to the hfa GArray. I think that comment
					 * was wrong, because we only ever create oid_info_t's in this
					 * function, and we are always careful here to g_strdup the name.
					 * All that to justify freeing n->name in the next line, since
					 * doing so fixes some memory leaks. */
					g_free(n->name);
				}

				n->name = g_strdup(name);

				if (! n->value_type) {
					n->value_type = type;
				}

				return n;
			}
		} else {
			n = g_malloc(sizeof(oid_info_t));
			n->subid = subids[i];
			n->kind = kind;
			n->children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_children");
			n->value_hfid = -2;
			n->key = key;
			n->parent = c;
			n->bits = NULL;

			emem_tree_insert32(c->children,n->subid,n);

			if (i == oid_len) {
				n->name = g_strdup(name);
				n->value_type = type;
				n->kind = kind;
				return n;
			} else {
				n->name = NULL;
				n->value_type = NULL;
				n->kind = OID_KIND_UNKNOWN;
			}
		}
		c = n;
	} while(++i);

	g_assert_not_reached();
	return NULL;
}
예제 #2
0
파일: oids.c 프로젝트: flaub/HotFuzz
static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_type_t* type, oid_key_t* key, guint oid_len, guint32 *subids) {
	guint i = 0;
	oid_info_t* c = &oid_root;

	if (!oid_root.children) {
		char* debug_env = getenv("WIRESHARK_DEBUG_MIBS");
		guint32 subid;

		debuglevel = debug_env ? strtoul(debug_env,NULL,10) : 0;

		oid_root.children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_root");

		/*
		 * make sure we got strings at least in the three root-children oids
		 * that way oid_resolved() will always have a string to print
		 */
		subid = 0; oid_add("itu-t",1,&subid);
		subid = 1; oid_add("iso",1,&subid);
		subid = 2; oid_add("joint-iso-itu-t",1,&subid);
	}

	oid_len--;

	do {
		oid_info_t* n = emem_tree_lookup32(c->children,subids[i]);

		if(n) {
			if (i == oid_len) {
				if (n->name) {
					if (!g_str_equal(n->name,name)) {
						D(2,("Renaming Oid from: %s -> %s, this means the same oid is registered more than once",n->name,name));
					}
					/* XXX - Don't free n->name here. It may be part of an hf_register_info
                                         * struct that has been appended to the hfa GArray. */
				}

				n->name = g_strdup(name);

				if (! n->value_type) {
					n->value_type = type;
				}

				return n;
			}
		} else {
			n = g_malloc(sizeof(oid_info_t));
			n->subid = subids[i];
			n->kind = kind;
			n->children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_children");
			n->value_hfid = -2;
			n->key = key;
			n->parent = c;
			n->bits = NULL;

			emem_tree_insert32(c->children,n->subid,n);

			if (i == oid_len) {
				n->name = g_strdup(name);
				n->value_type = type;
				n->kind = kind;
				return n;
			} else {
				n->name = NULL;
				n->value_type = NULL;
				n->kind = OID_KIND_UNKNOWN;
			}
		}
		c = n;
	} while(++i);

	g_assert_not_reached();
	return NULL;
}