summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2009-03-29 17:36:46 (GMT)
committerWill Thompson <will.thompson@collabora.co.uk>2009-03-29 22:02:33 (GMT)
commit20f701937483e1c89fd0252c5c0ce7ab0b57032c (patch)
tree19e2425e2bbd925324928a13b76ce64df7baf6bd
parent830513515018ad69c217514a15c3fc02a255bf4e (diff)
downloadpidgin-20f701937483e1c89fd0252c5c0ce7ab0b57032c.tar.gz
pidgin-20f701937483e1c89fd0252c5c0ce7ab0b57032c.tar.xz
Add purple_request_untrusted_cert().
Using this rather than more generic "show a dialog box" request API should allow standard UIs to present nicer certificate dialogs, and will allow telepathy-haze to understand what's going on.
-rw-r--r--libpurple/request.c29
-rw-r--r--libpurple/request.h76
2 files changed, 98 insertions, 7 deletions
diff --git a/libpurple/request.c b/libpurple/request.c
index 3795181..3ee10c8 100644
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -1388,6 +1388,35 @@ purple_request_folder(void *handle, const char *title, const char *dirname,
return NULL;
}
+void *
+purple_request_untrusted_cert(void *handle, PurpleAccount *account,
+ const gchar *subject_name, GList *cert_chain,
+ PurpleCertificateVerificationReason reason,
+ PurpleRequestUntrustedCertCb response_cb,
+ gpointer user_data)
+{
+ PurpleRequestUiOps *ops = purple_request_get_ui_ops();
+
+ if (ops == NULL)
+ return NULL;
+
+ if (ops->request_untrusted_cert != NULL) {
+ void *ui_handle = ops->request_untrusted_cert(account, subject_name,
+ cert_chain, reason, response_cb, user_data);
+
+ purple_request_info_add (PURPLE_REQUEST_UNTRUSTED_CERT, handle,
+ ui_handle);
+
+ return ui_handle;
+ }
+
+ /* TODO: fall back to purple_request_something_else */
+ /* FIXME: in 3.0 auto-decline the cert if request_untrusted_cert is
+ * not implemented.
+ */
+ return NULL;
+}
+
static void
purple_request_close_info(PurpleRequestInfo *info)
{
diff --git a/libpurple/request.h b/libpurple/request.h
index 08a18fa..c6729f7 100644
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -34,6 +34,7 @@
typedef struct _PurpleRequestField PurpleRequestField;
#include "account.h"
+#include "certificate.h"
#define PURPLE_DEFAULT_ACTION_NONE -1
@@ -42,12 +43,13 @@ typedef struct _PurpleRequestField PurpleRequestField;
*/
typedef enum
{
- PURPLE_REQUEST_INPUT = 0, /**< Text input request. */
- PURPLE_REQUEST_CHOICE, /**< Multiple-choice request. */
- PURPLE_REQUEST_ACTION, /**< Action request. */
- PURPLE_REQUEST_FIELDS, /**< Multiple fields request. */
- PURPLE_REQUEST_FILE, /**< File open or save request. */
- PURPLE_REQUEST_FOLDER /**< Folder selection request. */
+ PURPLE_REQUEST_INPUT = 0, /**< Text input request. */
+ PURPLE_REQUEST_CHOICE, /**< Multiple-choice request. */
+ PURPLE_REQUEST_ACTION, /**< Action request. */
+ PURPLE_REQUEST_FIELDS, /**< Multiple fields request. */
+ PURPLE_REQUEST_FILE, /**< File open or save request. */
+ PURPLE_REQUEST_FOLDER, /**< Folder selection request. */
+ PURPLE_REQUEST_UNTRUSTED_CERT /**< Untrusted certificate request */
} PurpleRequestType;
@@ -184,6 +186,41 @@ struct _PurpleRequestField
#endif
/**
+ * Signature of a callback to be passed to purple_request_untrusted_cert().
+ *
+ *
+ */
+typedef void (*PurpleRequestUntrustedCertCb) (gpointer user_data,
+ gboolean accept);
+
+/**
+ * Signature of an implementation of
+ * #PurpleCertificateUiOps::present_untrusted. When the UI or user has decided
+ * whether the certificate may be trusted, it should call @response_cb; if the
+ * request is closed before the UI or user has decided, the implementation
+ * should treat this as declining the certificate and call @response_cb
+ * appropriately.
+ *
+ * @param account The account to which the certificate pertains.
+ * @param subject_name The domain whose certificate is being checked
+ * @param cert_chain A non-empty list of #PurpleCertificate representing the
+ * untrusted certificate chain.
+ * @param reason The reason the certificate is untrusted.
+ * @param response_cb A function to be called with the user's response and @cb_data.
+ * @param user_data Data to pass to one of the response callbacks.
+ *
+ * @return A UI-specific handle for the ongoing request, as may be passed to
+ * #PurpleRequestUiOps::close_request.
+ */
+typedef gpointer (*PurpleRequestUntrustedCertFunc) (
+ PurpleAccount *account,
+ const gchar *subject_name,
+ GList *cert_chain,
+ PurpleCertificateVerificationReason reason,
+ PurpleRequestUntrustedCertCb response_cb,
+ gpointer user_data);
+
+/**
* Request UI operations.
*/
typedef struct
@@ -236,10 +273,14 @@ typedef struct
PurpleAccount *account, const char *who,
PurpleConversation *conv, void *user_data);
+ /** @see #PurpleRequestUntrustedCertFunc and
+ * purple_request_untrusted_cert().
+ */
+ PurpleRequestUntrustedCertFunc request_untrusted_cert;
+
void (*_purple_reserved1)(void);
void (*_purple_reserved2)(void);
void (*_purple_reserved3)(void);
- void (*_purple_reserved4)(void);
} PurpleRequestUiOps;
typedef void (*PurpleRequestInputCb)(void *, const char *);
@@ -1506,6 +1547,27 @@ void *purple_request_folder(void *handle, const char *title, const char *dirname
PurpleAccount *account, const char *who, PurpleConversation *conv,
void *user_data);
+/**
+ * Present an untrusted certificate to the user, who may accept or reject it.
+ *
+ * @param handle The plugin or connection handle. For some things this
+ * is <em>extremely</em> important. See the comments on
+ * purple_request_input().
+ * @param account The account to which the certificate pertains.
+ * @param subject_name The domain whose certificate is being checked
+ * @param cert_chain A non-empty list of #PurpleCertificate representing the
+ * untrusted certificate chain.
+ * @param reason Why libpurple doesn't trust the certificate.
+ * @param response_cb A function to be called with the user's response and @cb_data.
+ * @param user_data Data to pass to one of the response callbacks.
+ *
+ * @return A UI-specific handle.
+ */
+void *purple_request_untrusted_cert(void *handle, PurpleAccount *account,
+ const gchar *subject_name, GList *cert_chain,
+ PurpleCertificateVerificationReason reason,
+ PurpleRequestUntrustedCertCb response_cb, gpointer user_data);
+
/*@}*/
/**************************************************************************/