Esempio n. 1
0
File: Utils.c Progetto: cran/XML
SEXP
R_parseURI(SEXP r_uri)
{
  xmlURIPtr uri;
  SEXP ans, names;
  int i= 0;
  uri = xmlParseURI( CHAR( STRING_ELT( r_uri, 0 )));
  if(!uri) {
     PROBLEM "cannot parse URI %s", CHAR( STRING_ELT( r_uri, 0) )
     ERROR;
  }

  PROTECT(ans = NEW_LIST(8));
  PROTECT(names = NEW_CHARACTER(8));
 
  copyStrField(scheme);
  copyStrField(authority);
  copyStrField(server);
  copyStrField(user);
  copyStrField(path);
  copyStrField(query);
  copyStrField(fragment);
  SET_VECTOR_ELT(ans, i, ScalarInteger(uri->port));
  SET_STRING_ELT(names, i, mkChar("port"));

  SET_NAMES(ans, names);
  
  UNPROTECT(2);
  return(ans);
}
Esempio n. 2
0
/* ==================================================================== */
static char *getFileNameFromURL(char *url)
{
    char *filename = NULL;
    xmlURIPtr c = xmlParseURI(url);

    if (c == NULL)
    {
        Scierror(999, _("Could not parse the URL.\n"));
        return NULL;
    }

    if (c->path == NULL || strstr(c->path, "/") == 0 || strcmp(c->path, "/") == 0)
    {
        filename = (char *)MALLOC((strlen(DEFAULT_FILENAME) + 1) * sizeof(char));
        strcpy(filename, DEFAULT_FILENAME);
    }
    else
    {
        char bname[PATH_MAX] = {0};
        strncpy(bname, basename(c->path), sizeof(bname));
        filename = (char *)MALLOC((strlen(bname) + 1) * sizeof(char));
        strcpy(filename, bname);
    }
    return filename;

}
Esempio n. 3
0
/* {{{ proto DOMDocumentType dom_domimplementation_create_document_type(string qualifiedName, string publicId, string systemId);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
Since: DOM Level 2
*/
PHP_METHOD(domimplementation, createDocumentType)
{
	xmlDtd *doctype;
	int ret;
	size_t name_len = 0, publicid_len = 0, systemid_len = 0;
	char *name = NULL, *publicid = NULL, *systemid = NULL;
	xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
	xmlURIPtr uri;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
		return;
	}

	if (name_len == 0) {
		php_error_docref(NULL, E_WARNING, "qualifiedName is required");
		RETURN_FALSE;
	}

	if (publicid_len > 0) {
		pch1 = (xmlChar *) publicid;
	}
	if (systemid_len > 0) {
		pch2 = (xmlChar *) systemid;
	}

	uri = xmlParseURI(name);
	if (uri != NULL && uri->opaque != NULL) {
		localname = xmlStrdup((xmlChar *) uri->opaque);
		if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
			php_dom_throw_error(NAMESPACE_ERR, 1);
			xmlFreeURI(uri);
			xmlFree(localname);
			RETURN_FALSE;
		}
	} else {
		localname = xmlStrdup((xmlChar *) name);
	}

	/* TODO: Test that localname has no invalid chars
	php_dom_throw_error(INVALID_CHARACTER_ERR,);
	*/

	if (uri) {
		xmlFreeURI(uri);
	}

	doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
	xmlFree(localname);

	if (doctype == NULL) {
		php_error_docref(NULL, E_WARNING, "Unable to create DocumentType");
		RETURN_FALSE;
	}

	DOM_RET_OBJ((xmlNodePtr) doctype, &ret, NULL);
}
Esempio n. 4
0
URI::URI(gchar const *preformed) throw(BadURIException) {
    xmlURIPtr uri;
    if (!preformed) {
        throw MalformedURIException();
    }
    uri = xmlParseURI(preformed);
    if (!uri) {
        throw MalformedURIException();
    }
    _impl = Impl::create(uri);
}
Esempio n. 5
0
xmlNodePtr
soap_addressing_set_from_address_string(struct SoapEnv *envelope, const char *from)
{
  xmlURI *uri;
  xmlNodePtr ret;

  uri = xmlParseURI(from);
  ret = soap_addressing_set_from_address(envelope, uri);
  xmlFreeURI(uri);

  return ret;
}
Esempio n. 6
0
enum jal_status jal_create_reference_elem(
    const char *reference_uri,
    const char *digest_method,
    uint8_t *digest_buf,
    uint64_t len,
    xmlDocPtr doc,
    xmlNodePtr *elem)
{
    if(!doc || !elem || *elem || len <= 0 || !digest_method || !digest_buf) {
        return JAL_E_XML_CONVERSION;
    }

    xmlChar *namespace_uri = (xmlChar *)JAL_XMLDSIG_URI;
    xmlChar *xml_reference_uri = (xmlChar *)reference_uri;
    xmlChar *xml_digest_method = (xmlChar *)digest_method;

    xmlNodePtr reference_elem = xmlNewDocNode(doc, NULL, (xmlChar *) REFERENCE, NULL);
    xmlNodePtr digestmethod_elem = NULL;
    xmlNodePtr digestvalue_elem = NULL;

    enum jal_status ret = JAL_OK;

    if(reference_uri) {
        xmlURIPtr ret_uri = NULL;
        ret_uri = xmlParseURI(reference_uri);
        if (!ret_uri) {
            ret = JAL_E_INVAL_URI;
            goto err_out;
        }
        xmlFreeURI(ret_uri);
        xmlSetProp(reference_elem, (xmlChar *) URI, xml_reference_uri);
    }

    ret = jal_create_base64_element(doc, digest_buf, len, namespace_uri,
                                    (xmlChar *)DIGESTVALUE, &digestvalue_elem);
    if (ret != JAL_OK) {
        goto err_out;
    }

    digestmethod_elem = xmlNewChild(reference_elem, NULL, (xmlChar *) DIGESTMETHOD, NULL);
    xmlSetProp(digestmethod_elem, (xmlChar *)ALGORITHM, xml_digest_method);

    xmlAddChild(reference_elem, digestvalue_elem);

    *elem = reference_elem;

    return JAL_OK;

err_out:
    xmlFreeNodeList(reference_elem);
    return ret;
}
Esempio n. 7
0
static xmlURI *
_soap_addressing_extract_uri(xmlNodePtr node)
{
  xmlChar *content;
  xmlURI *uri = NULL;

  if ((content = xmlNodeGetContent(node)))
  {
    uri = xmlParseURI(content);
    xmlFree(content);
  }
  return uri;
}
Esempio n. 8
0
xmlNodePtr
soap_addressing_set_action_string(struct SoapEnv *envelope, const char *action)
{
  xmlURI *uri;
  xmlNodePtr ret;

  if (!(uri = xmlParseURI(action)))
    return NULL;

  ret = soap_addressing_set_action(envelope, uri);
  xmlFreeURI(uri);

  return ret;
}
Esempio n. 9
0
static Pvoid_t tokenize_uri(const char * uristr, Pvoid_t features) {
	xmlURIPtr uri = xmlParseURI(uristr);
	if (uri) {
		features = add_url_component(uri->path, features);

		if (uri->server) {
			replace(uri->server, strlen(uri->server), "www\\.", "");
			features = add_url_component(uri->server, features);
		}

		xmlFreeURI(uri);
	}

	return features;
}
Esempio n. 10
0
static gchar * 
ui_subscription_create_url (gchar *url,
                            gboolean auth, 
			    const gchar *username, 
			    const gchar *password) 
{
	gchar	*source = NULL;
	gchar *str, *tmp2;
	
	/* First, strip leading and trailing whitespace */
	str = g_strstrip(url);

	/* Add http:// if needed */
	if (strstr(str, "://") == NULL) {
		tmp2 = g_strdup_printf("http://%s",str);
		g_free(str);
		str = tmp2;
	}

	/* Add trailing / if needed */
	if (strstr(strstr(str, "://") + 3, "/") == NULL) {
		tmp2 = g_strdup_printf("%s/", str);
		g_free(str);
		str = tmp2;
	}

	/* Use the values in the textboxes if also specified in the URL! */
	if(auth) {
		xmlURIPtr uri = xmlParseURI(BAD_CAST str);
		if (uri != NULL) {
			xmlChar *sourceUrl;
			xmlFree(uri->user);
			uri->user = g_strdup_printf("%s:%s", username, password);
			sourceUrl = xmlSaveUri(uri);
			source = g_strdup(sourceUrl);
			g_free(uri->user);
			uri->user = NULL;
			xmlFree(sourceUrl);
			xmlFreeURI(uri);
		} else
			source = g_strdup(str);
	} else {
		source = g_strdup(str);
	}
	g_free(str);
	
	return source;
}
Esempio n. 11
0
static void
auth_dialog_load (AuthDialog *ad,
                     subscriptionPtr subscription,
                     gint flags)
{
	AuthDialogPrivate	*ui_data = ad->priv;
	gchar			*promptStr;
	gchar			*source = NULL;
	xmlURIPtr		uri;
	
	subscription->activeAuth = TRUE;
	
	ui_data->subscription = subscription;
	ui_data->flags = flags;
	
	ui_data->username = liferea_dialog_lookup (ui_data->dialog, "usernameEntry");
	ui_data->password = liferea_dialog_lookup (ui_data->dialog, "passwordEntry");
	
	uri = xmlParseURI (BAD_CAST subscription_get_source (ui_data->subscription));
	
	if (uri) {
		if (uri->user) {
			gchar *user = uri->user;
			gchar *pass = strstr (user, ":");
			if(pass) {
				pass[0] = '\0';
				pass++;
				gtk_entry_set_text (GTK_ENTRY (ui_data->password), pass);
			}
			gtk_entry_set_text (GTK_ENTRY (ui_data->username), user);
			xmlFree (uri->user);
			uri->user = NULL;
		}
		xmlFree (uri->user);
		uri->user = NULL;
		source = xmlSaveUri (uri);
		xmlFreeURI (uri);
	}
	
	promptStr = g_strdup_printf ( _("Enter the username and password for \"%s\" (%s):"),
	                             node_get_title (ui_data->subscription->node), source?source:_("Unknown source"));
	gtk_label_set_text (GTK_LABEL (liferea_dialog_lookup (ui_data->dialog, "prompt")), promptStr);
	g_free (promptStr);
	if (source)
		xmlFree (source);
}
Esempio n. 12
0
std::string utils::censor_url(const std::string& url) {
	std::string rv;
	if (url.length() > 0 && !utils::is_special_url(url)) {
		const char * myuri = url.c_str();
		xmlURIPtr uri = xmlParseURI(myuri);
		if (uri) {
			if (uri->user) {
				xmlFree(uri->user);
				uri->user = (char *)xmlStrdup((const xmlChar *)"*:*");
			}
			xmlChar * uristr = xmlSaveUri(uri);
			
			rv = (const char *)uristr;
			xmlFree(uristr);
			xmlFreeURI(uri);
		} else
			return url;
	} else {
		rv = url;
	}
	return rv;
}
Esempio n. 13
0
value
v2v_xml_parse_uri (value strv)
{
  CAMLparam1 (strv);
  CAMLlocal3 (rv, sv, ov);
  xmlURIPtr uri;

  uri = xmlParseURI (String_val (strv));
  if (uri == NULL)
    caml_invalid_argument ("parse_uri: unable to parse URI");

  rv = caml_alloc_tuple (9);

  /* field 0: uri_scheme : string option */
  if (uri->scheme) {
    sv = caml_copy_string (uri->scheme);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 0, ov);

  /* field 1: uri_opaque : string option */
  if (uri->opaque) {
    sv = caml_copy_string (uri->opaque);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 1, ov);

  /* field 2: uri_authority : string option */
  if (uri->authority) {
    sv = caml_copy_string (uri->authority);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 2, ov);

  /* field 3: uri_server : string option */
  if (uri->server) {
    sv = caml_copy_string (uri->server);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 3, ov);

  /* field 4: uri_user : string option */
  if (uri->user) {
    sv = caml_copy_string (uri->user);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 4, ov);

  /* field 5: uri_port : int */
  Store_field (rv, 5, Val_int (uri->port));

  /* field 6: uri_path : string option */
  if (uri->path) {
    sv = caml_copy_string (uri->path);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 6, ov);

  /* field 7: uri_fragment : string option */
  if (uri->fragment) {
    sv = caml_copy_string (uri->fragment);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 7, ov);

  /* field 8: uri_query_raw : string option */
  if (uri->query_raw) {
    sv = caml_copy_string (uri->query_raw);
    ov = caml_alloc (1, 0);
    Store_field (ov, 0, sv);
  }
  else ov = Val_int (0);
  Store_field (rv, 8, ov);

  xmlFreeURI (uri);

  CAMLreturn (rv);
}
Esempio n. 14
0
int main(int argc, char **argv) {
    int i;
    int ret;
    int exit_value = 0;


    if (argc <= 1) {
	usage(argv[0]);
	return(1);
    }

    LIBXML_TEST_VERSION
    for (i = 1; i < argc ; i++) {
	if (!strcmp(argv[i], "-"))
	    break;

	if (argv[i][0] != '-')
	    break;
	if ((!strcmp(argv[i], "-verbose")) ||
	    (!strcmp(argv[i], "-v")) ||
	    (!strcmp(argv[i], "--verbose"))) {
	    verbose++;
	    xmlCatalogSetDebug(verbose);
	} else if ((!strcmp(argv[i], "-noout")) ||
	    (!strcmp(argv[i], "--noout"))) {
            noout = 1;
	} else if ((!strcmp(argv[i], "-shell")) ||
	    (!strcmp(argv[i], "--shell"))) {
	    shell++;
            noout = 1;
	} else if ((!strcmp(argv[i], "-sgml")) ||
	    (!strcmp(argv[i], "--sgml"))) {
	    sgml++;
	} else if ((!strcmp(argv[i], "-create")) ||
	    (!strcmp(argv[i], "--create"))) {
	    create++;
	} else if ((!strcmp(argv[i], "-convert")) ||
	    (!strcmp(argv[i], "--convert"))) {
	    convert++;
	} else if ((!strcmp(argv[i], "-add")) ||
	    (!strcmp(argv[i], "--add"))) {
	    if (sgml)
		i += 2;
	    else
		i += 3;
	    add++;
	} else if ((!strcmp(argv[i], "-del")) ||
	    (!strcmp(argv[i], "--del"))) {
	    i += 1;
	    del++;
	} else {
	    fprintf(stderr, "Unknown option %s\n", argv[i]);
	    usage(argv[0]);
	    return(1);
	}
    }

    for (i = 1; i < argc; i++) {
	if ((!strcmp(argv[i], "-add")) ||
	    (!strcmp(argv[i], "--add"))) {
	    if (sgml)
		i += 2;
	    else
		i += 3;
	    continue;
	} else if ((!strcmp(argv[i], "-del")) ||
	    (!strcmp(argv[i], "--del"))) {
	    i += 1;
	    continue;
	} else if (argv[i][0] == '-')
	    continue;
	filename = argv[i];
	if (!sgml) {
	    ret = xmlLoadCatalog(argv[i]);
	    if ((ret < 0) && (create)) {
		xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
	    }
	}
	break;
    }

    if (convert)
        ret = xmlCatalogConvert();

    if ((add) || (del)) {
	for (i = 1; i < argc ; i++) {
	    if (!strcmp(argv[i], "-"))
		break;

	    if (argv[i][0] != '-')
		continue;
	    if (strcmp(argv[i], "-add") && strcmp(argv[i], "--add") &&
		strcmp(argv[i], "-del") && strcmp(argv[i], "--del"))
		continue;

	    if (sgml) {
		/*
		 * Maintenance of SGML catalogs.
		 */
		xmlCatalogPtr catal = NULL;
		xmlCatalogPtr super = NULL;

		catal = xmlLoadSGMLSuperCatalog(argv[i + 1]);

		if ((!strcmp(argv[i], "-add")) ||
		    (!strcmp(argv[i], "--add"))) {
		    if (catal == NULL)
			catal = xmlNewCatalog(1);
		    super = xmlLoadSGMLSuperCatalog(XML_SGML_DEFAULT_CATALOG);
		    if (super == NULL)
			super = xmlNewCatalog(1);

		    xmlACatalogAdd(catal, BAD_CAST "CATALOG",
					 BAD_CAST argv[i + 2], NULL);
		    xmlACatalogAdd(super, BAD_CAST "CATALOG",
					 BAD_CAST argv[i + 1], NULL);
		} else {
		    if (catal != NULL)
			ret = xmlACatalogRemove(catal, BAD_CAST argv[i + 2]);
		    else
			ret = -1;
		    if (ret < 0) {
			fprintf(stderr, "Failed to remove entry from %s\n",
				argv[i + 1]);
			exit_value = 1;
		    }
		    if ((noout) && (catal != NULL) &&
			(xmlCatalogIsEmpty(catal))) {
			super = xmlLoadSGMLSuperCatalog(
				   XML_SGML_DEFAULT_CATALOG);
			if (super != NULL) {
			    ret = xmlACatalogRemove(super,
				    BAD_CAST argv[i + 1]);
			    if (ret < 0) {
				fprintf(stderr,
					"Failed to remove entry from %s\n",
					XML_SGML_DEFAULT_CATALOG);
				exit_value = 1;
			    }
			}
		    }
		}
		if (noout) {
		    FILE *out;

		    if (xmlCatalogIsEmpty(catal)) {
			remove(argv[i + 1]);
		    } else {
			out = fopen(argv[i + 1], "w");
			if (out == NULL) {
			    fprintf(stderr, "could not open %s for saving\n",
				    argv[i + 1]);
			    exit_value = 2;
			    noout = 0;
			} else {
			    xmlACatalogDump(catal, out);
			    fclose(out);
			}
		    }
		    if (super != NULL) {
			if (xmlCatalogIsEmpty(super)) {
			    remove(XML_SGML_DEFAULT_CATALOG);
			} else {
			    out = fopen(XML_SGML_DEFAULT_CATALOG, "w");
			    if (out == NULL) {
				fprintf(stderr,
					"could not open %s for saving\n",
					XML_SGML_DEFAULT_CATALOG);
				exit_value = 2;
				noout = 0;
			    } else {
				
				xmlACatalogDump(super, out);
				fclose(out);
			    }
			}
		    }
		} else {
		    xmlACatalogDump(catal, stdout);
		}
		i += 2;
	    } else {
		if ((!strcmp(argv[i], "-add")) ||
		    (!strcmp(argv[i], "--add"))) {
			if ((argv[i + 3] == NULL) || (argv[i + 3][0] == 0))
			    ret = xmlCatalogAdd(BAD_CAST argv[i + 1], NULL,
						BAD_CAST argv[i + 2]);
			else
			    ret = xmlCatalogAdd(BAD_CAST argv[i + 1],
						BAD_CAST argv[i + 2],
						BAD_CAST argv[i + 3]);
			if (ret != 0) {
			    printf("add command failed\n");
			    exit_value = 3;
			}
			i += 3;
		} else if ((!strcmp(argv[i], "-del")) ||
		    (!strcmp(argv[i], "--del"))) {
		    ret = xmlCatalogRemove(BAD_CAST argv[i + 1]);
		    if (ret < 0) {
			fprintf(stderr, "Failed to remove entry %s\n",
				argv[i + 1]);
			exit_value = 1;
		    }
		    i += 1;
		}
	    }
	}
	
    } else if (shell) {
	usershell();
    } else {
	for (i++; i < argc; i++) {
	    xmlURIPtr uri;
	    xmlChar *ans;
	    
	    uri = xmlParseURI(argv[i]);
	    if (uri == NULL) {
		ans = xmlCatalogResolvePublic((const xmlChar *) argv[i]);
		if (ans == NULL) {
		    printf("No entry for PUBLIC %s\n", argv[i]);
		    exit_value = 4;
		} else {
		    printf("%s\n", ans);
		    xmlFree(ans);
		}
	    } else {
                xmlFreeURI(uri);
		ans = xmlCatalogResolveSystem((const xmlChar *) argv[i]);
		if (ans == NULL) {
		    printf("No entry for SYSTEM %s\n", argv[i]);
		    exit_value = 4;
		} else {
		    printf("%s\n", ans);
		    xmlFree(ans);
		}
	    }
	}
    }
    if ((!sgml) && ((add) || (del) || (create) || (convert))) {
	if (noout) {
	    FILE *out;

	    out = fopen(filename, "w");
	    if (out == NULL) {
		fprintf(stderr, "could not open %s for saving\n", filename);
		exit_value = 2;
		noout = 0;
	    } else {
		xmlCatalogDump(out);
	    }
	} else {
	    xmlCatalogDump(stdout);
	}
    }

    /*
     * Cleanup and check for memory leaks
     */
    xmlCleanupParser();
    xmlMemoryDump();
    return(exit_value);
}
Esempio n. 15
0
int
virt_viewer_util_extract_host(const char *uristr,
                              char **scheme,
                              char **host,
                              char **transport,
                              char **user,
                              int *port)
{
    xmlURIPtr uri;
    char *offset = NULL;

    if (uristr == NULL ||
        !g_ascii_strcasecmp(uristr, "xen"))
        uristr = "xen:///";

    uri = xmlParseURI(uristr);
    g_return_val_if_fail(uri != NULL, 1);

    if (host) {
        if (!uri->server) {
            *host = g_strdup("localhost");
        } else {
            if (uri->server[0] == '[') {
                gchar *tmp;
                *host = g_strdup(uri->server + 1);
                if ((tmp = strchr(*host, ']')))
                    *tmp = '\0';
            } else {
                *host = g_strdup(uri->server);
            }
        }
    }

    if (user) {
        if (uri->user)
            *user = g_strdup(uri->user);
        else
            *user = NULL;
    }

    if (port)
        *port = uri->port;

    if (uri->scheme)
        offset = strchr(uri->scheme, '+');

    if (transport) {
        if (offset)
            *transport = g_strdup(offset + 1);
        else
            *transport = NULL;
    }

    if (scheme && uri->scheme) {
        if (offset)
            *scheme = g_strndup(uri->scheme, offset - uri->scheme);
        else
            *scheme = g_strdup(uri->scheme);
    }

    xmlFreeURI(uri);
    return 0;
}
Esempio n. 16
0
static void
subscription_prop_dialog_load (SubscriptionPropDialog *spd, 
                               subscriptionPtr subscription) 
{
	gint 		interval;
	gint		default_update_interval;
	gint		defaultInterval, spinSetInterval;
	gchar 		*defaultIntervalStr;
	nodePtr		node = subscription->node;
	feedPtr		feed = (feedPtr)node->data;

	spd->priv->subscription = subscription;

	/* General */
	gtk_entry_set_text(GTK_ENTRY(spd->priv->feedNameEntry), node_get_title(node));

	spd->priv->refreshInterval = liferea_dialog_lookup(spd->priv->dialog,"refreshIntervalSpinButton");
	
	interval = subscription_get_update_interval(subscription);
	defaultInterval = subscription_get_default_update_interval(subscription);
	conf_get_int_value (DEFAULT_UPDATE_INTERVAL, &default_update_interval);
	spinSetInterval = defaultInterval > 0 ? defaultInterval : default_update_interval;
	
	if (-2 >= interval) {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalNever")), TRUE);
	} else if (-1 == interval) {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalDefault")), TRUE);
	} else {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalSpecific")), TRUE);
		spinSetInterval = interval;
	}
	
	/* Set refresh interval spin button and combo box */
	if (spinSetInterval % 1440 == 0) {	/* days */
		gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 2);
		spinSetInterval /= 1440;
	} else if (spinSetInterval % 60 == 0) {	/* hours */
		gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 1);
		spinSetInterval /= 60;
	} else {
		gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 0);
	}
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spd->priv->refreshInterval), spinSetInterval);

	gtk_widget_set_sensitive (spd->priv->refreshInterval, interval > 0);
	gtk_widget_set_sensitive (spd->priv->refreshIntervalUnit, interval > 0);
	
	/* setup info label about default update interval */
	if(-1 != defaultInterval)
		defaultIntervalStr = g_strdup_printf(ngettext("The provider of this feed suggests an update interval of %d minute.", 
		                                              "The provider of this feed suggests an update interval of %d minutes.",
		                                              defaultInterval), defaultInterval);
	else
		defaultIntervalStr = g_strdup(_("This feed specifies no default update interval."));

	gtk_label_set_text(GTK_LABEL(liferea_dialog_lookup(spd->priv->dialog, "feedUpdateInfo")), defaultIntervalStr);
	g_free(defaultIntervalStr);

	/* Source (only for feeds) */
	if (SUBSCRIPTION_TYPE(subscription) == feed_get_subscription_type ()) {
		if(subscription_get_source(subscription)[0] == '|') {
			gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), &(subscription_get_source(subscription)[1]));
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->cmdRadio), TRUE);
			ui_subscription_prop_enable_httpauth(spd->priv, FALSE);
			gtk_widget_set_sensitive(spd->priv->selectFile, TRUE);
		} else if(strstr(subscription_get_source(subscription), "://") != NULL) {
			xmlURIPtr uri = xmlParseURI(BAD_CAST subscription_get_source(subscription));
			xmlChar *parsedUrl;
			if(uri) {
				if(uri->user) {
					gchar *user = uri->user;
					gchar *pass = strstr(user, ":");
					if(pass) {
						pass[0] = '\0';
						pass++;
						gtk_entry_set_text(GTK_ENTRY(spd->priv->password), pass);
					}
					gtk_entry_set_text(GTK_ENTRY(spd->priv->username), user);
					xmlFree(uri->user);
					uri->user = NULL;
					gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->authcheckbox), TRUE);
				}
				parsedUrl = xmlSaveUri(uri);
				gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), parsedUrl);
				xmlFree(parsedUrl);
				xmlFreeURI(uri);
			} else {
				gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), subscription_get_source(subscription));
			}
			ui_subscription_prop_enable_httpauth(spd->priv, TRUE);
			gtk_widget_set_sensitive(spd->priv->selectFile, FALSE);
		} else {
			/* File */
			gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), subscription_get_source(subscription));
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->fileRadio), TRUE);
			ui_subscription_prop_enable_httpauth(spd->priv, FALSE);
			gtk_widget_set_sensitive(spd->priv->selectFile, TRUE);
		}

		if(subscription_get_filter(subscription)) {
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "filterCheckbox")), TRUE);
			gtk_entry_set_text(GTK_ENTRY(liferea_dialog_lookup(spd->priv->dialog, "filterEntry")), subscription_get_filter(subscription));
		}
	}

	/* Archive */
	if(feed->cacheLimit == CACHE_DISABLE) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheDisable")), TRUE);
	} else if(feed->cacheLimit == CACHE_DEFAULT) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheDefault")), TRUE);
	} else if(feed->cacheLimit == CACHE_UNLIMITED) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheUnlimited")), TRUE);
	} else {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheLimited")), TRUE);
		gtk_spin_button_set_value(GTK_SPIN_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "cacheItemLimit")), feed->cacheLimit);
	}

	gtk_widget_set_sensitive(liferea_dialog_lookup(spd->priv->dialog, "cacheItemLimit"), feed->cacheLimit > 0);

	on_feed_prop_filtercheck(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "filterCheckbox")), spd->priv);
	
	/* Download */
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "dontUseProxyCheck")), subscription->updateOptions->dontUseProxy);

	/* Advanced */	
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "enclosureDownloadCheck")), feed->encAutoDownload);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "loadItemLinkCheck")), node->loadItemLink);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "ignoreCommentFeeds")), feed->ignoreComments);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "enforcePopupCheck")), feed->enforcePopup);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "preventPopupCheck")), feed->preventPopup);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "markAsReadCheck")), feed->markAsRead);

	/* Remove tabs we do not need... */
	if (SUBSCRIPTION_TYPE(subscription) != feed_get_subscription_type ()) {
		/* Remove "Allgemein", "Source" and "Download" tab */
		gtk_notebook_remove_page (GTK_NOTEBOOK (liferea_dialog_lookup (spd->priv->dialog, "subscriptionPropNotebook")), 0);
		gtk_notebook_remove_page (GTK_NOTEBOOK (liferea_dialog_lookup (spd->priv->dialog, "subscriptionPropNotebook")), 0);
		gtk_notebook_remove_page (GTK_NOTEBOOK (liferea_dialog_lookup (spd->priv->dialog, "subscriptionPropNotebook")), 1);
	}
}
Esempio n. 17
0
static void
xsltDocumentFunctionLoadDocument(xmlXPathParserContextPtr ctxt, xmlChar* URI)
{
    xsltTransformContextPtr tctxt;
    xmlURIPtr uri;
    xmlChar *fragment;
    xsltDocumentPtr idoc; /* document info */
    xmlDocPtr doc;
    xmlXPathContextPtr xptrctxt = NULL;
    xmlXPathObjectPtr resObj = NULL;

    tctxt = xsltXPathGetTransformContext(ctxt);
    if (tctxt == NULL) {
	xsltTransformError(NULL, NULL, NULL,
	    "document() : internal error tctxt == NULL\n");
	valuePush(ctxt, xmlXPathNewNodeSet(NULL));
	return;
    }

    uri = xmlParseURI((const char *) URI);
    if (uri == NULL) {
	xsltTransformError(tctxt, NULL, NULL,
	    "document() : failed to parse URI\n");
	valuePush(ctxt, xmlXPathNewNodeSet(NULL));
	return;
    }

    /*
     * check for and remove fragment identifier
     */
    fragment = (xmlChar *)uri->fragment;
    if (fragment != NULL) {
        xmlChar *newURI;
	uri->fragment = NULL;
	newURI = xmlSaveUri(uri);
	idoc = xsltLoadDocument(tctxt, newURI);
	xmlFree(newURI);
    } else
	idoc = xsltLoadDocument(tctxt, URI);
    xmlFreeURI(uri);

    if (idoc == NULL) {
	if ((URI == NULL) ||
	    (URI[0] == '#') ||
	    ((tctxt->style->doc != NULL) &&
	    (xmlStrEqual(tctxt->style->doc->URL, URI))))
	{
	    /*
	    * This selects the stylesheet's doc itself.
	    */
	    doc = tctxt->style->doc;
	} else {
	    valuePush(ctxt, xmlXPathNewNodeSet(NULL));

	    if (fragment != NULL)
		xmlFree(fragment);

	    return;
	}
    } else
	doc = idoc->doc;

    if (fragment == NULL) {
	valuePush(ctxt, xmlXPathNewNodeSet((xmlNodePtr) doc));
	return;
    }

    /* use XPointer of HTML location for fragment ID */
#ifdef LIBXML_XPTR_ENABLED
    xptrctxt = xmlXPtrNewContext(doc, NULL, NULL);
    if (xptrctxt == NULL) {
	xsltTransformError(tctxt, NULL, NULL,
	    "document() : internal error xptrctxt == NULL\n");
	goto out_fragment;
    }

    resObj = xmlXPtrEval(fragment, xptrctxt);
    xmlXPathFreeContext(xptrctxt);
#endif

    if (resObj == NULL)
	goto out_fragment;

    switch (resObj->type) {
	case XPATH_NODESET:
	    break;
	case XPATH_UNDEFINED:
	case XPATH_BOOLEAN:
	case XPATH_NUMBER:
	case XPATH_STRING:
	case XPATH_POINT:
	case XPATH_USERS:
	case XPATH_XSLT_TREE:
	case XPATH_RANGE:
	case XPATH_LOCATIONSET:
	    xsltTransformError(tctxt, NULL, NULL,
		"document() : XPointer does not select a node set: #%s\n",
		fragment);
	goto out_object;
    }

    valuePush(ctxt, resObj);
    xmlFree(fragment);
    return;

out_object:
    xmlXPathFreeObject(resObj);

out_fragment:
    valuePush(ctxt, xmlXPathNewNodeSet(NULL));
    xmlFree(fragment);
}
Esempio n. 18
0
static void
conf_proxy_reset_settings_cb (GSettings *settings,
                              guint cnxn_id,
                              gchar *key,
                              gpointer user_data)
{
	gchar		*proxyname, *proxyusername, *proxypassword, *tmp;
	gboolean	gnomeUseProxy;
	guint		proxyport;
	gint		proxydetectmode;
	gboolean	proxyuseauth;
	xmlURIPtr 	uri;

	proxyname = NULL;
	proxyport = 0;
	proxyusername = NULL;
	proxypassword = NULL;

	conf_get_int_value (PROXY_DETECT_MODE, &proxydetectmode);
	switch (proxydetectmode) {
		default:
		case 0:
			debug0 (DEBUG_CONF, "proxy auto detect is configured");

			/* first check for a configured GNOME proxy, note: older
			   GNOME versions do use the boolean flag GNOME_USE_PROXY
			   while newer ones use the string key GNOME_PROXY_MODE */
			conf_get_str_value_from_schema (proxy_settings, GNOME_PROXY_MODE, &tmp);
			gnomeUseProxy = g_str_equal (tmp, "manual");
			g_free (tmp);

			/* first check for a configured GNOME proxy */
			if (gnomeUseProxy) {
				conf_get_str_value_from_schema (proxy_settings, GNOME_PROXY_HOST, &proxyname);
				conf_get_int_value_from_schema (proxy_settings, GNOME_PROXY_PORT, &proxyport);
				debug2 (DEBUG_CONF, "using GNOME configured proxy: \"%s\" port \"%d\"", proxyname, proxyport);
				conf_get_bool_value_from_schema (proxy_settings, GNOME_PROXY_USEAUTH, &proxyuseauth);
				if (proxyuseauth) {
					conf_get_str_value_from_schema (proxy_settings, GNOME_PROXY_USER, &proxyusername);
					conf_get_str_value_from_schema (proxy_settings, GNOME_PROXY_PASSWD, &proxypassword);
				}
			} else {
				/* otherwise there could be a proxy specified in the environment
				   the following code was derived from SnowNews' setup.c */
				if (g_getenv("http_proxy")) {
					/* The pointer returned by getenv must not be altered.
					   What about mentioning this in the manpage of getenv? */
					debug0 (DEBUG_CONF, "using proxy from environment");
					do {
						uri = xmlParseURI (BAD_CAST g_getenv ("http_proxy"));
						if (uri == NULL) {
							debug0 (DEBUG_CONF, "parsing URI in $http_proxy failed!");
							break;
						}
						if (uri->server == NULL) {
							debug0 (DEBUG_CONF, "could not determine proxy name from $http_proxy!");
							xmlFreeURI (uri);
							break;
						}
						proxyname = g_strdup (uri->server);
						proxyport = (uri->port == 0) ? 3128 : uri->port;
						if (uri->user) {
							tmp = strtok (uri->user, ":");
							tmp = strtok (NULL, ":");
							if (tmp) {
								proxyusername = g_strdup (uri->user);
								proxypassword = g_strdup (tmp);
							}
						}
						xmlFreeURI (uri);
					} while (FALSE);
				}
			}
			if (!proxyname)
				debug0 (DEBUG_CONF, "no proxy GNOME of $http_proxy configuration found...");
			break;
		case 1:
			debug0 (DEBUG_CONF, "proxy is disabled by user");
			/* nothing to do */
			break;
		case 2:
			debug0 (DEBUG_CONF, "manual proxy is configured");

			conf_get_str_value (PROXY_HOST, &proxyname);
			conf_get_int_value (PROXY_PORT, &proxyport);
			conf_get_bool_value (PROXY_USEAUTH, &proxyuseauth);
			if (proxyuseauth) {
				conf_get_str_value (PROXY_USER, &proxyusername);
				conf_get_str_value (PROXY_PASSWD, &proxypassword);
			}
			break;
	}
	debug4 (DEBUG_CONF, "Proxy settings are now %s:%d %s:%s", proxyname != NULL ? proxyname : "NULL", proxyport,
		  proxyusername != NULL ? proxyusername : "******",
		  proxypassword != NULL ? proxypassword : "******");

	network_set_proxy (proxyname, proxyport, proxyusername, proxypassword);
}
Esempio n. 19
0
static virDrvOpenStatus openvzOpen(virConnectPtr conn,
                                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                   unsigned int flags)
{
    struct openvz_driver *driver;

    virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);

    if (conn->uri == NULL) {
        if (!virFileExists("/proc/vz"))
            return VIR_DRV_OPEN_DECLINED;

        if (access("/proc/vz", W_OK) < 0)
            return VIR_DRV_OPEN_DECLINED;

        conn->uri = xmlParseURI("openvz:///system");
        if (conn->uri == NULL) {
            virReportOOMError();
            return VIR_DRV_OPEN_ERROR;
        }
    } else {
        /* If scheme isn't 'openvz', then its for another driver */
        if (conn->uri->scheme == NULL ||
            STRNEQ (conn->uri->scheme, "openvz"))
            return VIR_DRV_OPEN_DECLINED;

        /* If server name is given, its for remote driver */
        if (conn->uri->server != NULL)
            return VIR_DRV_OPEN_DECLINED;

        /* If path isn't /system, then they typoed, so tell them correct path */
        if (conn->uri->path == NULL ||
            STRNEQ (conn->uri->path, "/system")) {
            openvzError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected OpenVZ URI path '%s', try openvz:///system"),
                        conn->uri->path);
            return VIR_DRV_OPEN_ERROR;
        }

        if (!virFileExists("/proc/vz")) {
            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("OpenVZ control file /proc/vz does not exist"));
            return VIR_DRV_OPEN_ERROR;
        }

        if (access("/proc/vz", W_OK) < 0) {
            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("OpenVZ control file /proc/vz is not accessible"));
            return VIR_DRV_OPEN_ERROR;
        }
    }

    /* We now know the URI is definitely for this driver, so beyond
     * here, don't return DECLINED, always use ERROR */

    if (VIR_ALLOC(driver) < 0) {
        virReportOOMError();
        return VIR_DRV_OPEN_ERROR;
    }

    if (virDomainObjListInit(&driver->domains) < 0)
        goto cleanup;

    if (!(driver->caps = openvzCapsInit()))
        goto cleanup;

    if (openvzLoadDomains(driver) < 0)
        goto cleanup;

    if (openvzExtractVersion(driver) < 0)
        goto cleanup;

    conn->privateData = driver;

    return VIR_DRV_OPEN_SUCCESS;

