void RL::ListImpl::on_xcap_answer (bool error, std::string value) { if (error) { // FIXME: how to properly tell the user? } else { doc = std::tr1::shared_ptr<xmlDoc> (xmlRecoverMemory (value.c_str (), value.length ()), xmlFreeDoc); if ( !doc) doc = std::tr1::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); node = xmlDocGetRootElement (doc.get ()); if (node == NULL || node->name == NULL || !xmlStrEqual (BAD_CAST "list", node->name)) { // FIXME : how to properly tell the user? } else { parse (); } } }
int messageCheckAck(char *messageReceived, int messageSize) { char *path = "/acknowledge"; xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; xmlInitParser(); doc = xmlRecoverMemory(messageReceived, messageSize); if (doc == NULL) { return -1;} xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { xmlFreeDoc(doc); return -1; } xpathObj = xmlXPathEvalExpression(BAD_CAST path, xpathCtx); if(xpathObj->nodesetval->nodeTab == NULL){ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return(0); } xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); xmlCleanupParser(); return 1; }
void RL::Heap::parse_doc (std::string raw) { doc = std::tr1::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc); if ( !doc) doc = std::tr1::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); xmlNodePtr doc_root = xmlDocGetRootElement (doc.get ()); if (doc_root == NULL || doc_root->name == NULL || !xmlStrEqual (BAD_CAST "resource-lists", doc_root->name)) { std::cout << "Invalid document in " << __PRETTY_FUNCTION__ << std::endl; // FIXME: warn the user somehow? doc.reset (); } else { for (xmlNodePtr child = doc_root->children; child != NULL; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("list"), child->name)) { parse_list (child); break; // read only one! } } }
static xmlDocPtr idol_pl_parser_parse_xml_file (GFile *file) { xmlDocPtr doc; char *contents; gsize size; if (g_file_load_contents (file, NULL, &contents, &size, NULL, NULL) == FALSE) return NULL; /* Try to remove HTML style comments */ { char *needle; while ((needle = strstr (contents, "<!--")) != NULL) { while (strncmp (needle, "-->", 3) != 0) { *needle = ' '; needle++; if (*needle == '\0') break; } } } doc = xmlParseMemory (contents, size); if (doc == NULL) doc = xmlRecoverMemory (contents, size); g_free (contents); return doc; }
void RL::Entry::on_xcap_answer (bool error, std::string value) { if (error) { set_note (value); } else { doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (value.c_str (), value.length ()), xmlFreeDoc); if ( !doc) doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); node = xmlDocGetRootElement (doc.get ()); if (node == NULL || node->name == NULL || !xmlStrEqual (BAD_CAST "entry", node->name)) { set_note (_("Invalid server data")); } else { set_note (""); parse (); updated (); } } }
LM::Bank::Bank (boost::shared_ptr<Ekiga::PersonalDetails> details_, boost::shared_ptr<Dialect> dialect_, boost::shared_ptr<Cluster> cluster_): details(details_), cluster(cluster_), dialect(dialect_), doc (NULL) { gchar* c_raw = gm_conf_get_string (JABBER_KEY); if (c_raw != NULL) { // we already have it in store const std::string raw = c_raw; doc = xmlRecoverMemory (raw.c_str (), raw.length ()); xmlNodePtr root = xmlDocGetRootElement (doc); if (root == NULL) { root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc, root); } for (xmlNodePtr child = root->children; child != NULL; child = child->next) { if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("entry"), child->name)) { boost::shared_ptr<Account> account (new Account (details, dialect, cluster, child)); add (account); } } g_free (c_raw); } else { // create a new XML document doc = xmlNewDoc (BAD_CAST "1.0"); xmlNodePtr root = xmlNewDocNode (doc, NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc, root); } }
/*Experimental*/ int messageGetSingleValue(char *messageReceived, int messageSize, char *path, char *value, int valueMaxSize, int decodeB64) { char *tempB64, *temp; int finalSize; xmlDocPtr doc = NULL;/* node pointers */ xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; LIBXML_TEST_VERSION; xmlInitParser(); doc = xmlRecoverMemory(messageReceived, messageSize); if (doc == NULL) { return -1;} xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { xmlFreeDoc(doc); return -1; }; xpathObj = xmlXPathEvalExpression(BAD_CAST path, xpathCtx); if(xpathObj == NULL){ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return(-1); }; tempB64 = (char *) xmlXPathCastToString (xpathObj); if(decodeB64) { temp = b64decode((unsigned char *) tempB64, strlen(tempB64) , &finalSize); free(tempB64); } else { temp = tempB64; finalSize = strlen(temp); } if( finalSize + 1 <= valueMaxSize) { memcpy (value, temp, finalSize); value[finalSize] = '\0'; } else finalSize = -1; free(temp); xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); xmlCleanupParser(); return finalSize; }
/* * SCPD URL downloaded. */ static void got_scpd_url (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, GetSCPDURLData *data) { GUPnPServiceIntrospection *introspection; GError *error; GUPnPServiceInfoPrivate *priv; introspection = NULL; error = NULL; if (msg->status_code == SOUP_STATUS_CANCELLED) return; if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { xmlDoc *scpd; scpd = xmlRecoverMemory (msg->response_body->data, msg->response_body->length); if (scpd) { introspection = gupnp_service_introspection_new (scpd); xmlFreeDoc (scpd); } if (!introspection) { error = g_error_new (GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_INVALID_RESPONSE, "Could not parse SCPD"); } } else error = _gupnp_error_new_server_error (msg); /* prevent the callback from canceling the cancellable * (and so freeing data just before we do) */ if (data->cancellable) g_cancellable_disconnect (data->cancellable, data->cancelled_id); priv = gupnp_service_info_get_instance_private (data->info); priv->pending_gets = g_list_remove (priv->pending_gets, data); data->callback (data->info, introspection, error, data->user_data); if (error) g_error_free (error); get_scpd_url_data_free (data); }
xmlDocPtr XaLibDom::DomFromString(string XmlString) { xmlDocPtr XmlDomDoc; const char *XmlChar = (char*)XmlString.c_str(); int XmlStringSize=XmlString.size(); XmlDomDoc = xmlRecoverMemory(XmlChar,XmlStringSize); return XmlDomDoc; };
int messageRemoveElement(char *original, int originalSize, char *path, char *modified, int maxSize) { int messageSize; int result; xmlChar *s; xmlDocPtr doc = NULL;/* node pointers */ xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; xmlInitParser(); //xmlKeepBlanksDefault(0); doc = xmlRecoverMemory(original, originalSize); if (doc == NULL) { return -1;} xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { xmlFreeDoc(doc); return -1; }; xpathObj = xmlXPathEvalExpression(BAD_CAST path, xpathCtx); if(xpathObj == NULL){ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return(-1); }; xmlUnlinkNode(xpathObj->nodesetval->nodeTab[0]); xmlFreeNode(xpathObj->nodesetval->nodeTab[0]); xmlDocDumpMemory(doc, &s, &messageSize); if( messageSize + 1 <= maxSize) { strcpy((char *) modified, (char *) s); result = messageSize + 1; } else result = -1; xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFree(s); xmlFreeDoc(doc); xmlCleanupParser(); return result; }
xmlDocPtr XaLibDom::DomFromFile(const vector<string> XmlFilesPath,const int& AddRootTag) { xmlDocPtr XmlDomDoc; string XmlStringTotal=""; if (AddRootTag==1){ XmlStringTotal.append("<root>"); } //ADDING FILE int XmlFilesSize=XmlFilesPath.size(); if(XmlFilesSize>0) { unique_ptr<XaLibChar> LibChar (new XaLibChar()); for(auto i=0; i<XmlFilesSize; i++) { string XmlFilePath=XmlFilesPath.at(i).c_str(); char* XmlFilePathChar=(char*)XmlFilePath.c_str(); ifstream MyFile; MyFile.open(XmlFilePathChar); if (MyFile.is_open()){ string TmpString; while(getline(MyFile,TmpString) ) { XaLibChar::ClearReturn(TmpString); //string TmpStringCleared=LibChar->ClearReturn(TmpString); XmlStringTotal.append(TmpString); } MyFile.close(); } } } const char *XmlChar = (char*)XmlStringTotal.c_str(); int XmlStringSize=XmlStringTotal.size(); XmlDomDoc = xmlRecoverMemory(XmlChar,XmlStringSize); return XmlDomDoc; };
/* * Public API */ Local::Heap::Heap (boost::shared_ptr<Ekiga::PresenceCore> _presence_core, boost::shared_ptr<Local::Cluster> _local_cluster): presence_core(_presence_core), local_cluster(_local_cluster), doc () { xmlNodePtr root; gchar *c_raw = gm_conf_get_string (ROSTER_KEY); // Build the XML document representing the contacts list from the configuration if (c_raw != NULL) { const std::string raw = c_raw; doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc); if ( !doc) doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); root = xmlDocGetRootElement (doc.get ()); if (root == NULL) { root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); } for (xmlNodePtr child = root->children; child != NULL; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST ("entry"), child->name)) add (child); g_free (c_raw); // Or create a new XML document } else { doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); { // add 500, 501 and 520 at ekiga.net in this case! std::set<std::string> groups; groups.insert (_("Services")); add (_("Echo test"), "sip:[email protected]", groups); add (_("Conference room"), "sip:[email protected]", groups); add (_("Call back test"), "sip:[email protected]", groups); } } }
/* * SCPD URL downloaded. */ static void got_scpd_url (SoupSession *session, SoupMessage *msg, GetSCPDURLData *data) { GUPnPServiceIntrospection *introspection; GError *error; introspection = NULL; error = NULL; if (msg->status_code == SOUP_STATUS_CANCELLED) return; if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { xmlDoc *scpd; scpd = xmlRecoverMemory (msg->response_body->data, msg->response_body->length); if (scpd) { introspection = gupnp_service_introspection_new (scpd); xmlFreeDoc (scpd); } if (!introspection) { error = g_error_new (GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_INVALID_RESPONSE, "Could not parse SCPD"); } } else error = _gupnp_error_new_server_error (msg); data->info->priv->pending_gets = g_list_remove (data->info->priv->pending_gets, data); data->callback (data->info, introspection, error, data->user_data); if (error) g_error_free (error); get_scpd_url_data_free (data); }
OPENLDAP::Source::Source (Ekiga::ServiceCore &_core): core(_core), doc(), should_add_ekiga_net_book(false) { xmlNodePtr root; gchar *c_raw = gm_conf_get_string (KEY); if (c_raw != NULL && strcmp (c_raw, "")) { const std::string raw = c_raw; doc = std::tr1::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc); if ( !doc) doc = std::tr1::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); root = xmlDocGetRootElement (doc.get ()); if (root == NULL) { root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); } migrate_from_3_0_0 (); for (xmlNodePtr child = root->children ; child != NULL ; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST "server", child->name)) add (child); g_free (c_raw); } else { doc = std::tr1::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); should_add_ekiga_net_book = true; } if (should_add_ekiga_net_book) new_ekiga_net_book (); }
RL::Cluster::Cluster (Ekiga::ServiceCore& core_): core(core_), doc() { boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core"); presence_core->presence_received.connect (boost::bind (&RL::Cluster::on_presence_received, this, _1, _2)); presence_core->status_received.connect (boost::bind (&RL::Cluster::on_status_received, this, _1, _2)); contacts_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (CONTACTS_SCHEMA)); std::string raw = contacts_settings->get_string (RL_KEY); if (!raw.empty ()) { doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc); if ( !doc) doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); xmlNodePtr root = xmlDocGetRootElement (doc.get ()); if (root == NULL) { root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); } else { for (xmlNodePtr child = root->children; child != NULL; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST "entry", child->name)) add (child); } } else { doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc); xmlNodePtr root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL); xmlDocSetRootElement (doc.get (), root); add ("https://xcap.sipthor.net/xcap-root", "alice", "123", "*****@*****.**", "XCAP Test", false); // FIXME: remove } }
OPENLDAP::Source::Source (Ekiga::ServiceCore &_core): core(_core), doc(NULL) { xmlNodePtr root; gchar *c_raw = gm_conf_get_string (KEY); if (c_raw != NULL && strcmp (c_raw, "")) { const std::string raw = c_raw; doc = xmlRecoverMemory (raw.c_str (), raw.length ()); if (doc == NULL) doc = xmlNewDoc (BAD_CAST "1.0"); root = xmlDocGetRootElement (doc); if (root == NULL) { root = xmlNewNode (NULL, BAD_CAST "list"); xmlDocSetRootElement (doc, root); } for (xmlNodePtr child = root->children ; child != NULL ; child = child->next) if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST "server", child->name)) add (child); g_free (c_raw); } else { doc = xmlNewDoc (BAD_CAST "1.0"); root = xmlNewNode (NULL, BAD_CAST "list"); xmlDocSetRootElement (doc, root); new_ekiga_net_book (); } }
int messagecheckDiffieHellmanResponse( char *messageReceived, int messageSize ,char *sessionId, char *seqNumber, DH *dh) { char path [128]; xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx; xmlXPathObjectPtr xpathObj; xmlInitParser(); doc = xmlRecoverMemory(messageReceived, messageSize); if (doc == NULL) { return -1;} xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { xmlFreeDoc(doc); return -1; } strcpy(path, "/diffie-hellman[@sessionId = '"); strcat(path, sessionId); strcat(path, "' and @type= 'serverParam']"); xpathObj = xmlXPathEvalExpression(BAD_CAST path, xpathCtx); if(xpathObj == NULL){ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return(-1); } xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); xmlCleanupParser(); return 0; }
static void proxy_call_browse_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, &wc_error)) { error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_SEARCH_FAILED, _("Failed to browse: %s"), wc_error->message); op->callback (op->source, op->operation_id, NULL, 0, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlRecoverMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } gchar* xquery=NULL; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: xquery = "/CLASSIFICAVISTI/content"; break; case RAITV_MEDIA_TYPE_RECENT_THEME: xquery = "/INFORMAZIONICONTENTS/content"; break; default: goto finalize; } obj = xmlXPathEvalExpression ((xmlChar *) xquery, xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } if (nb_items < op->count) op->count = nb_items; op->category_info->count = nb_items; for (i = 0; i < nb_items; i++) { //Skip if(op->skip>0) { op->skip--; continue; } GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); GList *mapping = source->priv->raitv_browse_mappings; GrlMedia *media = grl_media_video_new (); while (mapping) { gchar *str; gchar *strvalue; RaitvAssoc *assoc = (RaitvAssoc *) mapping->data; str = g_strdup_printf ("string(%s[%i]/%s)", xquery,i + 1, assoc->exp); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { strvalue = g_strdup((gchar *) obj->stringval); //Sometimes GRL_METADATA_KEY_THUMBNAIL doesn't report complete url if(assoc->grl_key == GRL_METADATA_KEY_THUMBNAIL && !g_str_has_prefix(strvalue,"http://www.rai.tv/")) { strvalue = g_strdup_printf("http://www.rai.tv%s",obj->stringval); } GType _type; _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, strvalue); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi (strvalue)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof (strvalue)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { int year,month,day,hour,minute,seconds; sscanf((const char*)obj->stringval, "%02d/%02d/%04d %02d:%02d:%02d", &day, &month, &year, &hour,&minute, &seconds); GDateTime *date = g_date_time_new_local (year, month, day, hour,minute, seconds); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); if(date) g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } g_free (strvalue); } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) { break; } } finalize: g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); /* Signal the last element if it was not already signaled */ if (nb_items == 0) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } else { //Continue the search if(op->count>0) { //Skip the ones already read op->skip += nb_items; op->offset += nb_items; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: produce_from_popular_theme(op); break; case RAITV_MEDIA_TYPE_RECENT_THEME: produce_from_recent_theme(op); break; default: g_assert_not_reached (); break; } } } }
/* * Description URL downloaded. */ static void got_description_url (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg, GetDescriptionURLData *data) { GUPnPXMLDoc *doc; if (msg->status_code == SOUP_STATUS_CANCELLED) return; /* Now, make sure again this document is not already cached. If it is, * we re-use the cached one. */ doc = g_hash_table_lookup (data->control_point->priv->doc_cache, data->description_url); if (doc) { /* Doc was cached */ description_loaded (data->control_point, doc, data->udn, data->service_type, data->description_url); get_description_url_data_free (data); return; } /* Not cached */ if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { xmlDoc *xml_doc; /* Parse response */ xml_doc = xmlRecoverMemory (msg->response_body->data, msg->response_body->length); if (xml_doc) { doc = gupnp_xml_doc_new (xml_doc); description_loaded (data->control_point, doc, data->udn, data->service_type, data->description_url); /* Insert into document cache */ g_hash_table_insert (data->control_point->priv->doc_cache, g_strdup (data->description_url), doc); /* Make sure the document is removed from the cache * once finalized. */ g_object_weak_ref (G_OBJECT (doc), doc_finalized, data->control_point); /* If no proxy was created, make sure doc is freed. */ g_object_unref (doc); } else g_warning ("Failed to parse %s", data->description_url); } else g_warning ("Failed to GET %s: %s", data->description_url, msg->reason_phrase); get_description_url_data_free (data); }
/* simple function to retrieve an OPML document and parse and output all depth 1 outline tags as HTML into a buffer */ static void ns_blogChannel_download_request_cb (const struct updateResult * const result, gpointer user_data, guint32 flags) { struct requestData *requestData = user_data; xmlDocPtr doc = NULL; xmlNodePtr cur; GString *buffer = NULL; g_assert (NULL != requestData); if (result->data) { buffer = g_string_new (NULL); while (1) { doc = xmlRecoverMemory (result->data, result->size); if (NULL == doc) break; if (NULL == (cur = xmlDocGetRootElement (doc))) break; if (!xmlStrcmp (cur->name, BAD_CAST"opml") || !xmlStrcmp (cur->name, BAD_CAST"oml") || !xmlStrcmp (cur->name, BAD_CAST"outlineDocument")) { /* nothing */ } else break; cur = cur->xmlChildrenNode; while (cur) { if (!xmlStrcmp (cur->name, BAD_CAST"body")) { /* process all <outline> tags */ cur = cur->xmlChildrenNode; while (cur) { if (!xmlStrcmp (cur->name, BAD_CAST"outline")) { GString *tmp = getOutlineContents (cur); g_string_append_printf (buffer, "%s<br />", tmp->str); g_string_free (tmp, TRUE); } cur = cur->next; } break; } cur = cur->next; } break; } if (doc) xmlFreeDoc (doc); } if (buffer) { switch (requestData->tag) { case TAG_BLOGROLL: g_string_prepend (buffer, BLOGROLL_START); g_string_append (buffer, BLOGROLL_END); g_hash_table_insert (requestData->ctxt->tmpdata, g_strdup ("bC:blogRoll"), buffer->str); break; case TAG_MYSUBSCRIPTIONS: g_string_prepend (buffer, MYSUBSCR_START); g_string_append (buffer, MYSUBSCR_END); g_hash_table_insert (requestData->ctxt->tmpdata, g_strdup ("bC:mySubscriptions"), buffer->str); break; default: g_error ("wrong requestData->tag value"); break; } g_string_free (buffer, FALSE); buffer = g_string_new (NULL); g_string_append (buffer, g_hash_table_lookup (requestData->ctxt->tmpdata, "bC:blink")); g_string_append (buffer, g_hash_table_lookup (requestData->ctxt->tmpdata, "bC:blogRoll")); g_string_append (buffer, g_hash_table_lookup (requestData->ctxt->tmpdata, "bC:mySubscriptions")); metadata_list_set (&(requestData->ctxt->subscription->metadata), "blogChannel", buffer->str); g_string_free (buffer, TRUE); } g_list_free (requestData->ctxt->items); feed_free_parser_ctxt (requestData->ctxt); g_free (requestData); }
static void proxy_call_resolve_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; gsize length; gchar *value; gchar *thumbnail; gchar **tokens; GDateTime *date; GRL_DEBUG ("Response id=%u", op->operation_id); if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, &wc_error)) { error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_SEARCH_FAILED, _("Failed to resolve: %s"), wc_error->message); op->resolveCb (op->source, op->operation_id, op->media, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlRecoverMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_URL)) { value = eval_xquery ("/html/head/meta[@name='videourl']", xpath); if (value) { grl_media_set_url (op->media, value); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_TITLE)) { value = eval_xquery ("/html/head/meta[@name='title']", xpath); if (value) { grl_media_set_title (op->media, value); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_PUBLICATION_DATE)) { value = eval_xquery ("/html/head/meta[@name='itemDate']", xpath); if (value) { tokens = g_strsplit (value, "/", -1); if (g_strv_length (tokens) >= 3) { date = g_date_time_new_local (atoi (tokens[2]), atoi (tokens[1]), atoi (tokens[0]), 0, 0, 0); grl_media_set_publication_date (op->media, date); g_date_time_unref (date); } g_strfreev (tokens); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_THUMBNAIL)) { value = eval_xquery ("/html/head/meta[@name='vod-image']", xpath); if (value) { /* Sometimes thumbnail doesn't report a complete url */ if (value[0] == '/') { thumbnail = g_strconcat ("http://www.rai.tv", value, NULL); g_free (value); } else { thumbnail = value; } grl_media_set_thumbnail (op->media, thumbnail); g_free (thumbnail); } } finalize: op->resolveCb (op->source, op->operation_id, op->media, op->user_data, NULL); g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); }
/** * gupnp_service_info_get_introspection * @info: A #GUPnPServiceInfo * @error: return location for a #GError, or %NULL * * Note that introspection object is created from the information in service * description document (SCPD) provided by the service so it can not be created * if the service does not provide an SCPD. * * Warning: You should use gupnp_service_info_get_introspection_async() * instead, this function re-enter the GMainloop before returning. * * Return value: (transfer full): A new #GUPnPServiceIntrospection for this * service or %NULL. Unref after use. **/ GUPnPServiceIntrospection * gupnp_service_info_get_introspection (GUPnPServiceInfo *info, GError **error) { GUPnPServiceIntrospection *introspection; SoupSession *session; SoupMessage *msg; int status; char *scpd_url; xmlDoc *scpd; g_return_val_if_fail (GUPNP_IS_SERVICE_INFO (info), NULL); introspection = NULL; scpd_url = gupnp_service_info_get_scpd_url (info); msg = NULL; if (scpd_url != NULL) { msg = soup_message_new (SOUP_METHOD_GET, scpd_url); g_free (scpd_url); } if (msg == NULL) { g_set_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_INVALID_URL, "No valid SCPD URL defined"); return NULL; } /* Send off the message */ session = gupnp_context_get_session (info->priv->context); status = soup_session_send_message (session, msg); if (!SOUP_STATUS_IS_SUCCESSFUL (status)) { _gupnp_error_set_server_error (error, msg); g_object_unref (msg); return NULL; } scpd = xmlRecoverMemory (msg->response_body->data, msg->response_body->length); g_object_unref (msg); if (scpd) { introspection = gupnp_service_introspection_new (scpd); xmlFreeDoc (scpd); } if (!introspection) { g_set_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_INVALID_RESPONSE, "Could not parse SCPD"); } return introspection; }
xmlDocPtr XaLibDom::DomFromStringAndFile(const VectorXmlFilePath& XmlFiles,const VectorXmlString& XmlStrings,const int& AddRootTag) { xmlDocPtr XmlDomDoc; string XmlStringTotal=""; if (AddRootTag==1){ XmlStringTotal.append("<root>"); } else if(AddRootTag==2){ XmlStringTotal.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); XmlStringTotal.append("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"); XmlStringTotal.append("<xsl:output method=\"html\" encoding=\"UTF-8\"/>"); } //ADDING FILE int XmlFilesSize=XmlFiles.size(); if(XmlFilesSize>0) { unique_ptr<XaLibChar> LibChar (new XaLibChar()); for(int i=0; i<XmlFilesSize; i++) { string XmlFilePath=XmlFiles.at(i).c_str(); char* XmlFilePathChar=(char*)XmlFilePath.c_str(); ifstream MyFile; MyFile.open(XmlFilePathChar); if (MyFile.is_open()){ string TmpString; while(getline(MyFile,TmpString) ) { XaLibChar::ClearReturn(TmpString); //string TmpStringCleared=LibChar->ClearReturn(TmpString); XmlStringTotal.append(TmpString); } MyFile.close(); } } } //ADDING STRINGS int XmlStringsSize=XmlStrings.size(); if(XmlStringsSize>0) { for(int j=0; j<XmlStringsSize; j++) { string XmlString=XmlStrings.at(j).c_str(); XmlStringTotal.append(XmlString); } } if (AddRootTag==1){ XmlStringTotal.append("</root>"); } else if(AddRootTag==2){ XmlStringTotal.append("</xsl:stylesheet>"); } const char *XmlChar = (char*)XmlStringTotal.c_str(); int XmlStringSize=XmlStringTotal.size(); XmlDomDoc = xmlRecoverMemory(XmlChar,XmlStringSize); return XmlDomDoc; };
/** * gupnp_didl_lite_parser_parse_didl_recursive: * @parser: A #GUPnPDIDLLiteParser * @didl: The DIDL-Lite XML string to be parsed * @error: The location where to store any error, or %NULL * * Parses DIDL-Lite XML string @didl, emitting the ::object-available, * ::item-available and ::container-available signals appropriately during the * process. * * Return value: TRUE on success. **/ gboolean gupnp_didl_lite_parser_parse_didl_recursive (GUPnPDIDLLiteParser *parser, const char *didl, gboolean recursive, GError **error) { xmlDoc *doc; xmlNode *element; xmlNs *upnp_ns = NULL; xmlNs *dc_ns = NULL; xmlNs *dlna_ns = NULL; xmlNs *pv_ns = NULL; GUPnPAVXMLDoc *xml_doc = NULL; gboolean result; doc = xmlRecoverMemory (didl, strlen (didl)); if (doc == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "Could not parse DIDL-Lite XML:\n%s", didl); return FALSE; } /* Get a pointer to root element */ element = xml_util_get_element ((xmlNode *) doc, "DIDL-Lite", NULL); if (element == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "No 'DIDL-Lite' node in the DIDL-Lite XML:\n%s", didl); xmlFreeDoc (doc); return FALSE; } if (element->children == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY, "Empty 'DIDL-Lite' node in the DIDL-Lite XML:\n%s", didl); xmlFreeDoc (doc); return FALSE; } /* Create namespaces if they don't exist */ upnp_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_UPNP); if (! upnp_ns) upnp_ns = xml_util_create_namespace (xmlDocGetRootElement (doc), GUPNP_XML_NAMESPACE_UPNP); dc_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_DC); if (! dc_ns) dc_ns = xml_util_create_namespace (xmlDocGetRootElement (doc), GUPNP_XML_NAMESPACE_DC); dlna_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_DLNA); if (! dlna_ns) dlna_ns = xml_util_create_namespace (xmlDocGetRootElement (doc), GUPNP_XML_NAMESPACE_DLNA); pv_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_PV); if (! pv_ns) pv_ns = xml_util_create_namespace (xmlDocGetRootElement (doc), GUPNP_XML_NAMESPACE_PV); xml_doc = xml_doc_new (doc); result = parse_elements (parser, element, xml_doc, upnp_ns, dc_ns, dlna_ns, pv_ns, recursive, error); xml_doc_unref (xml_doc); return result; }
/** * gupnp_feature_list_parser_parse_text: * @parser: A #GUPnPFeatureListParser * @text: The feature list string to be parsed * @error: The location where to store the error information if any, or NULL * * Parses @text and returns the list of available features. * If an error occured @error will be set. * * Return value: (transfer full) (element-type GUPnPFeature): The list of * features or %NULL if an error occured. **/ GList * gupnp_feature_list_parser_parse_text (G_GNUC_UNUSED GUPnPFeatureListParser *parser, const char *text, GError **error) { xmlDoc *doc; xmlNode *element; GList *feature_list = NULL; doc = xmlRecoverMemory (text, strlen (text)); if (doc == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "Could not parse FeatureList XML:\n%s", text); return NULL; } /* Get a pointer to root element */ element = av_xml_util_get_element ((xmlNode *) doc, "Features", NULL); if (element == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "No 'Features' node in the XML:\n%s", text); xmlFreeDoc (doc); return NULL; } for (element = element->children; element; element = element->next) { GUPnPFeature *feature; const char *name; const char *version; char *object_ids; if (g_ascii_strcasecmp ((char *) element->name, "Feature") == 0) { name = av_xml_util_get_attribute_content (element, "name"); version = av_xml_util_get_attribute_content (element, "version"); if (!name || !version) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, "Invalid attributes in 'Feature' " "node in the XML:\n%s", text); xmlFreeDoc (doc); if (feature_list) g_list_free_full (feature_list, g_object_unref); return NULL; } object_ids = get_feature_object_ids (element); feature = g_object_new (GUPNP_TYPE_FEATURE, "name", name, "version", version, "object-ids", object_ids, NULL); feature_list = g_list_append (feature_list, feature); g_free (object_ids); } } xmlFreeDoc (doc); return feature_list; }