Exemple #1
0
/**
 * xmp_parse_context_new:
 * @parser: a #XMPParser
 * @flags: one or more #XMPParseFlags
 * @user_data: user data to pass to #GMarkupParser functions
 * @user_data_dnotify: user data destroy notifier called when the
 * parse context is freed
 *
 * Creates a new XMP parse context.  A parse context is used to parse
 * documents.  You can feed any number of documents containing XMP
 * metadata into a context, as long as no errors occur; once an error
 * occurs, the parse context can't continue to parse text (you have to
 * free it and create a new parse context).
 *
 * Return value: a new #XMPParseContext
 **/
XMPParseContext *
xmp_parse_context_new (const XMPParser *parser,
                       XMPParseFlags    flags,
                       gpointer         user_data,
                       GDestroyNotify   user_data_dnotify)
{
  XMPParseContext *context;

  g_return_val_if_fail (parser != NULL, NULL);

  context = g_slice_new0 (XMPParseContext);

  context->parser = parser;
  context->flags = flags;
  context->user_data = user_data;
  context->user_data_dnotify = user_data_dnotify;

  context->markup_context = g_markup_parse_context_new (&markup_xmp_parser,
                                                        0, context, NULL);
  context->state = STATE_START;
  context->depth = 0;

  context->namespaces = NULL;
  context->xmp_prefix = NULL;
  context->xmp_prefix_len = 0;
  context->rdf_prefix = NULL;
  context->rdf_prefix_len = 0;

  context->property = NULL;
  context->property_ns = NULL;
  context->prop_value = NULL;
  context->prop_cur_value = -1;
  context->prop_max_value = 0;
  context->prop_missing_value = FALSE;

  context->saved_state = STATE_ERROR;
  context->saved_depth = 0;

  return context;
}
Exemple #2
0
static void list_folder_callback(struct session_data *session,
					GError *err, void *user_data)
{
	struct transfer_data *transfer = session->pending->data;
	GMarkupParseContext *ctxt;
	DBusMessage *reply;
	DBusMessageIter iter, array;
	int i;

	reply = dbus_message_new_method_return(session->msg);

	if (transfer->filled == 0)
		goto done;

	for (i = transfer->filled - 1; i > 0; i--) {
		if (transfer->buffer[i] != '\0')
			break;

		transfer->filled--;
	}

	dbus_message_iter_init_append(reply, &iter);
	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_TYPE_ARRAY_AS_STRING
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
	ctxt = g_markup_parse_context_new(&parser, 0, &array, NULL);
	g_markup_parse_context_parse(ctxt, transfer->buffer,
					transfer->filled, NULL);
	g_markup_parse_context_free(ctxt);
	dbus_message_iter_close_container(&iter, &array);

	transfer->filled = 0;

done:
	g_dbus_send_message(session->conn, reply);
	dbus_message_unref(session->msg);
	session->msg = NULL;
}
Exemple #3
0
static void
get_saved_plugin_data (void)
{
  gchar *pspirc_name = gimp_personal_rc_file (PSPIRC);
  gchar *contents;
  gsize length;
  GMarkupParseContext *context;
  static GMarkupParser parser = {
    start_element_handler,
    end_element_handler,
    NULL,
    NULL,
    NULL
  };
  UserData user_data;

  plug_in_hash = g_hash_table_new (g_str_hash, g_str_equal);
  entry_hash = g_hash_table_new (g_str_hash, g_str_equal);

  /* Read data for the PS plug-ins found last time */
  if (!g_file_get_contents (pspirc_name, &contents, &length, NULL))
    {
      g_free (pspirc_name);
      return;
    }

  user_data.pspi = NULL;
  context = g_markup_parse_context_new (&parser, 0, &user_data, NULL);

  if (!g_markup_parse_context_parse (context, contents, length, NULL))
    {
      g_markup_parse_context_free (context);
      g_free (pspirc_name);
      return;
    }

  g_free (contents);
  g_markup_parse_context_end_parse (context, NULL);
  g_markup_parse_context_free (context);
}
void
xml_loadsave_live_game_read(const gchar *filename, LiveGame *live_game)
{
#ifdef DEBUG
    printf("xml_loadsave_live_game_read\n");
#endif

    GMarkupParser parser = {xml_loadsave_live_game_start_element,
			    xml_loadsave_live_game_end_element,
			    xml_loadsave_live_game_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;

    context = 
	g_markup_parse_context_new(&parser, 0, NULL, NULL);

    if(!g_file_get_contents(filename, &file_contents, &length, &error))
    {
	debug_print_message("xml_loadsave_live_game_read: error reading file %s\n", filename);
	misc_print_error(&error, TRUE);
    }

    lgame = live_game;
    lgame->team_names[0] = 
	lgame->team_names[1] = NULL;

    if(g_markup_parse_context_parse(context, file_contents, length, &error))
    {
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);
	g_free(file_contents);
    }
    else
    {
	debug_print_message("xml_loadsave_live_game_read: error parsing file %s\n", filename);
	misc_print_error(&error, TRUE);
    }
}
static gboolean
parse_file_gmarkup (const gchar          *filename,
		    const GMarkupParser  *parser,
		    gpointer             data,
		    GError              **err)
{
    GMarkupParseContext *context = NULL;
    gchar *contents = NULL;
    gboolean result = TRUE;
    gsize len;

    if (!g_file_get_contents (filename, &contents, &len, err))
    {
	result = FALSE;
	goto out;
    }
    
    context = g_markup_parse_context_new (parser, 0, data, NULL);

    if (!g_markup_parse_context_parse (context, contents, len, err))
    {
	result = FALSE;
	goto out;
    }

    if (!g_markup_parse_context_end_parse (context, err))
    {
	result = FALSE;
	goto out;
    }

out:
    if (contents)
	g_free (contents);

    if (context)
	g_markup_parse_context_free (context);

    return result;
}
Exemple #6
0
static char *
markup_test (const char *s)
{
	GMarkupParser *parser = g_new0 (GMarkupParser, 1);
	GMarkupParseContext *context;
	GError *error = NULL;
	
	context = g_markup_parse_context_new (parser, 0, 0, 0);

	g_markup_parse_context_parse (context, s, strlen (s), &error);
	g_markup_parse_context_free (context);

	if (error != NULL){
		char *msg = g_strdup (error->message);
		g_error_free (error);

		g_free (parser);
		return msg;
	}
	g_free (parser);
	return NULL;
}
Exemple #7
0
xmlnode *xmlnode_from_str(const char *str, size_t size)
{
	struct _xmlnode_parser_data *xpd = g_new0(struct _xmlnode_parser_data, 1);
	xmlnode *ret;
	GMarkupParseContext *context;
	size_t real_size = size == -1 ? strlen(str) : size;

	context = g_markup_parse_context_new(&xmlnode_parser, 0, xpd, NULL);

	if(!g_markup_parse_context_parse(context, str, real_size, NULL)) {
		while(xpd->current && xpd->current->parent)
			xpd->current = xpd->current->parent;
		if(xpd->current)
			xmlnode_free(xpd->current);
		xpd->current = NULL;
	}
	g_markup_parse_context_free(context);

	ret = xpd->current;
	g_free(xpd);
	return ret;
}
Exemple #8
0
int dmtxplugin_xml_parse_len(const char *data)
{
	GMarkupParseContext *ctx;
	struct context_len_data ctx_data;
	int size, ret;
	GError *error;

	size = strlen(data);
	//printf("XML parser: start parsing with data size %d\n", size);

	ctx_data.found = FALSE;
	ctx_data.len = 0;
	ctx = g_markup_parse_context_new(&len_parser, 0, &ctx_data, NULL);

        ret = g_markup_parse_context_parse(ctx, data, size, &error);
	if ( ret == FALSE)
	        printf("parser returned %d error : %s \n", ret, error->message );

	g_markup_parse_context_free(ctx);

	return ctx_data.len;
}
Exemple #9
0
/**
 * Parse config file
 *
 * @retval TRUE if file is parsed
 * @retval FALSE if failed to parse file
 */