cleanup:
    openvzFreeDriver(driver);
    return VIR_DRV_OPEN_ERROR;
};
Esempio n. 20
0
static int
parse (const char *arg, char **path_ret, char **protocol_ret,
       char ***server_ret, char **username_ret, char **password_ret)
{
  CLEANUP_XMLFREEURI xmlURIPtr uri = NULL;
  CLEANUP_FREE char *socket = NULL;
  char *path;

  uri = xmlParseURI (arg);
  if (!uri) {
    fprintf (stderr, _("%s: --add: could not parse URI '%s'\n"),
             getprogname (), arg);
    return -1;
  }

  /* Note we don't do much checking of the parsed URI, since the
   * underlying function 'guestfs_add_drive_opts' will check for us.
   * So just the basics here.
   */
  if (uri->scheme == NULL || STREQ (uri->scheme, "")) {
    /* Probably can never happen. */
    fprintf (stderr, _("%s: %s: scheme of URI is NULL or empty\n"),
             getprogname (), arg);
    return -1;
  }

  socket = query_get (uri, "socket");

  if (uri->server && STRNEQ (uri->server, "") && socket) {
    fprintf (stderr, _("%s: %s: cannot both a server name and a socket query parameter\n"),
             getprogname (), arg);
    return -1;
  }

  /* Is this needed? XXX
  if (socket && socket[0] != '/') {
    fprintf (stderr, _("%s: --add %s: socket query parameter must be an absolute path\n"),
             getprogname (), arg);
    return -1;
  }
  */

  *protocol_ret = strdup (uri->scheme);
  if (*protocol_ret == NULL) {
    perror ("strdup: protocol");
    return -1;
  }

  if (make_server (uri, socket, server_ret) == -1) {
    free (*protocol_ret);
    return -1;
  }

  *password_ret = NULL;
  *username_ret = NULL;
  if (uri->user && STRNEQ (uri->user, "")) {
    char *p = strchr (uri->user, ':');
    if (p != NULL) {
      if (STRNEQ (p+1, "")) {
        *password_ret = strdup (p+1);
        if (*password_ret == NULL) {
          perror ("strdup: password");
          free (*protocol_ret);
          guestfs_int_free_string_list (*server_ret);
          return -1;
        }
      }
      *p = '\0';
    }
    *username_ret = strdup (uri->user);
    if (*username_ret == NULL) {
      perror ("strdup: username");
      free (*password_ret);
      free (*protocol_ret);
      guestfs_int_free_string_list (*server_ret);
      return -1;
    }
  }

  /* We may have to adjust the path depending on the protocol.  For
   * example ceph/rbd URIs look like rbd:///pool/disk, but the
   * exportname expected will be "pool/disk".  Here, uri->path will be
   * "/pool/disk" so we have to knock off the leading '/' character.
   */
  path = uri->path;
  if (path && path[0] == '/' &&
      (STREQ (uri->scheme, "gluster") ||
       STREQ (uri->scheme, "iscsi") ||
       STREQ (uri->scheme, "rbd") ||
       STREQ (uri->scheme, "sheepdog")))
    path++;

  *path_ret = strdup (path ? path : "");
  if (*path_ret == NULL) {
    perror ("strdup: path");
    free (*protocol_ret);
    guestfs_int_free_string_list (*server_ret);
    free (*username_ret);
    free (*password_ret);
    return -1;
  }

  return 0;
}
Esempio n. 21
0
/**
 * xmlXIncludeLoadDoc:
 * @ctxt:  the XInclude context
 * @url:  the associated URL
 * @nr:  the xinclude node number
 *
 * Load the document, and store the result in the XInclude context
 */
static void
xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
    xmlDocPtr doc;
    xmlURIPtr uri;
    xmlChar *URL;
    xmlChar *fragment = NULL;
    int i;
    /*
     * Check the URL and remove any fragment identifier
     */
    uri = xmlParseURI((const char *)url);
    if (uri == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: invalid value URI %s\n", url);
        return;
    }
    if (uri->fragment != NULL) {
        fragment = (xmlChar *) uri->fragment;
        uri->fragment = NULL;
    }
    URL = xmlSaveUri(uri);
    xmlFreeURI(uri);
    if (URL == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: invalid value URI %s\n", url);
        if (fragment != NULL)
            xmlFree(fragment);
        return;
    }

    /*
     * Handling of references to the local document are done
     * directly through ctxt->doc.
     */
    if ((URL[0] == 0) || (URL[0] == '#')) {
        doc = NULL;
        goto loaded;
    }

    /*
     * Prevent reloading twice the document.
     */
    for (i = 0; i < ctxt->docNr; i++) {
        if (xmlStrEqual(URL, ctxt->urlTab[i])) {
            doc = ctxt->docTab[i];
            goto loaded;
        }
    }
    /*
     * Load it.
     */
    doc = xmlParseFile((const char *)URL);
    if (doc == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: could not load %s\n", URL);
        xmlFree(URL);
        if (fragment != NULL)
            xmlFree(fragment);
        return;
    }
    xmlXIncludeAddDoc(ctxt, doc, URL);

