static void wordnet2result(const gchar *Word, gchar *WordData, std::string &type, std::list<std::string> &wordlist, std::string &gloss)
{
	guint32 data_size = *reinterpret_cast<guint32 *>(WordData);
	type.clear();
	wordlist.clear();
	gloss.clear();
	WnUserData Data(Word, type, wordlist, gloss);
	GMarkupParser parser;
	parser.start_element = NULL;
	parser.end_element = NULL;
	parser.text = func_parse_text;
	parser.passthrough = NULL;
	parser.error = NULL;
	GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
	g_markup_parse_context_parse(context, WordData + sizeof(guint32) + sizeof(char), data_size - 2, NULL);
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);
}
Exemplo n.º 2
0
Arquivo: pbap.c Projeto: Sork007/obexd
static void pull_vcard_listing_callback(struct obc_session *session,
					GError *err, void *user_data)
{
	struct obc_transfer *transfer = obc_session_get_transfer(session);
	struct pbap_data *pbap = user_data;
	GMarkupParseContext *ctxt;
	DBusMessage *reply;
	DBusMessageIter iter, array;
	const char *buf;
	int size;

	if (pbap->msg == NULL)
		goto complete;

	if (err) {
		reply = g_dbus_create_error(pbap->msg,
						"org.openobex.Error.Failed",
						"%s", err->message);
		goto send;
	}

	reply = dbus_message_new_method_return(pbap->msg);

	buf = obc_transfer_get_buffer(transfer, &size);
	if (size == 0)
		buf = "";

	dbus_message_iter_init_append(reply, &iter);
	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_STRUCT_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
			DBUS_STRUCT_END_CHAR_AS_STRING, &array);
	ctxt = g_markup_parse_context_new(&listing_parser, 0, &array, NULL);
	g_markup_parse_context_parse(ctxt, buf, strlen(buf) - 1, NULL);
	g_markup_parse_context_free(ctxt);
	dbus_message_iter_close_container(&iter, &array);

	obc_transfer_clear_buffer(transfer);

send:
	g_dbus_send_message(conn, reply);
	dbus_message_unref(pbap->msg);
	pbap->msg = NULL;
