1 /*
2  *  Off-the-Record Messaging plugin for pidgin
3  *  Copyright (C) 2004-2014  Ian Goldberg, Rob Smits,
4  *                           Chris Alexander, Willy Lew,
5  *                           Nikita Borisov
6  *                           <otr@cypherpunks.ca>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of version 2 of the GNU General Public License as
10  *  published by the Free Software Foundation.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef __OTRG_DIALOGS_H__
23 #define __OTRG_DIALOGS_H__
24 
25 /* pidgin headers */
26 #include "notify.h"
27 
28 /* libotr headers */
29 #include <libotr/proto.h>
30 #include <libotr/message.h>
31 
32 /* The various help URLs */
33 #define BASE_HELPURL "https://otr-help.cypherpunks.ca/" PIDGIN_OTR_VERSION "/"
34 #define AUTHENTICATE_HELPURL  BASE_HELPURL "authenticate.php"
35 #define SESSIONID_HELPURL     BASE_HELPURL "sessionid.php"
36 #define UNVERIFIED_HELPURL    BASE_HELPURL "unverified.php"
37 #define LEVELS_HELPURL        BASE_HELPURL "levels.php"
38 #define SESSIONS_HELPURL      BASE_HELPURL "sessions.php"
39 
40 
41 typedef struct s_OtrgDialogWait *OtrgDialogWaitHandle;
42 
43 typedef struct {
44     void (*init)(void);
45 
46     void (*cleanup)(void);
47 
48     void (*notify_message)(PurpleNotifyMsgType type,
49 	const char *accountname, const char *protocol, const char *username,
50 	const char *title, const char *primary, const char *secondary);
51 
52     int (*display_otr_message)(const char *accountname, const char *protocol,
53 	    const char *username, const char *msg, int force_create);
54 
55     OtrgDialogWaitHandle (*private_key_wait_start)(const char *account,
56 	const char *protocol);
57 
58     void (*private_key_wait_done)(OtrgDialogWaitHandle handle);
59 
60     void (*unknown_fingerprint)(OtrlUserState us, const char *accountname,
61 	const char *protocol, const char *who, unsigned char fingerprint[20]);
62 
63     void (*verify_fingerprint)(Fingerprint *fprint);
64 
65     void (*socialist_millionaires)(ConnContext *context, char *question,
66 	    gboolean responder);
67 
68     void (*update_smp)(ConnContext *context, OtrlSMPEvent smp_event,
69 	    double progress_level);
70 
71     void (*connected)(ConnContext *context);
72 
73     void (*disconnected)(ConnContext *context);
74 
75     void (*stillconnected)(ConnContext *context);
76 
77     void (*finished)(const char *accountname, const char *protocol,
78 	    const char *username);
79 
80     void (*resensitize_all)(void);
81 
82     void (*new_conv)(PurpleConversation *conv);
83 
84     void (*remove_conv)(PurpleConversation *conv);
85 } OtrgDialogUiOps;
86 
87 /* Set the UI ops */
88 void otrg_dialog_set_ui_ops(const OtrgDialogUiOps *ops);
89 
90 /* Get the UI ops */
91 const OtrgDialogUiOps *otrg_dialog_get_ui_ops(void);
92 
93 /* Initialize the OTR dialog subsystem */
94 void otrg_dialog_init(void);
95 
96 /* Deinitialize the OTR dialog subsystem */
97 void otrg_dialog_cleanup(void);
98 
99 /* This is just like pidgin_notify_message, except: (a) it doesn't grab
100  * keyboard focus, (b) the button is "OK" instead of "Close", and (c)
101  * the labels aren't limited to 2K. */
102 void otrg_dialog_notify_message(PurpleNotifyMsgType type,
103 	const char *accountname, const char *protocol, const char *username,
104 	const char *title, const char *primary, const char *secondary);
105 
106 /* Put up the error version of otrg_dialog_notify_message */
107 void otrg_dialog_notify_error(const char *accountname, const char *protocol,
108 	const char *username, const char *title, const char *primary,
109 	const char *secondary);
110 
111 /* Put up the warning version of otrg_dialog_notify_message */
112 void otrg_dialog_notify_warning(const char *accountname, const char *protocol,
113 	const char *username, const char *title, const char *primary,
114 	const char *secondary);
115 
116 /* Put up the info version of otrg_dialog_notify_message */
117 void otrg_dialog_notify_info(const char *accountname, const char *protocol,
118 	const char *username, const char *title, const char *primary,
119 	const char *secondary);
120 
121 /* Display an OTR control message for the given accountname / protocol /
122  * username conversation.  Return 0 on success, non-0 on error (in which
123  * case the message will be displayed inline as a received message). */
124 int otrg_dialog_display_otr_message(const char *accountname,
125 	const char *protocol, const char *username, const char *msg,
126 	int force_create);
127 
128 /* Put up a Please Wait dialog. This dialog can not be cancelled.
129  * Return a handle that must eventually be passed to
130  * otrg_dialog_private_key_wait_done. */
131 OtrgDialogWaitHandle otrg_dialog_private_key_wait_start(const char *account,
132 	const char *protocol);
133 
134 /* End a Please Wait dialog. */
135 void otrg_dialog_private_key_wait_done(OtrgDialogWaitHandle handle);
136 
137 /* Show a dialog informing the user that a correspondent (who) has sent
138  * us a Key Exchange Message (kem) that contains an unknown fingerprint. */
139 void otrg_dialog_unknown_fingerprint(OtrlUserState us, const char *accountname,
140 	const char *protocol, const char *who, unsigned char fingerprint[20]);
141 
142 /* Show a dialog asking the user to verify the given fingerprint. */
143 void otrg_dialog_verify_fingerprint(Fingerprint *fprint);
144 
145 /* Show a dialog asking the user to give an SMP secret. */
146 void otrg_dialog_socialist_millionaires(ConnContext *context);
147 
148 /* Show a dialog asking the user to give an SMP secret, prompting with a
149  * question. */
150 void otrg_dialog_socialist_millionaires_q(ConnContext *context,
151 	char *question);
152 
153 /* Update the status of an ongoing socialist millionaires protocol. */
154 void otrg_dialog_update_smp(ConnContext *context, OtrlSMPEvent smp_event,
155 	double progress_level);
156 
157 /* Call this when a context transitions to ENCRYPTED. */
158 void otrg_dialog_connected(ConnContext *context);
159 
160 /* Call this when a context transitions to PLAINTEXT. */
161 void otrg_dialog_disconnected(ConnContext *context);
162 
163 /* Call this when we receive a Key Exchange message that doesn't cause
164  * our state to change (because it was just the keys we knew already). */
165 void otrg_dialog_stillconnected(ConnContext *context);
166 
167 /* Call this if the remote user terminates his end of an ENCRYPTED
168  * connection, and lets us know. */
169 void otrg_dialog_finished(const char *accountname, const char *protocol,
170 	const char *username);
171 
172 /* Set all OTR buttons to "sensitive" or "insensitive" as appropriate.
173  * Call this when accounts are logged in or out. */
174 void otrg_dialog_resensitize_all(void);
175 
176 /* Set up the per-conversation information display */
177 void otrg_dialog_new_conv(PurpleConversation *conv);
178 
179 /* Remove the per-conversation information display */
180 void otrg_dialog_remove_conv(PurpleConversation *conv);
181 
182 #endif
183