示例#1
0
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);
}
示例#2
0
void
feed_list_node_remove (nodePtr node)
{
	GtkWidget	*dialog;
	GtkWindow	*mainwindow;
	gchar		*text;
	
	g_assert (node == feedlist_get_selected ());

	liferea_shell_set_status_bar ("%s \"%s\"", _("Deleting entry"), node_get_title (node));
	text = g_strdup_printf (IS_FOLDER (node)?_("Are you sure that you want to delete \"%s\" and its contents?"):_("Are you sure that you want to delete \"%s\"?"), node_get_title (node));

	mainwindow = GTK_WINDOW (liferea_shell_get_window ());
	dialog = gtk_message_dialog_new (mainwindow,
	                                 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
	                                 GTK_MESSAGE_QUESTION,
	                                 GTK_BUTTONS_NONE,
	                                 "%s", text);
	gtk_dialog_add_buttons (GTK_DIALOG (dialog),
	                        "_Cancel", GTK_RESPONSE_CANCEL,
	                        "_Delete", GTK_RESPONSE_ACCEPT,
	                        NULL);
	gtk_window_set_title (GTK_WINDOW (dialog), _("Deletion Confirmation"));
	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
	gtk_window_set_transient_for (GTK_WINDOW (dialog), mainwindow);

	g_free (text);
	
	gtk_widget_show_all (dialog);

	g_signal_connect (G_OBJECT (dialog), "response",
	                  G_CALLBACK (feed_list_node_remove_cb), node);
}
示例#3
0
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);
}
示例#4
0
void
subscription_update (subscriptionPtr subscription, guint flags)
{
	updateRequestPtr		request;
	GTimeVal			now;
	
	if (!subscription)
		return;
		
	if (subscription->updateJob)
		return;
	
	debug1 (DEBUG_UPDATE, "Scheduling %s to be updated", node_get_title (subscription->node));
	 
	if (subscription_can_be_updated (subscription)) {
		liferea_shell_set_status_bar (_("Updating \"%s\""), node_get_title (subscription->node));

		g_get_current_time (&now);
		subscription_reset_update_counter (subscription, &now);

		request = update_request_new ();
		request->updateState = update_state_copy (subscription->updateState);
		request->options = update_options_copy (subscription->updateOptions);
		request->source = g_strdup (subscription_get_source (subscription));
		if (subscription_get_filter (subscription))
			request->filtercmd = g_strdup (subscription_get_filter (subscription));

		if (SUBSCRIPTION_TYPE (subscription)->prepare_update_request (subscription, request))
			subscription->updateJob = update_execute_request (subscription, request, subscription_process_update_result, subscription, flags);
		else
			update_request_free (request);
	}
}
示例#5
0
static void
do_menu_update (nodePtr node)
{
	if (network_monitor_is_online ())
		node_update_subscription (node, GUINT_TO_POINTER (FEED_REQ_PRIORITY_HIGH));
	else
		liferea_shell_set_status_bar (_("Liferea is in offline mode. No update possible."));

}
示例#6
0
/* Checks whether updating a feed makes sense. */
static gboolean
subscription_can_be_updated (subscriptionPtr subscription)
{
	if (subscription->updateJob) {
		liferea_shell_set_status_bar (_("Subscription \"%s\" is already being updated!"), node_get_title (subscription->node));
		return FALSE;
	}
	
	if (subscription->discontinued) {
		liferea_shell_set_status_bar (_("The subscription \"%s\" was discontinued. Liferea won't update it anymore!"), node_get_title (subscription->node));
		return FALSE;
	}

	if (!subscription_get_source (subscription)) {
		g_warning ("Feed source is NULL! This should never happen - cannot update!");
		return FALSE;
	}
	return TRUE;
}	
示例#7
0
void
subscription_update_favicon (subscriptionPtr subscription)
{
	debug1 (DEBUG_UPDATE, "trying to download favicon.ico for \"%s\"", node_get_title (subscription->node));
	liferea_shell_set_status_bar (_("Updating favicon for \"%s\""), node_get_title (subscription->node));
	g_get_current_time (&subscription->updateState->lastFaviconPoll);
	favicon_download (subscription,
	                  node_get_base_url (subscription->node),
			  subscription_get_source (subscription),
			  subscription->updateOptions,		// FIXME: correct?
	                  subscription_favicon_downloaded, 
			  (gpointer)subscription->node);
}
示例#8
0
static void
subscription_process_update_result (const struct updateResult * const result, gpointer user_data, guint32 flags)
{
	subscriptionPtr subscription = (subscriptionPtr)user_data;
	nodePtr		node = subscription->node;
	gboolean	processing = FALSE;
	GTimeVal	now;

	/* 1. preprocessing */

	g_assert (subscription->updateJob);
	/* update the subscription URL on permanent redirects */
	if ((301 == result->httpstatus) && result->source && !g_str_equal (result->source, subscription->updateJob->request->source)) {
		debug2 (DEBUG_UPDATE, "The URL of \"%s\" has changed permanently and was updated with \"%s\"", node_get_title(node), result->source);
		subscription_set_source (subscription, result->source);
		liferea_shell_set_status_bar (_("The URL of \"%s\" has changed permanently and was updated"), node_get_title(node));
	}

	if (401 == result->httpstatus) { /* unauthorized */
		auth_dialog_new (subscription, flags);
	} else if (410 == result->httpstatus) { /* gone */
		subscription->discontinued = TRUE;
		node->available = TRUE;
		liferea_shell_set_status_bar (_("\"%s\" is discontinued. Liferea won't updated it anymore!"), node_get_title (node));
	} else if (304 == result->httpstatus) {
		node->available = TRUE;
		liferea_shell_set_status_bar (_("\"%s\" has not changed since last update"), node_get_title(node));
	} else {
		processing = TRUE;
	}

	subscription_update_error_status (subscription, result->httpstatus, result->returncode, result->filterErrors);

	subscription->updateJob = NULL;

	/* 2. call subscription type specific processing */
	if (processing)
		SUBSCRIPTION_TYPE (subscription)->process_update_result (subscription, result, flags);

	/* 3. call favicon updating after subscription processing
	      to ensure we have valid baseUrl for feed nodes... */
	g_get_current_time (&now);
	if (favicon_update_needed (subscription->node->id, subscription->updateState, &now))
		subscription_update_favicon (subscription);
	
	/* 4. generic postprocessing */
	update_state_set_lastmodified (subscription->updateState, update_state_get_lastmodified (result->updateState));
	update_state_set_cookies (subscription->updateState, update_state_get_cookies (result->updateState));
	update_state_set_etag (subscription->updateState, update_state_get_etag (result->updateState));
	g_get_current_time (&subscription->updateState->lastPoll);

	// FIXME: use new-items signal in itemview class	
	itemview_update_node_info (subscription->node);
	itemview_update ();

	db_subscription_update (subscription);
	db_node_update (subscription->node);

	if (subscription->node->newCount > 0)
		feedlist_new_items (subscription->node);
}