Beispiel #1
0
static void _load_file(EDITOR *e, const gchar *filename)
{
	char *text = NULL;
	GtkRecentManager *rm = NULL;

	rm = gtk_recent_manager_get_default();
	gtk_recent_manager_add_item(rm, filename);

	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(filename);

	XI_message(("_load_file filename: %s", filename));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");

	change_window_title(e->window, e->filename);
	text = inhale_text_from_file(!strncmp(filename, "file:", 5)
					 ? filename + 5
					 : filename);

	XI_message(("web view load string [%s]", text));
	webkit_web_view_load_string(WEBKIT_WEB_VIEW(e->html_widget),
				    text, "text/html", "utf_8", "file://");

	g_free(text);
	e->is_changed = FALSE;
}
Beispiel #2
0
static void _load_file(EDITOR *e, const gchar *filename)
{
	//GtkWidget *choser;
	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(filename);

	XI_message(("_load_file filename: %s", filename));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");
	change_window_title(e->window, e->filename);

	char *contents;
	char *etag_out;
	gsize length;
	GFile *file;
	file = g_file_new_for_path(filename);
	gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window),
				    e->filename);
	if (g_file_load_contents(file, NULL, &contents, &length, &etag_out, NULL))
		gtkhtml_editor_set_text_html(GTKHTML_EDITOR(e->window),
					     contents, length);
	gtkhtml_editor_drop_undo(GTKHTML_EDITOR(e->window));
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), FALSE);
	return;
}
Beispiel #3
0
/******************************************************************************
 * *Function: conf_get_debug_fname
 * *Description: get debug fname and save it into gconf var
 * *Input: none
 * *Output: none
 * *Return: CONF_SUCCESS/CONF_FAIL
 * *Date: 2016/8/22
 * ****************************************************************************/
int conf_get_debug_fname()
{
	if(xml_get_value(KEYNAME_DEBUG_FNAME, gconf.debug_fname, CONF_NAME_LEN) == PARSE_FAIL) {
		strncpy(gconf.debug_fname, KEYVALUE_DFT_DEBUG_FNAME, CONF_NAME_LEN);
		return CONF_FAIL;
	}

	return CONF_SUCCESS;
}
Beispiel #4
0
/******************************************************************************
 * *Function: conf_get_dbtable
 * *Description: get dbtable and save it into gconf var
 * *Input: none
 * *Output: none
 * *Return: CONF_SUCCESS/CONF_FAIL
 * *Date: 2016/8/22
 * ****************************************************************************/
int conf_get_dbtable()
{
	if(xml_get_value(KEYNAME_DBTABLE, gconf.dbtable, CONF_NAME_LEN) == PARSE_FAIL) {
		strncpy(gconf.dbtable, KEYVALUE_DFT_DBTABLE, CONF_NAME_LEN);
		return CONF_FAIL;
	}

	return CONF_SUCCESS;
}
Beispiel #5
0
static void recent_item_cb(GtkRecentChooser *chooser, EDITOR *e)
{
	gchar *file_uri = gtk_recent_chooser_get_current_uri(chooser);

	XI_message(("file_uri: %s", file_uri));
	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(file_uri);

	//editor_open_recent (file_uri, e);
	_load_file(e, file_uri);
	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");

	change_window_title(e->window, e->filename);
}
Beispiel #6
0
/******************************************************************************
 * *Function: conf_get_debug
 * *Description: get debug value and save it into gconf var
 * *Input: none
 * *Output: none
 * *Return: CONF_SUCCESS/CONF_FAIL
 * *Date: 2016/8/22
 * ****************************************************************************/