loaded:
    if (fragment == NULL) {
        /*
         * Add the top children list as the replacement copy.
         */
        if (doc == NULL)
        {
            /* Hopefully a DTD declaration won't be copied from
             * the same document */
            ctxt->repTab[nr] = xmlCopyNodeList(ctxt->doc->children);
        } else {
            ctxt->repTab[nr] = xmlXIncludeCopyNodeList(ctxt, ctxt->doc,
                               doc, doc->children);
        }
    } else {
        /*
         * Computes the XPointer expression and make a copy used
         * as the replacement copy.
         */
        xmlXPathObjectPtr xptr;
        xmlXPathContextPtr xptrctxt;
        xmlNodeSetPtr set;

        if (doc == NULL) {
            xptrctxt = xmlXPtrNewContext(ctxt->doc, ctxt->incTab[nr], NULL);
        } else {
            xptrctxt = xmlXPtrNewContext(doc, NULL, NULL);
        }
        if (xptrctxt == NULL) {
            xmlGenericError(xmlGenericErrorContext,
                            "XInclude: could create XPointer context\n");
            xmlFree(URL);
            xmlFree(fragment);
            return;
        }
        xptr = xmlXPtrEval(fragment, xptrctxt);
        if (xptr == NULL) {
            xmlGenericError(xmlGenericErrorContext,
                            "XInclude: XPointer evaluation failed: #%s\n",
                            fragment);
            xmlXPathFreeContext(xptrctxt);
            xmlFree(URL);
            xmlFree(fragment);
            return;
        }
        switch (xptr->type) {
        case XPATH_UNDEFINED:
        case XPATH_BOOLEAN:
        case XPATH_NUMBER:
        case XPATH_STRING:
        case XPATH_POINT:
        case XPATH_USERS:
        case XPATH_XSLT_TREE:
            xmlGenericError(xmlGenericErrorContext,
                            "XInclude: XPointer is not a range: #%s\n",
                            fragment);
            xmlXPathFreeContext(xptrctxt);
            xmlFree(URL);
            xmlFree(fragment);
            return;
        case XPATH_NODESET:
        case XPATH_RANGE:
        case XPATH_LOCATIONSET:
            break;
        }
        set = xptr->nodesetval;
        if (set != NULL) {
            for (i = 0; i < set->nodeNr; i++) {
                if (set->nodeTab[i] == NULL)
                    continue;
                switch (set->nodeTab[i]->type) {
                case XML_TEXT_NODE:
                case XML_CDATA_SECTION_NODE:
                case XML_ELEMENT_NODE:
                case XML_ENTITY_REF_NODE:
                case XML_ENTITY_NODE:
                case XML_PI_NODE:
                case XML_COMMENT_NODE:
                case XML_DOCUMENT_NODE:
                case XML_HTML_DOCUMENT_NODE:
#ifdef LIBXML_DOCB_ENABLED
                case XML_DOCB_DOCUMENT_NODE:
#endif
                    continue;
                case XML_ATTRIBUTE_NODE:
                    xmlGenericError(xmlGenericErrorContext,
                                    "XInclude: XPointer selects an attribute: #%s\n",
                                    fragment);
                    set->nodeTab[i] = NULL;
                    continue;
                case XML_NAMESPACE_DECL:
                    xmlGenericError(xmlGenericErrorContext,
                                    "XInclude: XPointer selects a namespace: #%s\n",
                                    fragment);
                    set->nodeTab[i] = NULL;
                    continue;
                case XML_DOCUMENT_TYPE_NODE:
                case XML_DOCUMENT_FRAG_NODE:
                case XML_NOTATION_NODE:
                case XML_DTD_NODE:
                case XML_ELEMENT_DECL:
                case XML_ATTRIBUTE_DECL:
                case XML_ENTITY_DECL:
                case XML_XINCLUDE_START:
                case XML_XINCLUDE_END:
                    xmlGenericError(xmlGenericErrorContext,
                                    "XInclude: XPointer selects unexpected nodes: #%s\n",
                                    fragment);
                    set->nodeTab[i] = NULL;
                    set->nodeTab[i] = NULL;
                    continue; /* for */
                }
            }
        }
        ctxt->repTab[nr] = xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr);
        xmlXPathFreeObject(xptr);
        xmlXPathFreeContext(xptrctxt);
        xmlFree(fragment);
    }
    xmlFree(URL);
}
Esempio n. 22
0
URI::URI() {
    const gchar *in = "";
    _impl = Impl::create(xmlParseURI(in));
}
Esempio n. 23
0
/**
 * xmlXIncludeLoadTxt:
 * @ctxt:  the XInclude context
 * @url:  the associated URL
 * @nr:  the xinclude node number
 *
 * Load the content, and store the result in the XInclude context
 */
