?? parse-resource.c
字號:
#include <string.h>#include <glib.h>#include "bionet.h"#include "libbionet-internal.h"#include "bionet-util.h"bionet_resource_t *libbionet_parse_resource(xmlNode *x) { // these are optional char *hab_type=NULL, *hab_id=NULL, *node_id=NULL; // these are required char *resource_id=NULL, *flavor=NULL, *type=NULL, *value=NULL, *time=NULL; bionet_resource_t *resource = NULL; if (x->type != XML_ELEMENT_NODE) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "invalid XML element type passed to libbionet_parse_resource()"); return NULL; } if (strcmp(x->name, "resource") != 0) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "non-<resource> XML element passed to libbionet_parse_resource()"); return NULL; } // these can be NULL so we dont have to check them hab_type = xmlGetProp(x, "hab-type"); hab_id = xmlGetProp(x, "hab-id"); node_id = xmlGetProp(x, "node-id"); resource_id = xmlGetProp(x, "id"); if (resource_id == NULL) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Resource-ID"); goto cleanup; } type = xmlGetProp(x, "type"); if (type == NULL) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Type"); goto cleanup; } flavor = xmlGetProp(x, "flavor"); if (flavor == NULL) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Flavor"); goto cleanup; } value = xmlGetProp(x, "value"); if (value == NULL) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Value"); goto cleanup; } time = xmlGetProp(x, "time"); if (time == NULL) { g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "got <resource> with no Time"); goto cleanup; } resource = bionet_resource_new_with_valuestr_timestr( hab_type, hab_id, node_id, type, flavor, resource_id, value, time );cleanup: if (hab_type != NULL) xmlFree(hab_type); if (hab_id != NULL) xmlFree(hab_id); if (node_id != NULL) xmlFree(node_id); if (resource_id != NULL) xmlFree(resource_id); if (flavor != NULL) xmlFree(flavor); if (type != NULL) xmlFree(type); if (value != NULL) xmlFree(value); if (time != NULL) xmlFree(time); return resource;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -