int SongMetaData_parse_DIDL(struct SongMetaData *object, const char *xml) { struct xmldoc *doc = xmldoc_parsexml(xml); if (doc == NULL) return 0; // ... did I mention that I hate navigating XML documents ? struct xmlelement *didl_node = find_element_in_doc(doc, "DIDL-Lite"); if (didl_node == NULL) return 0; struct xmlelement *item_node = find_element_in_element(didl_node, "item"); if (item_node == NULL) return 0; struct xmlelement *value_node = NULL; value_node = find_element_in_element(item_node, "dc:title"); if (value_node) object->title = get_node_value(value_node); value_node = find_element_in_element(item_node, "upnp:artist"); if (value_node) object->artist = get_node_value(value_node); value_node = find_element_in_element(item_node, "upnp:album"); if (value_node) object->album = get_node_value(value_node); value_node = find_element_in_element(item_node, "upnp:genre"); if (value_node) object->genre = get_node_value(value_node); xmldoc_free(doc); return 1; }
void csSCF::RegisterClassesInt(char const* pluginPath, iDocumentNode* scfnode, const char* context) { bool const seen = pluginPath != 0 && libraryNames->Contains(pluginPath); if (IsVerbose(SCF_VERBOSE_PLUGIN_REGISTER)) { char const* s = pluginPath != 0 ? pluginPath : "{unknown}"; char const* c = GetContextName(context); if (!seen) csPrintfErr("SCF_NOTIFY: registering plugin %s in context `%s'\n", s, c); else csPrintfErr("SCF_NOTIFY: ignoring duplicate plugin registration %s " "in context `%s'\n", s, c); } if (seen) return; // *** RETURN: Do not re-register *** csRef<iDocumentNode> classesnode = scfnode->GetNode("classes"); if (classesnode) { csRef<iDocumentNodeIterator> classiter = classesnode->GetNodes("class"); csRef<iDocumentNode> classnode; while ((classnode = classiter->Next())) { csString classname = get_node_value(classnode, "name"); csString imp = get_node_value(classnode, "implementation"); csString desc = get_node_value(classnode, "description"); // For backward compatibility, we build a comma-delimited dependency // string from the individual dependency nodes. In the future, // iSCF::GetClassDependencies() should be updated to return an // iStringArray, rather than a simple comma-delimited string. csString depend; csRef<iDocumentNode> depnode = classnode->GetNode("requires"); if (depnode) { csRef<iDocumentNodeIterator> depiter = depnode->GetNodes("class"); csRef<iDocumentNode> depclassnode; while ((depclassnode = depiter->Next())) { if (!depend.IsEmpty()) depend << ", "; depend << depclassnode->GetContentsValue(); } } char const* pdepend = (depend.IsEmpty() ? 0 : depend.GetData()); RegisterClass(classname, pluginPath, imp, desc, pdepend, context); } } }
static int read_validity(xmlNode *n, cp_validity_t **dst) { const char *from, *to; *dst = (cp_validity_t*)cds_malloc(sizeof(cp_validity_t)); if (!(*dst)) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(**dst)); from = get_node_value(find_node(n, "from", common_policy_ns)); to = get_node_value(find_node(n, "to", common_policy_ns)); (*dst)->from = xmltime2time(from); (*dst)->to = xmltime2time(to); return RES_OK; }
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 read_sphere(xmlNode *n, cp_sphere_t **dst) { *dst = (cp_sphere_t*)cds_malloc(sizeof(cp_sphere_t)); if (!(*dst)) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(**dst)); (*dst)->next = NULL; str_dup_zt(&(*dst)->value, get_node_value(n)); return RES_OK; }
char * output_get_grouprole(void) { char *grouprole = NULL; struct xmldoc *doc = xmldoc_fromdoc(RENDERXML); if(doc){ struct xmlelement *render_node = find_element_in_doc(doc, "Gmediarender"); struct xmlelement *group_node = find_element_in_element(render_node, "Group"); struct xmlelement *value_node = find_element_in_element(group_node, "GroupRole"); grouprole = get_node_value(value_node); xmldoc_free(doc); } return grouprole; }
static int read_package(xmlNode *n, package_t **dst) { const char *name; if (!dst) return -1; *dst = (package_t*)cds_malloc(sizeof(package_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(package_t)); name = get_node_value(n); if (name) (*dst)->name = zt_strdup(name); return 0; }
static int read_id(xmlNode *n, cp_id_t **dst) { *dst = (cp_id_t*)cds_malloc(sizeof(cp_id_t)); if (!(*dst)) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(**dst)); (*dst)->next = NULL; get_str_attr(n, "entity", &(*dst)->entity); if ((*dst)->entity.len == 0) { /* hack - eyeBeams format differs from draft ! */ str_dup_zt(&(*dst)->entity, get_node_value(n)); } return RES_OK; }
static int read_msg_actions(xmlNode *an, cp_actions_t **dst) { xmlNode *n; const char *s; int res = RES_OK; if ((!an) || (!dst)) return RES_INTERNAL_ERR; *dst = (cp_actions_t*)cds_malloc(sizeof(cp_actions_t)); if (!(*dst)) return RES_MEMORY_ERR; memset(*dst, 0, sizeof(cp_actions_t)); n = find_node(an, "im-handling", msg_rules_ns); if (n) { /* may be only one sub-handling node? */ s = get_node_value(n); (*dst)->unknown = create_unknown(sizeof(msg_handling_t)); if (!(*dst)->unknown) return RES_MEMORY_ERR; res = str2msg_handling(s, (msg_handling_t*)(*dst)->unknown->data); } return res; }
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; }
DomString DomCharacterData::substring_data(unsigned long offset, unsigned long count) { if (impl) return get_node_value().substr(offset, count); return DomString(); }
/**************************************************************************** * Function : get_response_value * * Parameters : * IN http_message_t* hmsg : HTTP response message * IN int code : return code in the HTTP response * IN char*name : name of the action * OUT int *upnp_error_code : UPnP error code * OUT IXML_Node ** action_value : SOAP response node * OUT DOMString * str_value : state varible value ( in the case of * querry state variable request) * * Description : This function handles the response coming back from the * device. This function parses the response and gives back the SOAP * response node. * * Return : int * return the type of the SOAP message if successful else returns * appropriate error. * * Note : ****************************************************************************/ static int get_response_value( IN http_message_t * hmsg, IN int code, IN char *name, OUT int *upnp_error_code, OUT IXML_Node ** action_value, OUT DOMString * str_value ) { IXML_Node *node = NULL; IXML_Node *root_node = NULL; IXML_Node *error_node = NULL; IXML_Document *doc = NULL; char *node_str = NULL; const char *temp_str = NULL; DOMString error_node_str = NULL; int err_code; xboolean done = FALSE; char *names[5]; const DOMString nodeValue; err_code = UPNP_E_BAD_RESPONSE; // default error // only 200 and 500 status codes are relevant if( ( hmsg->status_code != HTTP_OK && hmsg->status_code != HTTP_INTERNAL_SERVER_ERROR ) || !has_xml_content_type( hmsg ) ) { goto error_handler; } if( ixmlParseBufferEx( hmsg->entity.buf, &doc ) != IXML_SUCCESS ) { goto error_handler; } root_node = ixmlNode_getFirstChild( ( IXML_Node * ) doc ); if( root_node == NULL ) { goto error_handler; } if( code == SOAP_ACTION_RESP ) { // // try reading soap action response // assert( action_value != NULL ); *action_value = NULL; names[0] = "Envelope"; names[1] = "Body"; names[2] = name; if( dom_find_deep_node( names, 3, root_node, &node ) == UPNP_E_SUCCESS ) { node_str = ixmlPrintNode( node ); if( node_str == NULL ) { err_code = UPNP_E_OUTOF_MEMORY; goto error_handler; } if( ixmlParseBufferEx( node_str, ( IXML_Document ** ) action_value ) != IXML_SUCCESS ) { err_code = UPNP_E_BAD_RESPONSE; goto error_handler; } err_code = SOAP_ACTION_RESP; done = TRUE; } } else if( code == SOAP_VAR_RESP ) { // try reading var response assert( str_value != NULL ); *str_value = NULL; names[0] = "Envelope"; names[1] = "Body"; names[2] = "QueryStateVariableResponse"; names[3] = "return"; if( dom_find_deep_node( names, 4, root_node, &node ) == UPNP_E_SUCCESS ) { nodeValue = get_node_value( node ); if( nodeValue == NULL ) { goto error_handler; } *str_value = ixmlCloneDOMString( nodeValue ); err_code = SOAP_VAR_RESP; done = TRUE; } } if( !done ) { // not action or var resp; read error code and description *str_value = NULL; names[0] = "Envelope"; names[1] = "Body"; names[2] = "Fault"; names[3] = "detail"; names[4] = "UPnPError"; if( dom_find_deep_node( names, 5, root_node, &error_node ) != UPNP_E_SUCCESS ) { goto error_handler; } if( dom_find_node( "errorCode", error_node, &node ) != UPNP_E_SUCCESS ) { goto error_handler; } temp_str = get_node_value( node ); if( temp_str == NULL ) { goto error_handler; } *upnp_error_code = atoi( temp_str ); if( *upnp_error_code > 400 ) { err_code = *upnp_error_code; goto error_handler; // bad SOAP error code } if( code == SOAP_VAR_RESP ) { if( dom_find_node( "errorDescription", error_node, &node ) != UPNP_E_SUCCESS ) { goto error_handler; } nodeValue = get_node_value( node ); if( nodeValue == NULL ) { goto error_handler; } *str_value = ixmlCloneDOMString( nodeValue ); if( *str_value == NULL ) { goto error_handler; } err_code = SOAP_VAR_RESP_ERROR; } else if( code == SOAP_ACTION_RESP ) { error_node_str = ixmlPrintNode( error_node ); if( error_node_str == NULL ) { err_code = UPNP_E_OUTOF_MEMORY; goto error_handler; } if( ixmlParseBufferEx( error_node_str, ( IXML_Document ** ) action_value ) != IXML_SUCCESS ) { err_code = UPNP_E_BAD_RESPONSE; goto error_handler; } err_code = SOAP_ACTION_RESP_ERROR; } } error_handler: ixmlDocument_free( doc ); ixmlFreeDOMString( node_str ); ixmlFreeDOMString( error_node_str ); return err_code; }
int check_occupied(int* board, int pos_x, int pos_y) { return get_node_value(board, pos_x, pos_y) != TILE_0_VALUE; }
double monotonicity(int* board) { double totals[] = {0.0, 0.0 ,0.0, 0.0}; int current = 0; int next = 0; double current_value = 0; double next_value = 0; for (int i = 0; i < 4; i++) { // Check up and down current = 0; next = current + 1; while (next < 4) { while ((next < 4) && !check_occupied(board, i, next)) { next++; } if (next >= 4) { next--; } current_value = 0; next_value = 0; if (check_occupied(board, i, current)) { current_value = get_node_value(board, i, current); } if (check_occupied(board, i, next)) { next_value = get_node_value(board, i, next); } if (current_value > next_value) { totals[0] += next_value - current_value; } else if (next_value > current_value) { totals[1] += current_value - next_value; } current = next; next++; } } for (int j = 0; j < 4; j++) { // Check left and right current = 0; next = current + 1; while (next < 4) { while ((next < 4) && !check_occupied(board, j, next)) { next++; } if (next >= 4) { next--; } current_value = 0; next_value = 0; if (check_occupied(board, current, j)) { current_value = get_node_value(board, current, j); } if (check_occupied(board, next, j)) { next_value = get_node_value(board, next, j); } if (current_value > next_value) { totals[2] += next_value - current_value; } else if (next_value > current_value) { totals[3] += current_value - next_value; } current = next; next++; } } double total_up_down = (totals[0] > totals[1]) ? totals[0] : totals[1]; double total_left_right = (totals[2] > totals[3]) ? totals[2] : totals[3]; return total_up_down + total_left_right; }