static void
xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
    xmlParserInputBufferPtr buf;
    xmlNodePtr node;
    xmlURIPtr uri;
    xmlChar *URL;
    int i;
    /*
     * Check the URL and remove any fragment identifier
     */
    uri = xmlParseURI((const char *)url);
    if (uri == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: invalid value URI %s\n", url);
        return;
    }
    if (uri->fragment != NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: fragment identifier forbidden for text: %s\n",
                        uri->fragment);
        xmlFreeURI(uri);
        return;
    }
    URL = xmlSaveUri(uri);
    xmlFreeURI(uri);
    if (URL == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: invalid value URI %s\n", url);
        return;
    }

    /*
     * Handling of references to the local document are done
     * directly through ctxt->doc.
     */
    if (URL[0] == 0) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: text serialization of document not available\n");
        xmlFree(URL);
        return;
    }

    /*
     * Prevent reloading twice the document.
     */
    for (i = 0; i < ctxt->txtNr; i++) {
        if (xmlStrEqual(URL, ctxt->txturlTab[i])) {
            node = xmlCopyNode(ctxt->txtTab[i], 1);
            goto loaded;
        }
    }
    /*
     * Load it.
     * Issue 62: how to detect the encoding
     */
    buf = xmlParserInputBufferCreateFilename((const char *)URL, 0);
    if (buf == NULL) {
        xmlGenericError(xmlGenericErrorContext,
                        "XInclude: could not load %s\n", URL);
        xmlFree(URL);
        return;
    }
    node = xmlNewText(NULL);

    /*
     * Scan all chars from the resource and add the to the node
     */
    while (xmlParserInputBufferRead(buf, 128) > 0) {
        int len;
        const xmlChar *content;

        content = xmlBufferContent(buf->buffer);
        len = xmlBufferLength(buf->buffer);
        for (i = 0; i < len; i++) {
            /*
             * TODO: if the encoding issue is solved, scan UTF8 chars instead
             */
            if (!IS_CHAR(content[i])) {
                xmlGenericError(xmlGenericErrorContext,
                                "XInclude: %s contains invalid char %d\n", URL, content[i]);
            } else {
                xmlNodeAddContentLen(node, &content[i], 1);
            }
        }
        xmlBufferShrink(buf->buffer, len);
    }
    xmlFreeParserInputBuffer(buf);
    xmlXIncludeAddTxt(ctxt, node, URL);

loaded:
    /*
     * Add the element as the replacement copy.
     */
    ctxt->repTab[nr] = node;
    xmlFree(URL);
}