complete:
	obc_transfer_unregister(transfer);
}
Exemplo n.º 3
0
static void parser_callback(const char *str, gpointer user_data)
{
	struct wispr_session *wispr = user_data;
	GMarkupParseContext *context;
	gboolean result;

	//printf("%s\n", str);

	context = g_markup_parse_context_new(&wispr_parser,
			G_MARKUP_TREAT_CDATA_AS_TEXT, &wispr->msg, NULL);

	result = g_markup_parse_context_parse(context, str, strlen(str), NULL);
	if (result == TRUE)
		result = g_markup_parse_context_end_parse(context, NULL);

	g_markup_parse_context_free(context);
}
Exemplo n.º 4
0
void DictConfigXmlToInfo(const char *configxml, DictManageInfo &info)
{
	info.groups.clear();
	config_ParseUserData Data;
	Data.info = &info;
	Data.in_querydict = false;
	Data.in_scandict = false;
	GMarkupParser parser;
	parser.start_element = config_parse_start_element;
	parser.end_element = config_parse_end_element;
	parser.text = NULL;
	parser.passthrough = NULL;
	parser.error = NULL;
	GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
	g_markup_parse_context_parse(context, configxml, -1, NULL);
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);
}
Exemplo n.º 5
0
void
xml_loadsave_jobs_read(const gchar *dirname, const gchar *basename)
{
#ifdef DEBUG
    printf("xml_loadsave_jobs_read\n");
#endif

    GMarkupParser parser = {xml_loadsave_jobs_start_element,
			    xml_loadsave_jobs_end_element,
			    xml_loadsave_jobs_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;
    gchar file[SMALL];

    free_jobs(TRUE);

    sprintf(file, "%s%s%s___job_teams.xml", dirname, G_DIR_SEPARATOR_S, basename);
    xml_loadsave_teams_read(file, job_teams);

    sprintf(file, "%s%s%s___jobs.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_jobs_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_jobs_read: error parsing file %s\n", file);
	misc_print_error(&error, TRUE);
    }
}
Exemplo n.º 6
0
gboolean
cdk_style_scheme_reload (CdkStyleScheme *self)
{
  g_return_val_if_fail (CDK_IS_STYLE_SCHEME (self), FALSE);

  g_hash_table_remove_all (self->priv->style_map);

  gchar *contents = NULL;
  gsize length = 0;
  GError *error = NULL;
  if (! g_file_get_contents (self->priv->filename, &contents, &length, &error))
    {
      g_warning ("failed to read style scheme file '%s': %s",
                 self->priv->filename, error->message);
      g_error_free (error);
      return FALSE;
    }

  GMarkupParser parser;
  memset (&parser, 0, sizeof (GMarkupParser));
  parser.start_element = on_start_element;
  parser.end_element = on_end_element;

  GMarkupParseContext *ctx =
    g_markup_parse_context_new (&parser, 0, self, NULL);
  error = NULL;
  if (! g_markup_parse_context_parse (ctx, contents, length, &error))
    {
      g_warning ("error parsing XML style scheme file '%s': %s",
                 self->priv->filename, error->message);
      g_error_free (error);
      g_free (contents);
      g_markup_parse_context_free (ctx);
      return FALSE;
    }

  g_free (contents);
  g_markup_parse_context_free (ctx);

  //g_debug ("loaded style scheme from XML file '%s'", self->priv->filename);
  g_signal_emit_by_name (self, "reloaded");

  return TRUE;
}
Exemplo n.º 7
0
void
ghb_appcast_parse(gchar *buf, gchar **desc, gchar **build, gchar **version)
{
    GMarkupParseContext *ctx;
    GMarkupParser parser;
    parse_data_t pd;
    GError *err = NULL;
    gint len;
    gchar *start;
    //gchar tmp[4096]

    // Skip junk at beginning of buffer
    start = strstr(buf, "<?xml ");
    pd.description = g_string_new("");
    pd.item = FALSE;
    pd.build = NULL;
    pd.version = NULL;
    len = strlen(start);
    pd.tag_stack = g_queue_new();
    pd.key = NULL;
    pd.value = NULL;

    parser.start_element = start_element;
    parser.end_element = end_element;
    parser.text = text_data;
    parser.passthrough = passthrough;
    parser.error = parse_error;
    ctx = g_markup_parse_context_new(
            &parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &pd, destroy_notify);

    g_markup_parse_context_parse(ctx, start, len, &err);
    g_markup_parse_context_end_parse(ctx, &err);
    g_markup_parse_context_free(ctx);
    g_queue_free(pd.tag_stack);
    *desc = g_string_free(pd.description, FALSE);
    // work around a bug to leaves the CDATA closing brakets on the string
    gchar *glitch;
    glitch = g_strrstr(*desc, "]]>");
    if (glitch)
        *glitch = 0;
    *build = pd.build;
    *version = pd.version;
}
Exemplo n.º 8
0
Arquivo: wispr.c Projeto: igaw/connman
static void xml_wispr_parser_callback(const char *str, gpointer user_data)
{
	struct connman_wispr_portal_context *wp_context = user_data;
	GMarkupParseContext *parser_context = NULL;
	bool result;

	DBG("");

	parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
					G_MARKUP_TREAT_CDATA_AS_TEXT,
					&(wp_context->wispr_msg), NULL);

	result = g_markup_parse_context_parse(parser_context,
					str, strlen(str), NULL);
	if (result)
		g_markup_parse_context_end_parse(parser_context, NULL);

	g_markup_parse_context_free(parser_context);
}
Exemplo n.º 9
0
/** Parse a team definition file and write the team accordingly. */
void
xml_team_read(Team *tm, const gchar *def_file)
{
#ifdef DEBUG
    printf("xml_team_read\n");
#endif

    GMarkupParser parser = {xml_team_read_start_element,
			    xml_team_read_end_element,
			    xml_team_read_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;

    team = tm;
    d_file = def_file;

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

    if(!g_file_get_contents(def_file, &file_contents, &length, &error))
    {
	debug_print_message("xml_team_read: error reading file %s\n", def_file);
	misc_print_error(&error, FALSE);
	return;
    }

    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
    {
	g_critical("xml_team_read: error parsing file %s\n", def_file);
	misc_print_error(&error, TRUE);
    }

    team_complete_def(team);
}
Exemplo n.º 10
0
gboolean
migrate_46 (const gchar  *filename,
            GError      **error)
{
  gsize                length;
  gchar               *contents;
  GMarkupParseContext *context;
  ConfigParser        *parser;
  gboolean             succeed = FALSE;

  g_return_val_if_fail (filename != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

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

  parser = g_slice_new0 (ConfigParser);
  parser->state = START;
  parser->plugin_id_counter = 0;
  parser->panel_id_counter = 0;
  parser->channel = xfconf_channel_new (XFCE_PANEL_CHANNEL_NAME);

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

  if (g_markup_parse_context_parse (context, contents, length, error))
    {
      /* check if the entire file is parsed */
      if (g_markup_parse_context_end_parse (context, error))
        succeed = TRUE;
    }

  /* if parsing failed somehow, empty the channel so no broken config is left */
  if (!succeed)
    xfconf_channel_reset_property (parser->channel, "/", TRUE);

  g_free (contents);
  g_markup_parse_context_free (context);
  g_object_unref (G_OBJECT (parser->channel));
  g_slice_free (ConfigParser, parser);

  return succeed;
}
static void powerword2link(const char *p, guint32 sec_size, const gchar *oword, std::string *pango, LinksPosList *links_list)
{
	PwUserData Data;
	Data.pango = pango;
	Data.links_list = links_list;
	Data.cur_pos = 0;
	Data.oword = oword;
	Data.first_jbcy = true;

	GMarkupParser parser;
	parser.start_element = func_parse_start_element;
	parser.end_element = NULL;
	parser.text = NULL;
	parser.passthrough = func_parse_passthrough;
	parser.error = NULL;
	GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
	g_markup_parse_context_parse(context, p, sec_size, NULL);
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);
}
Exemplo n.º 12
0
int main ( int argc, char **argv )
{
    GError *error = NULL;
    char *buffer = NULL;
    size_t buffer_length = 0;
    GMarkupParseContext *pc = pango_markup_parser_new ( 0 );
    while ( error == NULL && getline ( &buffer, &buffer_length, stdin) > 0 ) {
        g_markup_parse_context_parse(pc, buffer, buffer_length, &error);
    }
    free(buffer);
    buffer = NULL;
    if ( error == NULL &&  pango_markup_parser_finish ( pc, NULL, &buffer, NULL, &error)) {
        fputs(buffer, stdout);
    } else {
        fprintf(stderr, "Failed to parse input: '%s'\n",error->message);
        g_error_free(error);
    }
    g_free(buffer);
    g_markup_parse_context_free(pc);
}
static gboolean
_set_content (GstMediaDescriptorParser * parser,
    const gchar * content, gsize size, GError ** error)
{
  GError *err = NULL;
  GstMediaDescriptorParserPrivate *priv = parser->priv;

  priv->parsecontext = g_markup_parse_context_new (&content_parser,
      G_MARKUP_TREAT_CDATA_AS_TEXT, parser, NULL);

  if (g_markup_parse_context_parse (priv->parsecontext, content,
          size, &err) == FALSE)
    goto failed;

  return TRUE;

failed:
  g_propagate_error (error, err);
  return FALSE;
}
Exemplo n.º 14
0
gint read_xml_frame(FILE *fp, struct model_pak *model)
{
gchar *line;
GMarkupParser xml_parser;
GMarkupParseContext *xml_context;
GError *error;

xml_system_table = g_hash_table_new_full(&g_str_hash, &hash_strcmp, &g_free, NULL);

/* TODO - think more about this... */
xml_model = model;

/* setup context parse (ie callbacks) */
xml_parser.start_element = &xml_start_element;
xml_parser.end_element = &xml_end_element;
xml_parser.text = &xml_parse_text;
xml_parser.passthrough = NULL;
xml_parser.error = NULL;
xml_context = g_markup_parse_context_new(&xml_parser, 0, model, NULL);

/* read in blocks (lines) of text */
line = file_read_line(fp);
while (line)
  {
/* parse the line */
  if (!g_markup_parse_context_parse(xml_context, line, strlen(line), &error))
    printf("read_xml() : parsing error.\n");

  g_free(line);
  line = file_read_line(fp);
  }

/* cleanup */
if (!g_markup_parse_context_end_parse(xml_context, &error))
  printf("read_xml() : errors occurred reading file.\n");

g_markup_parse_context_free(xml_context);
g_hash_table_destroy(xml_system_table);

return(0);
}
Exemplo n.º 15
0
static void
territories_init (void)
{
        gboolean res;
        gsize    buf_len;
        g_autofree char *buf = NULL;
        g_autoptr (GError) error = NULL;

        if (gnome_territories_map)
                return;

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

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

        error = NULL;
        res = g_file_get_contents (ISO_CODES_DATADIR "/iso_3166.xml",
                                   &buf,
                                   &buf_len,
                                   &error);
        if (res) {
                g_autoptr (GMarkupParseContext) ctx = NULL;
                GMarkupParser        parser = { territories_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",
                                   ISO_CODES_DATADIR "/iso_3166.xml",
                                   error->message);
                }
        } else {
                g_warning ("Failed to load '%s': %s\n",
                           ISO_CODES_DATADIR "/iso_3166.xml",
                           error->message);
        }
}
Exemplo n.º 16
0
static char *sdp_xml_parse_record(const char *data)
{
	GMarkupParseContext *ctx;
	struct context_data ctx_data;
	int size;

	size = strlen(data);
	ctx_data.found = FALSE;
	ctx_data.id = NULL;
	ctx = g_markup_parse_context_new(&parser, 0, &ctx_data, NULL);

	if (g_markup_parse_context_parse(ctx, data, size, NULL) == FALSE) {
		g_markup_parse_context_free(ctx);
		g_free(ctx_data.id);
		return NULL;
	}

	g_markup_parse_context_free(ctx);

	return ctx_data.id;
}
Exemplo n.º 17
0
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;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
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);
    }
}
Exemplo n.º 20
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);
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
gboolean parser_parseContents(Parser* parser, gchar* contents, gsize length, GQueue* actions) {

	/* parse the contents, collecting actions. we store a pointer
	 * to it in parser so we have access while parsing elements. */
	parser->actions = actions;
	GError *error = NULL;
	gboolean success = g_markup_parse_context_parse(parser->context, contents, (gssize) length, &error);
	parser->actions = NULL;

	/* check for success in parsing and validating the XML */
	if(success && !error) {
		return TRUE;
	} else {
		/* some kind of error occurred, check the parser */
		g_assert(error);
		error("g_markup_parse_context_parse: Shadow XML parsing error %i: %s",
				error->code, error->message);
		g_error_free(error);

		return FALSE;
	}
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
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;
}
Exemplo n.º 26
0
Arquivo: conf.c Projeto: skoobe/riofs
/**
 * 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;
}
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;
}
Exemplo n.º 28
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;
}
Exemplo n.º 29
0
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;
}
Exemplo n.º 30
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);
        }
}