gboolean conf_parse_file (ConfData *conf, const gchar *filename)
{
    gchar *contents;
    gsize  length;
    GError *error;
    GMarkupParseContext *context;

    const GMarkupParser parser = {
        start_element_handler,
        end_element_handler,
        text_handler,
        NULL,
        error_handler
    };

    error = NULL;
    if (!g_file_get_contents (filename, &contents, &length, &error)) {
        LOG_err (CONF, "%s", error->message);
        g_error_free (error);
        return FALSE;
    }

    context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, conf, NULL);

    if (!g_markup_parse_context_parse (context, contents, (gssize)length, NULL)) {
        g_markup_parse_context_free (context);
        return FALSE;
    }

    if (!g_markup_parse_context_end_parse (context, NULL)) {
        g_markup_parse_context_free (context);
        return FALSE;
    }

    g_markup_parse_context_free (context);
    g_free (contents);

    return TRUE;
}
Exemple #10
0
static int event_report_close(void *obj)
{
	struct mns_session *mns = obj;
	GMarkupParseContext *ctxt;
	struct map_event *event;

	DBG("");

	event = g_new0(struct map_event, 1);
	ctxt = g_markup_parse_context_new(&event_report_parser, 0, event,
									NULL);
	g_markup_parse_context_parse(ctxt, mns->buffer->str, mns->buffer->len,
									NULL);
	g_markup_parse_context_free(ctxt);

	map_dispatch_event(mns->mas_instance_id, mns->remote_address, event);
	map_event_free(event);

	reset_request(mns);

	return 0;
}
static GHashTable *
read_country_codes (const gchar *country_codes_file,
                    GCancellable *cancellable,
                    GError **error)
{
	GHashTable *table = NULL;
	GMarkupParseContext *ctx;
	char *buf;
	gsize buf_len;

	/* Set domain to iso_3166 for country name translation */
	bindtextdomain ("iso_3166", ISO_CODES_LOCALESDIR);
	bind_textdomain_codeset ("iso_3166", "UTF-8");

	if (!g_file_get_contents (country_codes_file, &buf, &buf_len, error)) {
		g_prefix_error (error,
		                "Failed to load '%s' from 'iso-codes': ",
		                country_codes_file);
		return NULL;
	}

	table = g_hash_table_new_full (g_str_hash,
	                               g_str_equal,
	                               g_free,
	                               (GDestroyNotify)nma_country_info_unref);

	ctx = g_markup_parse_context_new (&iso_3166_parser, 0, table, NULL);
	if (!g_markup_parse_context_parse (ctx, buf, buf_len, error)) {
		g_prefix_error (error,
		                "Failed to parse '%s' from 'iso-codes': ",
		                country_codes_file);
		g_hash_table_destroy (table);
		return NULL;
	}

	g_markup_parse_context_free (ctx);
	g_free (buf);
	return table;
}
void
xml_loadsave_users_read(const gchar *dirname, const gchar *basename)
{
#ifdef DEBUG
    printf("xml_loadsave_users_read\n");
#endif

    GMarkupParser parser = {xml_loadsave_users_start_element,
			    xml_loadsave_users_end_element,
			    xml_loadsave_users_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;
    gchar file[SMALL];

    sprintf(file, "%s%s%s___users.xml", dirname, G_DIR_SEPARATOR_S, basename);

    context = 
	g_markup_parse_context_new(&parser, 0, NULL, NULL);

    if(!g_file_get_contents(file, &file_contents, &length, &error))
    {
	debug_print_message("xml_loadsave_users_read: error reading file %s\n", file);
	misc_print_error(&error, TRUE);
    }

    if(g_markup_parse_context_parse(context, file_contents, length, &error))
    {
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);
	g_free(file_contents);
    }
    else
    {
	debug_print_message("xml_loadsave_users_read: error parsing file %s\n", file);
	misc_print_error(&error, TRUE);
    }
}
Exemple #13
0
bool SettingsLoad (SettingsPersist * psSettingsData) {
  bool boSuccess = FALSE;
  GMarkupParseContext * psParseContext;
  GMarkupParser * psParser;
  FILE * fhFile;
  gchar szFileBuffer[FILE_BUFFER_SIZE];
  int nRead;

  psSettingsData->nLevel = 0;

  psParser = g_new0 (GMarkupParser, 1);
  psParser->start_element = StartElement;
  psParser->end_element = EndElement;
  psParser->text = Text;
  psParser->passthrough = NULL;
  psParser->error = NULL;

  fhFile = fopen (psSettingsData->szFilename->str, "rb");
  if (fhFile) {
    boSuccess = TRUE;
    psParseContext = g_markup_parse_context_new (psParser, 0, (gpointer)psSettingsData, DestroyUserData);

    nRead = fread (szFileBuffer, sizeof (char), FILE_BUFFER_SIZE, fhFile);
    while (boSuccess && (nRead > 0)) {
      boSuccess = g_markup_parse_context_parse (psParseContext, szFileBuffer, nRead, NULL);
      nRead = fread (szFileBuffer, sizeof (char), FILE_BUFFER_SIZE, fhFile);
    }

    if (boSuccess) {
      g_markup_parse_context_end_parse (psParseContext, NULL);
    }
    g_markup_parse_context_free (psParseContext);
    fclose (fhFile);
  }
  g_free (psParser);
  // The context is destroyed automatically by the parser

  return boSuccess;
}
Exemple #14
0
static void
languages_variant_init (const char *variant)
{
        gboolean res;
        gsize    buf_len;
        g_autofree char *buf = NULL;
        g_autofree char *filename = NULL;
        g_autoptr (GError) error = NULL;

        bindtextdomain (variant, ISO_CODES_LOCALESDIR);
        bind_textdomain_codeset (variant, "UTF-8");

        error = NULL;
        filename = g_strdup_printf (ISO_CODES_DATADIR "/%s.xml", variant);
        res = g_file_get_contents (filename,
                                   &buf,
                                   &buf_len,
                                   &error);
        if (res) {
                g_autoptr (GMarkupParseContext) ctx = NULL;
                GMarkupParser        parser = { languages_parse_start_tag, NULL, NULL, NULL, NULL };

                ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);

                error = NULL;
                res = g_markup_parse_context_parse (ctx, buf, buf_len, &error);

                if (! res) {
                        g_warning ("Failed to parse '%s': %s\n",
                                   filename,
                                   error->message);
                }
        } else {
                g_warning ("Failed to load '%s': %s\n",
                           filename,
                           error->message);
        }
}
static GHashTable *
parse_gschema_files (gchar    **files,
                     gboolean   byteswap,
                     GError   **error)
{
  GMarkupParser parser = { start_element, end_element, text };
  GMarkupParseContext *context;
  ParseState state = { byteswap, };
  const gchar *filename;

  context = g_markup_parse_context_new (&parser,
                                        G_MARKUP_PREFIX_ERROR_POSITION,
                                        &state, NULL);
  state.schemas = gvdb_hash_table_new (NULL, NULL);

  while ((filename = *files++) != NULL)
    {
      gchar *contents;
      gsize size;

      if (!g_file_get_contents (filename, &contents, &size, error))
        return FALSE;

      if (!g_markup_parse_context_parse (context, contents, size, error))
        {
          g_prefix_error (error, "%s: ", filename);
          return FALSE;
        }

      if (!g_markup_parse_context_end_parse (context, error))
        {
          g_prefix_error (error, "%s: ", filename);
          return FALSE;
        }
    }

  return state.schemas;
}
gboolean
mdm_settings_parse_schemas (const char  *file,
                            const char  *root,
                            GSList     **schemas)
{
        GMarkupParseContext *ctx;
        ParserInfo          *info;
        char                *contents;
        gsize                len;
        GError              *error;
        gboolean             res;

        g_return_val_if_fail (file != NULL, FALSE);
        g_return_val_if_fail (root != NULL, FALSE);

        g_assert (schemas != NULL);

        contents = NULL;
        error = NULL;
        res = g_file_get_contents (file, &contents, &len, &error);
        if (! res) {
                g_warning ("Unable to read schemas file: %s", error->message);
                g_error_free (error);
                return FALSE;
        }

        info = g_new0 (ParserInfo, 1);
        ctx = g_markup_parse_context_new (&parser, 0, info, NULL);
        g_markup_parse_context_parse (ctx, contents, len, NULL);

        *schemas = info->list;

        g_markup_parse_context_free (ctx);
        g_free (info);
        g_free (contents);

        return TRUE;
}
Exemple #17
0
static void
spell_iso_code_names_init (void)
{
	GError *err = NULL;
	gchar  *buf;
	gsize   buf_len;

	iso_code_names = g_hash_table_new_full (g_str_hash, g_str_equal,
						g_free, g_free);

	bindtextdomain ("iso_639", ISO_CODES_LOCALESDIR);
	bind_textdomain_codeset ("iso_639", "UTF-8");

	/* FIXME: We should read this in chunks and pass to the parser. */
	if (g_file_get_contents (ISO_CODES_DATADIR "/iso_639.xml", &buf, &buf_len, &err)) {
		GMarkupParseContext *ctx;
		GMarkupParser        parser = {
			spell_iso_codes_parse_start_tag,
			NULL, NULL, NULL, NULL
		};

		ctx = g_markup_parse_context_new (&parser, 0, NULL, NULL);
		if (!g_markup_parse_context_parse (ctx, buf, buf_len, &err)) {
			g_warning ("Failed to parse '%s': %s",
				   ISO_CODES_DATADIR"/iso_639.xml",
				   err->message);
			g_error_free (err);
		}

		g_markup_parse_context_free (ctx);
		g_free (buf);
	} else {
		g_warning ("Failed to load '%s': %s",
				ISO_CODES_DATADIR"/iso_639.xml", err->message);
		g_error_free (err);
	}
}
Exemple #18
0
LmParser *
lm_parser_new (LmParserMessageFunction function,
               gpointer                user_data,
               GDestroyNotify          notify)
{
    LmParser *parser;

    parser = g_new0 (LmParser, 1);
    if (!parser) {
        return NULL;
    }

    parser->m_parser = g_new0 (GMarkupParser, 1);
    if (!parser->m_parser) {
        g_free (parser);
        return NULL;
    }

    parser->function  = function;
    parser->user_data = user_data;
    parser->notify    = notify;

    parser->m_parser->start_element = parser_start_node_cb;
    parser->m_parser->end_element   = parser_end_node_cb;
    parser->m_parser->text          = parser_text_cb;
    parser->m_parser->error         = parser_error_cb;

    parser->context = g_markup_parse_context_new (parser->m_parser, 0,
                                                  parser, NULL);

    parser->cur_root = NULL;
    parser->cur_node = NULL;

    parser->incomplete = NULL;

    return parser;
}
Exemple #19
0
void profile_vorbis_load(void)
{
	gchar *filepath, *buf;
	GMarkupParser mp;
	GMarkupParseContext *mpc;

	mp.start_element = enc_get_element;
	mp.end_element = vorbis_end_element;
	mp.text = enc_get_value;
	mp.passthrough = NULL;
	mp.error = NULL;

	filepath = g_strconcat(home, "/.muse/vorbis.xml", NULL);
	g_file_get_contents(filepath, &buf, NULL, NULL);
	g_free(filepath);
	if(!buf)
		return;

	mpc = g_markup_parse_context_new(&mp, (GMarkupParseFlags) 0, NULL, NULL);
	g_markup_parse_context_parse(mpc, buf, -1, NULL);
	g_markup_parse_context_free(mpc);
	func("finito il parsing");

}	
Exemple #20
0
/* three profile_something_load zone */
void profile_lame_load(void)
{
	gchar *filepath, *buf;
	GMarkupParser mp;
	GMarkupParseContext *mpc;

	mp.start_element = enc_get_element;
	mp.end_element = lame_end_element;
	mp.text = enc_get_value;
	mp.passthrough = NULL;
	mp.error = NULL;

	filepath = g_strconcat(home, "/.muse/lame.xml", NULL);
	g_file_get_contents(filepath, &buf, NULL, NULL);
	g_free(filepath);
	if(!buf)
		return;
	
	/* f**k C++ and his cast */
	mpc = g_markup_parse_context_new(&mp, (GMarkupParseFlags) 0, NULL,  NULL);
	g_markup_parse_context_parse(mpc, buf, -1, NULL);
	g_markup_parse_context_free(mpc);

}	
Exemple #21
0
void profile_ice_load(void)
{
	gchar *filepath, *buf;
	GMarkupParser mp;
	GMarkupParseContext *mpc;
	
	mp.start_element = ice_get_element;
	mp.end_element = ice_end_element;
	mp.text = ice_get_value;
	mp.passthrough = NULL;
	mp.error = NULL;

	filepath = g_strconcat(home, "/.muse/ice.xml", NULL);
	g_file_get_contents(filepath, &buf, NULL, NULL);
	func("testo del file %s %s", filepath, buf);
	g_free(filepath);
	if(!buf)
		return;
	

	mpc = g_markup_parse_context_new(&mp, (GMarkupParseFlags) 0, NULL, NULL);
	g_markup_parse_context_parse(mpc, buf, -1, NULL);
	g_markup_parse_context_free(mpc);
}	
static int
__parse_message(const char *buf, TrepiaMessageType *type, GHashTable **info)
{
	TrepiaParserData *parser_data = g_new0(TrepiaParserData, 1);
	GMarkupParseContext *context;
	GHashTable *keys;

	keys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	parser_data->keys = keys;
	parser_data->type = type;

	context = g_markup_parse_context_new(&accounts_parser, 0,
										 parser_data, __free_parser_data);

	if (!g_markup_parse_context_parse(context, buf, strlen(buf), NULL)) {
		g_markup_parse_context_free(context);
		g_free(parser_data);
		g_hash_table_destroy(keys);

		return 1;
	}

	if (!g_markup_parse_context_end_parse(context, NULL)) {
		g_markup_parse_context_free(context);
		g_free(parser_data);
		g_hash_table_destroy(keys);

		return 1;
	}

	g_markup_parse_context_free(context);
	g_free(parser_data);
	*info = keys;

	return 0;
}
Exemple #23
0
gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup)
{
	GMarkupParseContext *context;
	gboolean ret = TRUE;
	GQParserData *parser_data;

	parser_data = g_new0(GQParserData, 1);

	parser_data->startup = startup;
	options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL);

	context = g_markup_parse_context_new(&parser, 0, parser_data, NULL);

	if (g_markup_parse_context_parse(context, buf, size, NULL) == FALSE)
		{
		ret = FALSE;
		DEBUG_1("Parse failed");
		}

	g_free(parser_data);

	g_markup_parse_context_free(context);
	return ret;
}
Exemple #24
0
XMLNode *
ibus_xml_parse_buffer (const gchar *buffer)
{
    gboolean retval;
    GError *error = NULL;

    GMarkupParseContext *context;
    XMLNode *node;

    const static GMarkupParser root_parser = {
        _start_root_element_cb,
        _end_element_cb,
        _text_cb,
        0,
        0,
    };

    context = g_markup_parse_context_new (&root_parser, 0, &node, 0);

    do {
        retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), &error);
        if (!retval)
            break;

        retval = g_markup_parse_context_end_parse (context, &error);
        if (!retval)
            break;
        g_markup_parse_context_free (context);
        return node;
    } while (0);

    g_warning ("Parse buffer failed: %s", error->message);
    g_error_free (error);
    g_markup_parse_context_free (context);
    return NULL;
}
static sdp_record_t *sdp_xml_parse_record(const char *data, int size)
{
    GMarkupParseContext *ctx;
    struct context_data *ctx_data;
    sdp_record_t *record;

    ctx_data = malloc(sizeof(*ctx_data));
    if (!ctx_data)
        return NULL;


    record = sdp_record_alloc();
    if (!record) {
        free(ctx_data);
        return NULL;
    }

    memset(ctx_data, 0, sizeof(*ctx_data));
    ctx_data->record = record;

    ctx = g_markup_parse_context_new(&parser, 0, ctx_data, NULL);

    if (g_markup_parse_context_parse(ctx, data, size, NULL) == FALSE) {
        error("XML parsing error");
        g_markup_parse_context_free(ctx);
        sdp_record_free(record);
        free(ctx_data);
        return NULL;
    }

    //free the method buf
    g_markup_parse_context_free(ctx);
    free(ctx_data);

    return record;
}
static void
parse_rules_file (GnomeXkbInfo  *self,
                  const gchar   *path,
                  GError       **error)
{
  gchar *buffer;
  gsize length;
  GMarkupParseContext *context;
  GError *sub_error = NULL;

  g_file_get_contents (path, &buffer, &length, &sub_error);
  if (sub_error)
    {
      g_propagate_error (error, sub_error);
      return;
    }

  context = g_markup_parse_context_new (&markup_parser, 0, self, NULL);
  g_markup_parse_context_parse (context, buffer, length, &sub_error);
  g_markup_parse_context_free (context);
  g_free (buffer);
  if (sub_error)
    g_propagate_error (error, sub_error);
}
static int
test_in_chunks (const gchar *contents,
                gint         length,
                gint         chunk_size)
{
    GMarkupParseContext *context;
    int i = 0;

    context = g_markup_parse_context_new (&silent_parser, 0, NULL, NULL);

    while (i < length)
    {
        int this_chunk = MIN (length - i, chunk_size);

        if (!g_markup_parse_context_parse (context,
                                           contents + i,
                                           this_chunk,
                                           NULL))
        {
            g_markup_parse_context_free (context);
            return 1;
        }

        i += this_chunk;
    }

    if (!g_markup_parse_context_end_parse (context, NULL))
    {
        g_markup_parse_context_free (context);
        return 1;
    }

    g_markup_parse_context_free (context);

    return 0;
}
void load_workflow_description_from_file(workflow_t *workflow, const char* filename)
{
    log_notice("loading workflow: '%s'", filename);
    struct my_parse_data parse_data = { workflow, NULL, NULL, 0, 0, 0};
    parse_data.cur_locale = xstrdup(setlocale(LC_ALL, NULL));
    strchrnul(parse_data.cur_locale, '.')[0] = '\0';

    GMarkupParser parser;
    memset(&parser, 0, sizeof(parser)); /* just in case */
    parser.start_element = &start_element;
    parser.end_element = &end_element;
    parser.text = &text;
    parser.passthrough = &passthrough;
    parser.error = &error;

    GMarkupParseContext *context = g_markup_parse_context_new(
                    &parser, G_MARKUP_TREAT_CDATA_AS_TEXT,
                    &parse_data, /*GDestroyNotify:*/ NULL);

    FILE* fin = fopen(filename, "r");
    if (fin != NULL)
    {
        size_t read_bytes;
        char buff[1024];
        while ((read_bytes = fread(buff, 1, 1024, fin)) != 0)
        {
            g_markup_parse_context_parse(context, buff, read_bytes, NULL);
        }
        fclose(fin);
    }

    g_markup_parse_context_free(context);

    free(parse_data.attribute_lang); /* just in case */
    free(parse_data.cur_locale);
}
Exemple #29
0
void
_gtk_builder_parser_parse_buffer (GtkBuilder   *builder,
                                  const gchar  *filename,
                                  const gchar  *buffer,
                                  gsize         length,
                                  gchar       **requested_objs,
                                  GError      **error)
{
  const gchar* domain;
  ParserData *data;
  GSList *l;

  /* Store the original domain so that interface domain attribute can be
   * applied for the builder and the original domain can be restored after
   * parsing has finished. This allows subparsers to translate elements with
   * gtk_builder_get_translation_domain() without breaking the ABI or API
   */
  domain = gtk_builder_get_translation_domain (builder);

  data = g_new0 (ParserData, 1);
  data->builder = builder;
  data->filename = filename;
  data->domain = g_strdup (domain);
  data->object_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
                                            (GDestroyNotify)g_free, NULL);

  data->requested_objects = NULL;
  if (requested_objs)
    {
      gint i;

      data->inside_requested_object = FALSE;
      for (i = 0; requested_objs[i]; ++i)
        {
          data->requested_objects = g_slist_prepend (data->requested_objects,
                                                     g_strdup (requested_objs[i]));
        }
    }
  else
    {
      /* get all the objects */
      data->inside_requested_object = TRUE;
    }

  data->ctx = g_markup_parse_context_new (&parser,
                                          G_MARKUP_TREAT_CDATA_AS_TEXT,
                                          data, NULL);

  if (!g_markup_parse_context_parse (data->ctx, buffer, length, error))
    goto out;

  _gtk_builder_finish (builder);
  if (_gtk_builder_lookup_failed (builder, error))
    goto out;

  /* Custom parser_finished */
  data->custom_finalizers = g_slist_reverse (data->custom_finalizers);
  for (l = data->custom_finalizers; l; l = l->next)
    {
      SubParser *sub = (SubParser*)l->data;

      gtk_buildable_custom_finished (GTK_BUILDABLE (sub->object),
                                     builder,
                                     sub->child,
                                     sub->tagname,
                                     sub->data);
      if (_gtk_builder_lookup_failed (builder, error))
        goto out;
    }

  /* Common parser_finished, for all created objects */
  data->finalizers = g_slist_reverse (data->finalizers);
  for (l = data->finalizers; l; l = l->next)
    {
      GtkBuildable *buildable = (GtkBuildable*)l->data;

      gtk_buildable_parser_finished (GTK_BUILDABLE (buildable), builder);
      if (_gtk_builder_lookup_failed (builder, error))
        goto out;
    }

 out:

  g_slist_free_full (data->stack, (GDestroyNotify)free_info);
  g_slist_free_full (data->custom_finalizers, (GDestroyNotify)free_subparser);
  g_slist_free (data->finalizers);
  g_slist_free_full (data->requested_objects, g_free);
  g_free (data->domain);
  g_hash_table_destroy (data->object_ids);
  g_markup_parse_context_free (data->ctx);
  g_free (data);

  /* restore the original domain */
  gtk_builder_set_translation_domain (builder, domain);
}
Exemple #30
0
void
dt_styles_import_from_file(const char *style_path)
{

  FILE    			*style_file;
  StyleData           *style;
  GMarkupParseContext	*parser;
  gchar				buf[1024];
  int					num_read;

  style = dt_styles_style_data_new();
  parser = g_markup_parse_context_new (&dt_style_parser, 0, style, NULL);

  if ((style_file = fopen (style_path, "r")))
  {

    while (!feof (style_file))
    {
      num_read = fread (buf, sizeof(gchar), 1024, style_file);

      if (num_read == 0)
      {
        break;
      }
      else if (num_read < 0)
      {
        // ERROR !
        break;
      }

      if (!g_markup_parse_context_parse(parser, buf, num_read, NULL))
      {
        g_markup_parse_context_free(parser);
        dt_styles_style_data_free(style,TRUE);
        fclose (style_file);
        return;
      }
    }
  }
  else
  {
    // Failed to open file, clean up.
    g_markup_parse_context_free(parser);
    dt_styles_style_data_free(style,TRUE);
    return;
  }

  if (!g_markup_parse_context_end_parse (parser, NULL))
  {
    g_markup_parse_context_free(parser);
    dt_styles_style_data_free(style,TRUE);
    fclose (style_file);
    return;
  }
  g_markup_parse_context_free (parser);
  // save data
  dt_style_save(style);
  //
  dt_styles_style_data_free(style,TRUE);
  fclose (style_file);
}