int conf_get_debug()
{
	char buf[CONF_NAME_LEN];

	if(xml_get_value(KEYNAME_DEBUG, buf, CONF_NAME_LEN) == PARSE_FAIL) {
		gconf.debug = KEYVALUE_DFT_DEBUG;
		return CONF_FAIL;
	}

	gconf.debug = atoi(buf);
	if(gconf.debug != DEBUG_CLOSE	||
		gconf.debug != DEBUG_STDOUT	||
		gconf.debug != DEBUG_FILE )
		gconf.debug = KEYVALUE_DFT_DEBUG;

	return CONF_SUCCESS;
}
Beispiel #7
0
int main(int argc, char *argv[])
{
    xmlDocPtr doc   = NULL;
	xmlChar *result = NULL;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <xmlfile>\n", argv[0]);
        return -1;
    }

    doc = xml_get_doc(argv[1]);
    if (doc == NULL) {
        xmlCleanupParser();
        return -1;
    }

    result = xml_get_value(doc, "//Format/meta/good");
    if (result == NULL)
        fprintf(stderr, "Not found\n");
    else {
        fprintf(stdout, "result = %s\n", result);
        xmlFree(result);
    }

    result = xml_get_prop(doc, "//Format", "FmtName");
    if (result == NULL)
        fprintf(stderr, "Not found\n");
    else {
        fprintf(stdout, "prop result: %s\n", result);
        xmlFree(result);
    }

    result = xml_doc_to_string(doc);
    if (result == NULL)
        fprintf(stderr, "Not fount\n");
    else {
        fprintf(stdout, "result = %s\n", result);
        xmlFree(result);
    }

    xmlFreeDoc(doc);
    xmlCleanupParser();

	return 0;
}
Beispiel #8
0
static void sync_with_main(const gchar *key)
{
	gchar *buf = NULL;

	if (key)
		buf = (gchar *)main_url_encode(key);
	else
		buf = (gchar *)
		    main_url_encode(xml_get_value("keys", "verse"));
	XI_message(("%s", buf));
	if (buf && (strlen(buf) > 3)) {
		gchar *url =
		    g_strdup_printf("passagestudy.jsp?action=showParallel&"
				    "type=verse&value=%s", buf);

		main_url_handler(url, TRUE);
		g_free(url);
	}
}
Beispiel #9
0
G_MODULE_EXPORT void action_new_activate_cb(GtkWidget *widget, EDITOR *e)
{ /* for studypad only */
	gchar *filename = NULL;

	if (e->is_changed)
		ask_about_saving(e);

	filename = g_strdup_printf("%s/%s", settings.gSwordDir, "studypad.spt");

	_load_file(e, filename);

	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(_("Untitled document"));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");
	change_window_title(e->window, e->filename);
	e->is_changed = TRUE;
}
Beispiel #10
0
static void action_new_cb(GtkAction *action, EDITOR *e)
{ /* for studypad only */

	if (editor_is_dirty(e))
		_save_file(e);

	_load_file(e,
		   g_strdup_printf("%s/%s", settings.gSwordDir,
				   "template.pad"));

	if (e->filename)
		g_free(e->filename);
	e->filename = g_strdup(_("Untitled document"));

	xml_set_value("Xiphos", "studypad", "lastfile", e->filename);
	settings.studypadfilename = xml_get_value("studypad", "lastfile");
	change_window_title(e->window, e->filename);

	gtkhtml_editor_set_filename(GTKHTML_EDITOR(e->window), NULL);
	gtkhtml_editor_set_changed(GTKHTML_EDITOR(e->window), TRUE);
}
Beispiel #11
0
static gint save_dialog(GtkhtmlEditor *editor, EDITOR *e)
{
	GtkWidget *dialog;
	const gchar *filename;
	gint response;

	dialog =
	    gtk_file_chooser_dialog_new(_("Save As"), GTK_WINDOW(editor),
					GTK_FILE_CHOOSER_ACTION_SAVE,
#ifdef HAVE_GTK_310
					"_Cancel", GTK_RESPONSE_CANCEL,
					"_Open", GTK_RESPONSE_ACCEPT,
#else
					GTK_STOCK_CANCEL,
					GTK_RESPONSE_CANCEL,
					GTK_STOCK_SAVE,
					GTK_RESPONSE_ACCEPT,
#endif
					NULL);

	gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);

	filename = gtkhtml_editor_get_filename(editor);

	if (filename != NULL)
		gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
					      filename);
	else {
		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
						    settings.studypaddir);
		gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
						  _("Untitled document"));
	}

	response = gtk_dialog_run(GTK_DIALOG(dialog));

	if (response == GTK_RESPONSE_ACCEPT) {
		gchar *new_filename;

		new_filename =
		    gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		gtkhtml_editor_set_filename(editor, new_filename);

		if (e->filename)
			g_free(e->filename);
		e->filename = g_strdup(new_filename);

		xml_set_value("Xiphos", "studypad", "lastfile",
			      e->filename);
		settings.studypadfilename =
		    xml_get_value("studypad", "lastfile");

		change_window_title(e->window, e->filename);

		g_free(new_filename);
	}

	gtk_widget_destroy(dialog);

	return response;
}
Beispiel #12
0
static st_rss_t *
rss_open_atom (st_rss_t *rss, const char *encoding)
{
  xml_doc_t *doc;
  xml_node_t *node;
  const char *p = NULL;

  doc = xml_parse (rss->url, encoding);
  if (!doc)
    {
      fprintf (stderr, "ERROR: cannot read %s\n", rss->url);
      return NULL;
    }

  node = xml_get_rootnode (doc);
  if (!node)
    {
      fprintf (stderr, "ERROR: empty document %s\n", rss->url);
      xml_free (doc);
      return NULL;
    }

  node = xml_get_childnode (node);
  while (node && xml_is_empty_node (node))
    node = xml_get_nextnode (node);
  if (!node)
    {
//      fprintf (stderr, "");
      return NULL;
    }

  while (node)
    {
      while (node && xml_is_empty_node (node))
        node = xml_get_nextnode (node);

      if (!node)
        break;

      if (!strcasecmp (xml_get_name (node), "title"))
        rss_read_copy (rss->title, xml_get_childnode (node));
      else if (!strcasecmp (xml_get_name (node), "description"))
        rss_read_copy (rss->desc, xml_get_childnode (node));
//      else if (!strcasecmp (xml_get_name (node), "link"))
//        rss_read_copy (rss->url, xml_get_childnode (node));
      else if (!strcasecmp (xml_get_name (node), "date") ||
               !strcasecmp (xml_get_name (node), "pubDate") ||
               !strcasecmp (xml_get_name (node), "dc:date") ||
               !strcasecmp (xml_get_name (node), "modified") ||
               !strcasecmp (xml_get_name (node), "updated"))
        rss->date = strptime2 ((const char *) xml_get_string (xml_get_childnode (node)));
      else if ((!strcasecmp (xml_get_name (node), "entry")))
        {
          xml_node_t *pnode = xml_get_childnode (node);
          st_rss_item_t *item = &rss->item[rss->item_count];
//          int found = 0;
          char link[RSSMAXBUFSIZE];

          *link = 0;

          while (pnode)
            {
              while (pnode && xml_is_empty_node (pnode))
                pnode = xml_get_nextnode (pnode);

              if (!pnode)
                break;

#ifdef  DEBUG
              printf ("%s\n", xml_get_name (pnode));
              fflush (stdout);
#endif

              if (!strcasecmp (xml_get_name (pnode), "title"))
                {
                  rss_read_copy (item->title, xml_get_childnode (pnode));
//                  found = 1;
                }
#if 0
              else if (!strcasecmp (xml_get_name (pnode), "id"))
                {
                  rss_read_copy (link, xml_get_childnode (pnode));
//                  found = 1;
                }
#endif
              else if (!strcasecmp (xml_get_name (pnode), "link") && (!(*link)))
                {
#if 0
<link rel="alternate" type="text/html" href="http://edition.cnn.com/2006/POLITICS/11/01/kerry.remarks/"/>
#endif
                  p = (const char *) xml_get_value (pnode, "href");
                  if (p)
                    {
                      strncpy (link, p, RSSMAXBUFSIZE)[RSSMAXBUFSIZE-1] = 0;
//                      found = 1;
                    }
                }
              else if (!strcasecmp (xml_get_name (pnode), "content"))
                {
                  rss_read_copy (item->desc, xml_get_childnode (pnode));
//                  found = 1;
                }
              else if (!strcasecmp (xml_get_name (pnode), "author"))
                {
                  xml_node_t *tnode = xml_get_childnode (pnode); 
                  if (!strcasecmp (xml_get_name (tnode), "name"))
                    rss_read_copy (item->user, xml_get_childnode (tnode));
//                  found = 1;
                }
              else if (!strcasecmp (xml_get_name (pnode), "modified") ||
                       !strcasecmp (xml_get_name (pnode), "updated"))
                { 
                  item->date = strptime2 ((const char *) xml_get_string (xml_get_childnode (pnode)));
//                  found = 1;
                }
//              else if (!strcasecmp (xml_get_name (pnode), "duration")) // HACK yt:duration
              else if (stristr (xml_get_name (pnode), "duration")) // HACK yt:duration
                {
                  p = (const char *) xml_get_value (pnode, "seconds");
                  if (p)
                    {
                      item->media.duration = strtol (p, NULL, 10);
//                      found = 1;
//                      break;
                    }
                }
//              else if (!strcasecmp (xml_get_name (pnode), "group")) // media:group
              else if (stristr (xml_get_name (pnode), "group")) // media:group
#if 1
                {
                  rss_open_rss_mrss (pnode, item);
                }
#else
                {
                  xml_node_t *tnode = xml_get_childnode (pnode); 
                  while (tnode)
                    {
                      if (!tnode)
                        break;

//                      if (!strcasecmp (xml_get_name (tnode), "content")) // media:content
                      if (stristr (xml_get_name (tnode), "content")) // media:content
                        {
                          p = (const char *) xml_get_value (tnode, "duration");
                          if (p)
                            {
                              item->media.duration = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "filesize");
                          if (p)
                            {
                              item->media.filesize = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "width");
                          if (p)
                            {
                              item->media.width = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "height");
                          if (p)
                            {
                              item->media.height = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                        }
//                      else if (!strcasecmp (xml_get_name (tnode), "keywords")) // media:keywords
                      else if (stristr (xml_get_name (tnode), "keywords")) // media:keywords
                        {
                          rss_read_copy (item->media.keywords, xml_get_childnode (tnode));
                        }
//                      else if (!strcasecmp (xml_get_name (tnode), "thumbnail")) // media:thumbnail
                      else if (stristr (xml_get_name (tnode), "thumbnail")) // media:thumbnail
                        {
                          p = (const char *) xml_get_value (tnode, "url");
                          if (p)
                            if (!(item->media.thumbnail[0]))
                            {
                              strncpy (item->media.thumbnail, p, RSSMAXBUFSIZE)[RSSMAXBUFSIZE-1] = 0;
//                              found = 1;
//                              break;  
                            }
                        }
                      tnode = xml_get_nextnode (tnode);
                    }
                }
#endif
              pnode = xml_get_nextnode (pnode);
            }

          if (*link)
            strcpy (item->url, link);

          rss->item_count++;

          if (rss->item_count == RSSMAXITEM)
            break;
        }
Beispiel #13
0
static st_rss_t *
rss_open_rss (st_rss_t *rss, const char *encoding)
{
  xml_doc_t *doc;
  xml_node_t *node;
  int rdf = 0;

  doc = xml_parse (rss->url, encoding);
  if (!doc)
    {
      fprintf (stderr, "ERROR: cannot read %s\n", rss->url);
      return NULL;
    }

  node = xml_get_rootnode (doc);
  if (!node)
    {
      fprintf (stderr, "ERROR: empty document %s\n", rss->url);
      xml_free (doc);
      return NULL;
    }

  // rdf?
  // TODO: move this to rss_demux()
  if (strcasecmp (xml_get_name (node), "rss") != 0 &&
      !strcasecmp (xml_get_name (node), "rdf"))
    rdf = 1;

  node = xml_get_childnode (node);
  while (node && xml_is_empty_node (node))
    node = xml_get_nextnode (node);

  if (!node)
    {
//      fprintf (stderr, "");
      return NULL;
    }

  if (strcasecmp (xml_get_name (node), "channel"))
    {
      fprintf (stderr, "ERROR: bad document: did not immediately find the RSS element\n");
      return NULL;
    }

  if (!rdf) // document is RSS
    node = xml_get_childnode (node);

  while (node)
    {
      while (node && xml_is_empty_node (node))
        node = xml_get_nextnode (node);

      if (!node)
        break;

      if (!strcasecmp (xml_get_name (node), "title"))
        rss_read_copy (rss->title, xml_get_childnode (node));
      else if (!strcasecmp (xml_get_name (node), "description"))
        rss_read_copy (rss->desc, xml_get_childnode (node));
//      else if (!strcasecmp (xml_get_name (node), "link"))
//        rss_read_copy (rss->url, xml_get_childnode (node));
      else if (!strcasecmp (xml_get_name (node), "date") ||
               !strcasecmp (xml_get_name (node), "pubDate") ||
               !strcasecmp (xml_get_name (node), "dc:date"))
        rss->date = strptime2 ((const char *) xml_get_string (xml_get_childnode (node)));
      else if (!strcasecmp (xml_get_name (node), "channel") && rdf)
        {
          xml_node_t *pnode = xml_get_childnode (node);

          while (pnode)
            {
              if (!strcasecmp (xml_get_name (pnode), "title"))
                rss_read_copy (rss->title, xml_get_childnode (pnode));
              else if (!strcasecmp (xml_get_name (pnode), "description"))
                rss_read_copy (rss->desc, xml_get_childnode (pnode));
              else if (!strcasecmp (xml_get_name (pnode), "date") ||
                       !strcasecmp (xml_get_name (pnode), "pubDate") ||
                       !strcasecmp (xml_get_name (pnode), "dc:date"))
                rss->date = strptime2 ((const char *) xml_get_string (xml_get_childnode (pnode)));

              pnode = xml_get_nextnode (pnode);
            }

        }
      else if (!strcasecmp (xml_get_name (node), "item") || !strcasecmp (xml_get_name (node), "entry"))
        {
          xml_node_t *pnode = xml_get_childnode (node);
          st_rss_item_t *item = &rss->item[rss->item_count];
//          int found = 0;
          const char *p = NULL;
          char link[RSSMAXBUFSIZE], guid[RSSMAXBUFSIZE];

printf ("SHIT");
fflush (stdout);
          *link = *guid = 0;

          while (pnode)
            {
              while (pnode && xml_is_empty_node (pnode))
                pnode = xml_get_nextnode (pnode);

              if (!pnode)
                break;

#ifdef  DEBUG
              printf ("%s\n", xml_get_name (pnode));
              fflush (stdout);
#endif

              if (!strcasecmp (xml_get_name (pnode), "title"))
                {
                  rss_read_copy (item->title, xml_get_childnode (pnode));
//                  found = 1;
                }
              else if (!strcasecmp (xml_get_name (pnode), "link"))
                {
                  rss_read_copy (link, xml_get_childnode (pnode));
//                  found = 1;
                }
#if 0
              else if (!strcasecmp (xml_get_name (pnode), "enclosure"))
                {
                  p = (const char *) xml_get_value (pnode, "url");
                  if (p)
                    {
                      strncpy (link, p, RSSMAXBUFSIZE)[RSSMAXBUFSIZE-1] = 0;
//                      found = 1;
                    }
                }
#endif
              else if (!strcasecmp (xml_get_name (pnode), "guid") && (!(*link)))
                {
                  rss_read_copy (guid, xml_get_childnode (pnode));
//                  found = 1;
                }
              else if (!strcasecmp (xml_get_name (pnode), "description"))
                {
                  rss_read_copy (item->desc, xml_get_childnode (pnode));
//                  found = 1;
                }
              else if (!strcasecmp (xml_get_name (pnode), "date") ||
                       !strcasecmp (xml_get_name (pnode), "pubDate") ||
                       !strcasecmp (xml_get_name (pnode), "dc:date") ||
                       !strcasecmp (xml_get_name (pnode), "cropDate"))
                { 
                  item->date = strptime2 ((const char *) xml_get_string (xml_get_childnode (pnode)));
//                  found = 1;
                }
//              else if (!strcasecmp (xml_get_name (pnode), "duration")) // HACK yt:duration
              else if (stristr (xml_get_name (pnode), "duration")) // HACK yt:duration
                {
                  p = (const char *) xml_get_value (pnode, "seconds");
                  if (p)
                    {
                      item->media.duration = strtol (p, NULL, 10);
//                      found = 1;
//                      break;
                    }
                }
//              else if (!strcasecmp (xml_get_name (pnode), "group")) // media:group
              else if (stristr (xml_get_name (pnode), "group")) // media:group
                {
                  rss_open_rss_mrss (pnode, item);
                }
              else if (!strcasecmp (xml_get_name (pnode), "author") ||
                       !strcasecmp (xml_get_name (pnode), "dc:creator") ||
                       !strcasecmp (xml_get_name (pnode), "creator"))
                {
                    rss_read_copy (item->user, xml_get_childnode (pnode));
//                  found = 1;
                }
#if 0
              else
                {
                  if (!found) // possibly malformed feed
                    break;
                  else
                    found = 0;
                }
#endif

              pnode = xml_get_nextnode (pnode);
            }

          // some feeds use the guid tag for the link
          if (*link)
            strcpy (item->url, link);
          else if (*guid)
            strcpy (item->url, guid);
          else
            *(item->url) = 0;

          rss->item_count++;

          if (rss->item_count == RSSMAXITEM)
            break;
        }

//      rss->item_count++;

      node = xml_get_nextnode (node);
    }

#ifdef  DEBUG
  rss_st_rss_t_sanity_check (rss);
  fflush (stdout);
#endif

  return rss;
}
Beispiel #14
0
                static void
                rss_open_rss_mrss (xml_node_t *pnode, st_rss_item_t *item)
                {
                  const char *p = NULL;
                  xml_node_t *tnode = xml_get_childnode (pnode); 
                  while (tnode)
                    {
                      if (!tnode)
                        break;

//                      if (!strcasecmp (xml_get_name (tnode), "content")) // media:content
                      if (stristr (xml_get_name (tnode), "content")) // media:content
                        {
                          p = (const char *) xml_get_value (tnode, "duration");
                          if (p)
                            {
                              item->media.duration = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "filesize");
                          if (p)
                            {
                              item->media.filesize = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "width");
                          if (p)
                            {
                              item->media.width = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                          p = (const char *) xml_get_value (tnode, "height");
                          if (p)
                            {
                              item->media.height = strtol (p, NULL, 10);
//                              found = 1;
//                              break;
                            }
                        }
//                      else if (!strcasecmp (xml_get_name (tnode), "keywords")) // media:keywords
                      else if (stristr (xml_get_name (tnode), "keywords")) // media:keywords
                        {
                          rss_read_copy (item->media.keywords, xml_get_childnode (tnode));
                        }
//                      else if (!strcasecmp (xml_get_name (tnode), "thumbnail")) // media:thumbnail
                      else if (stristr (xml_get_name (tnode), "thumbnail")) // media:thumbnail
                        {
                          p = (const char *) xml_get_value (tnode, "url");
                          if (p)
                            if (!(item->media.thumbnail[0]))
                            {
                              strncpy (item->media.thumbnail, p, RSSMAXBUFSIZE)[RSSMAXBUFSIZE-1] = 0;
//                              found = 1;
//                              break;  
                            }
                        }
                      tnode = xml_get_nextnode (tnode);
                    }
                }
Beispiel #15
0
int
rss_demux (const char *fname, const char *encoding)
{
  xml_doc_t *doc = NULL;
  xml_node_t *node = NULL;
  int version = -1;
  char *p = NULL;

  if (!(doc = xml_parse (fname, encoding)))
    {
      fprintf (stderr, "ERROR: cannot read %s\n", fname);
      return -1;
    }

  node = xml_get_rootnode (doc);

  if (!node)
    return -1;

  if (!xml_get_name (node))
    return -1;

#ifdef  DEBUG
  printf ("%s\n", xml_get_name (node));
  fflush (stdout);
#endif

  if (!strcasecmp (xml_get_name (node), "html")) // not xml
    return -1;

  if (!strcasecmp (xml_get_name (node), "feed")) // atom
    {
      version = ATOM_V0_1; // default

      if (!(p = (char *) xml_get_value (node, "version")))
        return version;

      if (!strcasecmp (p, "1.0"))
        version = ATOM_V1_0;
      else if (!strcasecmp (p, "0.3"))
        version = ATOM_V0_3;
      else if (!strcasecmp (p, "0.2"))
        version = ATOM_V0_2;
//      else if (!strcasecmp (p, "0.1"))
//        version = ATOM_V0_1;

      return version;
    }
  else if (!strcasecmp (xml_get_name (node), "rss")) // rss
    {
      version = RSS_V2_0; // default

      if (!(p = (char *) xml_get_value (node, "version")))
        return version;

      if (!strcasecmp (p, "0.91"))
        version = RSS_V0_91;
      else if (!strcasecmp (p, "0.92"))
        version = RSS_V0_92;
      else if (!strcasecmp (p, "0.93"))
        version = RSS_V0_93;
      else if (!strcasecmp (p, "0.94"))
        version = RSS_V0_94;
      else if (!strcasecmp (p, "2") || !strcasecmp (p, "2.0") || !strcasecmp (p, "2.00"))
        version = RSS_V2_0;

      return version;
    }
  else if (!strcasecmp (xml_get_name (node), "rdf"))
    {
#if 0
      if (!(p = xml_get_value (node, "xmlns")))
        return -1;

      // hack
      if (!strcasecmp (p, "http://my.netscape.com/rdf/simple/0.9/"))
        version = RSS_V0_90;
      else if (!strcasecmp (p, "http://purl.org/rss/1.0/"))
        version = RSS_V1_0;
#else
      version = RSS_V1_0;
#endif

      return version;
    }

  return -1;
}