gboolean
empathy_xml_validate (xmlDoc      *doc,
    const gchar *dtd_filename)
{
  gchar *path;
  xmlChar *escaped;
  xmlValidCtxt  cvp;
  xmlDtd *dtd;
  gboolean ret;

  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "libempathy",
         dtd_filename, NULL);
  if (!g_file_test (path, G_FILE_TEST_EXISTS))
    {
      g_free (path);
      path = g_build_filename (DATADIR, "empathy", dtd_filename, NULL);
    }

  DEBUG ("Loading dtd file %s", path);

  /* The list of valid chars is taken from libxml. */
  escaped = xmlURIEscapeStr ((const xmlChar *) path,
    (const xmlChar *)":@&=+$,/?;");
  g_free (path);

  memset (&cvp, 0, sizeof (cvp));
  dtd = xmlParseDTD (NULL, escaped);
  ret = xmlValidateDtd (&cvp, doc, dtd);

  xmlFree (escaped);
  xmlFreeDtd (dtd);

  return ret;
}
Exemple #2
0
static String _xmlreader_get_valid_file_path(const char *source) {
  int isFileUri = 0;

  xmlURI *uri = xmlCreateURI();
  xmlChar *escsource = xmlURIEscapeStr((xmlChar*)source, (xmlChar*)":");
  xmlParseURIReference(uri, (char*)escsource);
  xmlFree(escsource);

  if (uri->scheme != NULL) {
    /* absolute file uris - libxml only supports localhost or empty host */
    if (strncasecmp(source, "file:///",8) == 0) {
      isFileUri = 1;
      source += 7;
    } else if (strncasecmp(source, "file://localhost/",17) == 0) {
      isFileUri = 1;
      source += 16;
    }
  }

  String file_dest = String(source, CopyString);
  if ((uri->scheme == NULL || isFileUri)) {
    file_dest = File::TranslatePath(file_dest);
  }
  xmlFreeURI(uri);
  return file_dest;
}
Exemple #3
0
/**
 * Converts the passed-in string from UTF-8 to ASCII for http transmisison.
 *
 * @param pczInString String to convert
 *
 * @return The converted string which MUST BE FREED BY THE CALLER.
 */
static gchar *
convertToASCII(const gchar *pczInString)
{
  // for UTF-8 to ASCII conversions
  setlocale(LC_CTYPE, "en_US");

  GError * pError = NULL;

  gsize szBytesRead = 0;
  gsize szBytesWritten = 0;

  gchar * pcConvertedString = g_convert(pczInString,
                                        strlen(pczInString),
                                        "ASCII//TRANSLIT",
                                        "UTF-8",
                                        &szBytesRead,
                                        &szBytesWritten,
                                        &pError);

  if (pError)
    {
      LXW_LOG(LXW_ERROR, "yahooutil::convertToASCII(%s): Error: %s", 
              pczInString, pError->message);

      g_error_free(pError);

      pcConvertedString = g_strndup(pczInString, strlen(pczInString));
    }

  // now escape space, if any
  xmlChar * pxEscapedString = xmlURIEscapeStr((const xmlChar *)pcConvertedString, NULL);

  if (pxEscapedString)
    {
      // release ConvertedString, reset it, then release EscapedString.
      // I know it's confusing, but keeps everything as a gchar and g_free
      g_free(pcConvertedString);

      pcConvertedString = g_strndup((const gchar *)pxEscapedString, 
                                    strlen((const gchar *)pxEscapedString));

      xmlFree(pxEscapedString);
    }

  // restore locale to default
  setlocale(LC_CTYPE, "");

  return pcConvertedString;
}
Exemple #4
0
/* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a
	common function in libxml extension as code is common to a few xml extensions */
char *_xmlreader_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) {
	xmlURI *uri;
	xmlChar *escsource;
	char *file_dest;
	int isFileUri = 0;

	uri = xmlCreateURI();
	escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":");
	xmlParseURIReference(uri, (const char *)escsource);
	xmlFree(escsource);

	if (uri->scheme != NULL) {
		/* absolute file uris - libxml only supports localhost or empty host */
		if (strncasecmp(source, "file:///",8) == 0) {
			isFileUri = 1;
#ifdef PHP_WIN32
			source += 8;
#else
			source += 7;
#endif
		} else if (strncasecmp(source, "file://localhost/",17) == 0) {
			isFileUri = 1;
#ifdef PHP_WIN32
			source += 17;
#else
			source += 16;
#endif
		}
	}

	file_dest = source;

	if ((uri->scheme == NULL || isFileUri)) {
		if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) {
			xmlFreeURI(uri);
			return NULL;
		}
		file_dest = resolved_path;
	}

	xmlFreeURI(uri);

	return file_dest;
}
Exemple #5
0
/**
 * exsltStrEncodeUriFunction:
 * @ctxt: an XPath parser context
 * @nargs: the number of arguments
 *
 * URI-Escapes a string
 */
static void
exsltStrEncodeUriFunction (xmlXPathParserContextPtr ctxt, int nargs) {
    int escape_all = 1, str_len = 0;
    xmlChar *str = NULL, *ret = NULL, *tmp;

    if ((nargs < 2) || (nargs > 3)) {
	xmlXPathSetArityError(ctxt);
	return;
    }

    if (nargs >= 3) {
        /* check for UTF-8 if encoding was explicitly given;
           we don't support anything else yet */
        tmp = xmlXPathPopString(ctxt);
        if (xmlUTF8Strlen(tmp) != 5 || xmlStrcmp((const xmlChar *)"UTF-8",tmp)) {
	    xmlXPathReturnEmptyString(ctxt);
	    xmlFree(tmp);
	    return;
	}
	xmlFree(tmp);
    }

    escape_all = xmlXPathPopBoolean(ctxt);

    str = xmlXPathPopString(ctxt);
    str_len = xmlUTF8Strlen(str);

    if (str_len == 0) {
	xmlXPathReturnEmptyString(ctxt);
	xmlFree(str);
	return;
    }

    ret = xmlURIEscapeStr(str,(const xmlChar *)(escape_all?"-_.!~*'()":"-_.!~*'();/?:@&=+$,[]"));
    xmlXPathReturnString(ctxt, ret);

    if (str != NULL)
	xmlFree(str);
}
Exemple #6
0
/*
 *  set_common_attributes
 *
 *  Set the on event attributes, 
 *
 *  This should be called by every prompt adding function.
 */
void set_common_attributes(struct prompt_add_args* args, xmlNodePtr input){

    if (args->rule->tabindex > 0){
        char* intbuf;
        asprintf(&intbuf, "%d", args->rule->tabindex);
        xmlNewProp(input, "tabindex", intbuf);
        free(intbuf);
    } 

    // class gets inserted to a list
    if ((args->rule->el_class != NULL) && args->rule->el_class[0]!='\0'){
        append_class(input, args->rule->el_class);
    }    
    // Add a class for the pg attribute name
    // but remove the [n] from base[n]
    char* fieldname;
    asprintf(&fieldname, "%s", args->rule->fieldname);
    int k;
    for (k=0; k<strlen(fieldname); k++){
        if (fieldname[k] == '[') fieldname[k] = '\0';
    }
    append_class(input, fieldname);
    free(fieldname);
    fieldname = NULL;

    // add the pgtype_datum as a json attribute 
    if ((args->pgtype != NULL) && (args->rule->publish_pgtype)){
        char* pgtype_json = pgtype_datum_to_json(args->pgtype);
        if (pgtype_json != NULL){
            char* escaped_pgtype = xmlURIEscapeStr(pgtype_json, NULL);
            if (escaped_pgtype != NULL){
                xmlNewProp(input, "pgtype", escaped_pgtype);
                free(escaped_pgtype);
            }    
            free(pgtype_json);
        }    
    }

    if (has_data(args->rule->regex_pattern)){
        xmlNewProp(input, "pattern", args->rule->regex_pattern);
    }    

    if (has_data(args->rule->onfocus)) add_event(args, input, 
        "onfocus", args->rule->onfocus);

    if (has_data(args->rule->onblur))  add_event(args, input, 
        "onblur", args->rule->onblur);

    if (has_data(args->rule->onchange))  add_event(args, input, 
        "onchange", args->rule->onchange);

    if (has_data(args->rule->onselect))  add_event(args, input, 
        "onselect", args->rule->onselect);

    if (has_data(args->rule->onclick))  add_event(args, input, 
        "onclick", args->rule->onclick);

    if (has_data(args->rule->ondblclick))  add_event(args, input, 
        "ondblclick", args->rule->ondblclick);

    if (has_data(args->rule->onmousedown))  add_event(args, input, 
        "onmousedown", args->rule->onmousedown);

    if (has_data(args->rule->onmouseup))  add_event(args, input, 
        "onmouseup", args->rule->onmouseup);

    if (has_data(args->rule->onmouseover))  add_event(args, input, 
        "onmouseover", args->rule->onmouseover);

    if (has_data(args->rule->onmouseout))  add_event(args, input, 
        "onmouseout", args->rule->onmouseout);

    if (has_data(args->rule->onkeypress))  add_event(args, input, 
        "onkeypress", args->rule->onkeypress);

    if (has_data(args->rule->onkeydown))  add_event(args, input, 
        "onkeydown", args->rule->onkeydown);

    if (has_data(args->rule->onkeyup))  add_event(args, input, 
        "onkeyup", args->rule->onkeyup);

    if (has_data(args->rule->src)) add_event(args, input, 
        "src", args->rule->src);

    return;
}
Exemple #7
0
xmlNodePtr add_text_array(struct prompt_add_args* args){

    xmlNodePtr text_array;
    text_array = xmlNewChild(args->child_of, NULL, "ol", NULL);
    xmlNewProp(text_array, "id", args->fname);

    char** array_elements = parse_pg_array(args->fvalue);

    if (array_elements != NULL){

        int n;
        for(n=0; array_elements[n] != NULL; n++){
            xmlNodePtr array_item;
            array_item = xmlNewChild(text_array, NULL, "li", NULL);
    
            // create a name like base[0], base[1], etc.
            char* fname_buf;
            asprintf(&fname_buf, "%s[%d]", args->fname, n);

            struct prompt_add_args newargs = (struct prompt_add_args){
                .hargs = args->hargs,
                .t_action = args->t_action,
                .rule = args->rule,
                .pgtype = args->pgtype,
                .row_index = n,
                .child_of = array_item,
                .fname = fname_buf,
                .fvalue = array_elements[n]
            };
            args->rule->publish_pgtype = false;
            
            xmlNodePtr new_input = add_input_text( &newargs );
            
            set_common_attributes(&newargs, new_input);

            free(fname_buf);
        }

        free(array_elements);
    }    

    // add an add new item button.
    char* button_name;
    asprintf(&button_name, "%s_btn", args->fname);

    xmlNodePtr button;
    button = xmlNewTextChild(args->child_of, NULL, "button", "+Add Element");
    xmlNewProp(button, "name", button_name);
    xmlNewProp(button, "id", button_name);
    // A button type button, not a reset or submit, but perfect for js.
    xmlNewProp(button, "type", "button");  

    if (args->rule != NULL){
        char* args_rule_js = json_add_element_args(NULL, args->rule, NULL);
        if (args_rule_js != NULL){
            char* args_rule_esc = xmlURIEscapeStr(args_rule_js, NULL); 
            char* event_esc;
            asprintf(&event_esc, "%s('%s');", "add_array_input", args_rule_esc);

            xmlNewProp(button, "onclick", event_esc); 
            free(event_esc);
            free(args_rule_esc);
            free(args_rule_js);
        }    
    }
    free(button_name);
    return text_array;
}
static gboolean
_save_data_track_xml (xmlTextWriter *project,
                      RejillaBurnSession *session)
{
    gchar *uri;
    gint success;
    GSList *iter;
    GSList *tracks;
    GSList *grafts;
    gchar *filename;
    RejillaTrackDataCfg *track;

    tracks = rejilla_burn_session_get_tracks (session);
    track = REJILLA_TRACK_DATA_CFG (tracks->data);

    filename = rejilla_track_data_cfg_get_icon_path (track);
    if (filename) {
        /* Write the icon if any */
        success = xmlTextWriterWriteElement (project, (xmlChar *) "icon", (xmlChar *) filename);
        g_free (filename);
        if (success < 0)
            return FALSE;
    }

    grafts = rejilla_track_data_get_grafts (REJILLA_TRACK_DATA (track));
    for (; grafts; grafts = grafts->next) {
        RejillaGraftPt *graft;

        graft = grafts->data;

        success = xmlTextWriterStartElement (project, (xmlChar *) "graft");
        if (success < 0)
            return FALSE;

        success = xmlTextWriterWriteElement (project, (xmlChar *) "path", (xmlChar *) graft->path);
        if (success < 0)
            return FALSE;

        if (graft->uri) {
            xmlChar *escaped;

            escaped = (unsigned char *) g_uri_escape_string (graft->uri, NULL, FALSE);
            success = xmlTextWriterWriteElement (project, (xmlChar *) "uri", escaped);
            g_free (escaped);
            if (success < 0)
                return FALSE;
        }

        success = xmlTextWriterEndElement (project); /* graft */
        if (success < 0)
            return FALSE;
    }

    /* save excluded uris */
    iter = rejilla_track_data_get_excluded_list (REJILLA_TRACK_DATA (track));
    for (; iter; iter = iter->next) {
        xmlChar *escaped;

        escaped = xmlURIEscapeStr ((xmlChar *) iter->data, NULL);
        success = xmlTextWriterWriteElement (project, (xmlChar *) "excluded", (xmlChar *) escaped);
        g_free (escaped);
        if (success < 0)
            return FALSE;
    }

    /* save restored uris */
    iter = rejilla_track_data_cfg_get_restored_list (track);
    for (; iter; iter = iter->next) {
        uri = iter->data;
        success = xmlTextWriterWriteElement (project, (xmlChar *) "restored", (xmlChar *) uri);
        if (success < 0)
            return FALSE;
    }

    /* NOTE: we don't write symlinks and unreadable they are useless */
    return TRUE;
}