static gboolean hkp_message_propagate_error (SeahorseHKPSource *self, SoupMessage *message, GError **error) { gchar *server; g_autofree gchar *text = NULL; if (!SOUP_MESSAGE_IS_ERROR (message)) return FALSE; if (message->status_code == SOUP_STATUS_CANCELLED) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, _("The operation was cancelled")); return TRUE; } g_object_get (self, "key-server", &server, NULL); /* Make the body lower case, and no tags */ text = g_strndup (message->response_body->data, message->response_body->length); if (text != NULL) { dehtmlize (text); seahorse_util_string_lower (text); } if (text && strstr (text, "no keys")) return FALSE; /* not found is not an error */ if (text && strstr (text, "too many")) { g_set_error (error, HKP_ERROR_DOMAIN, 0, _("Search was not specific enough. Server “%s” found too many keys."), server); } else { g_set_error (error, HKP_ERROR_DOMAIN, message->status_code, _("Couldn’t communicate with server “%s”: %s"), server, message->reason_phrase); } return TRUE; }
/* Cancels operation and marks the HKP operation as failed */ static void fail_hkp_operation (SeahorseHKPOperation *hop, SoupMessage *msg, const gchar *text) { gchar *t, *server; GError *error = NULL; if (!seahorse_operation_is_running (SEAHORSE_OPERATION (hop))) return; g_object_get (hop->hsrc, "key-server", &server, NULL); if (text) { error = g_error_new (HKP_ERROR_DOMAIN, msg ? msg->status_code : 0, "%s", text); } else if (msg) { /* Make the body lower case, and no tags */ t = g_strndup (msg->response_body->data, msg->response_body->length); if (t != NULL) { dehtmlize (t); seahorse_util_string_lower (t); } if (t && strstr (t, "no keys")) error = NULL; /* not found is not an error */ else if (t && strstr (t, "too many")) error = g_error_new (HKP_ERROR_DOMAIN, 0, _("Search was not specific enough. Server '%s' found too many keys."), server); else error = g_error_new (HKP_ERROR_DOMAIN, msg->status_code, _("Couldn't communicate with server '%s': %s"), server, msg->reason_phrase); g_free (t); } else { /* We should always have msg or text */ g_assert (FALSE); } seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, error); g_free (server); }