static void update_exec_cmd (updateJobPtr job) { FILE *f; int status; size_t len; job->result = update_result_new (); /* if the first char is a | we have a pipe else a file */ debug1 (DEBUG_UPDATE, "executing command \"%s\"...", (job->request->source) + 1); f = popen ((job->request->source) + 1, "r"); if (f) { while (!feof (f) && !ferror (f)) { job->result->data = g_realloc (job->result->data, job->result->size + 1025); len = fread (&job->result->data[job->result->size], 1, 1024, f); if (len > 0) job->result->size += len; } status = pclose (f); if (WIFEXITED (status) && WEXITSTATUS (status) == 0) job->result->httpstatus = 200; else job->result->httpstatus = 404; /* FIXME: maybe setting request->returncode would be better */ if (job->result->data) job->result->data[job->result->size] = '\0'; } else { liferea_shell_set_status_bar (_("Error: Could not open pipe \"%s\""), (job->request->source) + 1); job->result->httpstatus = 404; /* FIXME: maybe setting request->returncode would be better */ } update_process_finished_job (job); }
static void update_load_file (updateJobPtr job) { gchar *filename = job->request->source; gchar *anchor; job->result = update_result_new (); if (!strncmp (filename, "file://",7)) filename += 7; anchor = strchr (filename, '#'); if (anchor) *anchor = 0; /* strip anchors from filenames */ if (g_file_test (filename, G_FILE_TEST_EXISTS)) { /* we have a file... */ if ((!g_file_get_contents (filename, &(job->result->data), &(job->result->size), NULL)) || (job->result->data[0] == '\0')) { job->result->httpstatus = 403; /* FIXME: maybe setting request->returncode would be better */ liferea_shell_set_status_bar (_("Error: Could not open file \"%s\""), filename); } else { job->result->httpstatus = 200; debug2 (DEBUG_UPDATE, "Successfully read %d bytes from file %s.", job->result->size, filename); } } else { liferea_shell_set_status_bar (_("Error: There is no file \"%s\""), filename); job->result->httpstatus = 404; /* FIXME: maybe setting request->returncode would be better */ } update_process_finished_job (job); }
static updateJobPtr update_job_new (gpointer owner, updateRequestPtr request, update_result_cb callback, gpointer user_data, updateFlags flags) { updateJobPtr job; job = g_new0 (struct updateJob, 1); job->owner = owner; job->request = request; job->result = update_result_new (); job->callback = callback; job->user_data = user_data; job->flags = flags; job->state = REQUEST_STATE_INITIALIZED; return job; }
static void inoreader_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags) { debug_start_measurement (DEBUG_UPDATE); if (result->data) { updateResultPtr resultCopy; /* FIXME: The following is a very dirty hack to edit the feed's XML before processing it */ resultCopy = update_result_new () ; resultCopy->source = g_strdup (result->source); resultCopy->httpstatus = result->httpstatus; resultCopy->contentType = g_strdup (result->contentType); g_free (resultCopy->updateState); resultCopy->updateState = update_state_copy (result->updateState); /* update the XML by removing 'read', 'reading-list' etc. as labels. */ xmlDocPtr doc = xml_parse (result->data, result->size, NULL); xmlXPathContextPtr xpathCtxt = xmlXPathNewContext (doc) ; xmlXPathRegisterNs (xpathCtxt, "atom", "http://www.w3.org/2005/Atom"); inoreader_source_xpath_foreach_match ("/atom:feed/atom:entry/atom:category[@scheme='http://www.inoreader.com/reader/']", xpathCtxt, inoreader_source_xml_unlink_node, NULL); xmlXPathFreeContext (xpathCtxt); /* good now we have removed the read and unread labels. */ xmlChar *newXml; int newXmlSize ; xmlDocDumpMemory (doc, &newXml, &newXmlSize); resultCopy->data = g_strndup ((gchar*) newXml, newXmlSize); resultCopy->size = newXmlSize; xmlFree (newXml); xmlFreeDoc (doc); feed_get_subscription_type ()->process_update_result (subscription, resultCopy, flags); update_result_free (resultCopy); } else { feed_get_subscription_type ()->process_update_result (subscription, result, flags); return ; } xmlDocPtr doc = xml_parse (result->data, result->size, NULL); if (doc) { xmlNodePtr root = xmlDocGetRootElement (doc); xmlNodePtr entry = root->children ; GHashTable *cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); while (entry) { if (!g_str_equal (entry->name, "entry")) { entry = entry->next; continue; /* not an entry */ } inoreader_source_item_retrieve_status (entry, subscription, cache); entry = entry->next; } g_hash_table_unref (cache); xmlFreeDoc (doc); } else { debug0 (DEBUG_UPDATE, "google_feed_subscription_process_update_result(): Couldn't parse XML!"); g_warning ("google_feed_subscription_process_update_result(): Couldn't parse XML!"); } debug_end_measurement (DEBUG_UPDATE, "time taken to update statuses"); }