Commit 24518597 authored by cypherpunk's avatar cypherpunk
Browse files

	* dialogs.c:
	* dialogs.h:
	* gtk-dialog.c:
	* otr-plugin.c: Use the new SMP event callback instead of
	handling the SMP state machine ourselves.
parent 3d86d7a3
2008-07-02
* dialogs.c:
* dialogs.h:
* gtk-dialog.c:
* otr-plugin.c: Use the new SMP event callback instead of
handling the SMP state machine ourselves.
2008-06-19
* Makefile.static: Forgot to add tooltipmenu.o to
......
......@@ -153,9 +153,10 @@ void otrg_dialog_socialist_millionaires_q(ConnContext *context,
}
/* Update the status of an ongoing socialist millionaires protocol. */
void otrg_dialog_update_smp(ConnContext *context, double progress_level)
void otrg_dialog_update_smp(ConnContext *context, OtrlSMPEvent smp_event,
double progress_level)
{
ui_ops->update_smp(context, progress_level);
ui_ops->update_smp(context, smp_event, progress_level);
}
/* Call this when a context transitions to ENCRYPTED. */
......
......@@ -62,7 +62,8 @@ typedef struct {
void (*socialist_millionaires)(ConnContext *context, char *question,
gboolean responder);
void (*update_smp)(ConnContext *context, double progress_level);
void (*update_smp)(ConnContext *context, OtrlSMPEvent smp_event,
double progress_level);
void (*connected)(ConnContext *context);
......@@ -146,7 +147,8 @@ void otrg_dialog_socialist_millionaires_q(ConnContext *context,
char *question);
/* Update the status of an ongoing socialist millionaires protocol. */
void otrg_dialog_update_smp(ConnContext *context, double progress_level);
void otrg_dialog_update_smp(ConnContext *context, OtrlSMPEvent smp_event,
double progress_level);
/* Call this when a context transitions to ENCRYPTED. */
void otrg_dialog_connected(ConnContext *context);
......
......@@ -1441,7 +1441,7 @@ static void otrg_gtk_dialog_socialist_millionaires(ConnContext *context,
* protocol. Progress_level is a percentage, from 0.0 (aborted) to
* 1.0 (complete). Any other value represents an intermediate state. */
static void otrg_gtk_dialog_update_smp(ConnContext *context,
double progress_level)
OtrlSMPEvent smp_event, double progress_level)
{
PurpleConversation *conv = otrg_plugin_context_to_conv(context, 0);
GtkProgressBar *bar;
......@@ -1473,7 +1473,7 @@ static void otrg_gtk_dialog_update_smp(ConnContext *context,
gtk_dialog_set_default_response(GTK_DIALOG(dialog),
GTK_RESPONSE_ACCEPT);
if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) {
if (smp_event == OTRL_SMPEVENT_SUCCESS) {
if (context->active_fingerprint->trust &&
context->active_fingerprint->trust[0]) {
gtk_label_set_text(GTK_LABEL(smp_data->smp_progress_label),
......
......@@ -308,6 +308,35 @@ static int max_message_size_cb(void *opdata, ConnContext *context)
return *((int*)lookup_result);
}
static void handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
ConnContext *context, unsigned short progress_percent,
char *question)
{
if (!context) return;
switch (smp_event)
{
case OTRL_SMPEVENT_ASK_FOR_SECRET :
otrg_dialog_socialist_millionaires(context);
break;
case OTRL_SMPEVENT_ASK_FOR_ANSWER :
otrg_dialog_socialist_millionaires_q(context, question);
break;
case OTRL_SMPEVENT_CHEATED :
otrg_plugin_abort_smp(context);
/* FALLTHROUGH */
case OTRL_SMPEVENT_IN_PROGRESS :
case OTRL_SMPEVENT_SUCCESS :
case OTRL_SMPEVENT_FAILURE :
case OTRL_SMPEVENT_ABORT :
otrg_dialog_update_smp(context,
smp_event, ((gdouble)progress_percent)/100.0);
break;
case OTRL_SMPEVENT_ERROR :
otrg_plugin_abort_smp(context);
break;
}
}
static OtrlMessageAppOps ui_ops = {
policy_cb,
create_privkey_cb,
......@@ -326,7 +355,9 @@ static OtrlMessageAppOps ui_ops = {
log_message_cb,
max_message_size_cb,
NULL, /* account_name */
NULL /* account_name_free */
NULL, /* account_name_free */
NULL, /* received_symkey */
handle_smp_event
};
static void process_sending_im(PurpleAccount *account, char *who,
......@@ -440,8 +471,6 @@ static gboolean process_receiving_im(PurpleAccount *account, char **who,
gboolean res;
const char *accountname;
const char *protocol;
ConnContext *context;
NextExpectedSMP nextMsg;
if (!who || !*who || !message || !*message)
return 0;
......@@ -471,75 +500,6 @@ static gboolean process_receiving_im(PurpleAccount *account, char **who,
otrg_ui_update_keylist();
}
/* Keep track of our current progress in the Socialist Millionaires'
* Protocol. */
context = otrl_context_find(otrg_plugin_userstate, username,
accountname, protocol, 0, NULL, NULL, NULL);
if (context) {
nextMsg = context->smstate->nextExpected;
if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) {
otrg_plugin_abort_smp(context);
otrg_dialog_update_smp(context, 0.0);
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
context->smstate->sm_prog_state = OTRL_SMP_PROG_OK;
} else {
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q);
if (tlv) {
if (nextMsg != OTRL_SMP_EXPECT1)
otrg_plugin_abort_smp(context);
else {
char *question = (char *)tlv->data;
char *eoq = memchr(question, '\0', tlv->len);
if (eoq) {
otrg_dialog_socialist_millionaires_q(context,
question);
}
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
if (tlv) {
if (nextMsg != OTRL_SMP_EXPECT1)
otrg_plugin_abort_smp(context);
else {
otrg_dialog_socialist_millionaires(context);
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
if (tlv) {
if (nextMsg != OTRL_SMP_EXPECT2)
otrg_plugin_abort_smp(context);
else {
otrg_dialog_update_smp(context, 0.6);
context->smstate->nextExpected = OTRL_SMP_EXPECT4;
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
if (tlv) {
if (nextMsg != OTRL_SMP_EXPECT3)
otrg_plugin_abort_smp(context);
else {
otrg_dialog_update_smp(context, 1.0);
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
if (tlv) {
if (nextMsg != OTRL_SMP_EXPECT4)
otrg_plugin_abort_smp(context);
else {
otrg_dialog_update_smp(context, 1.0);
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
if (tlv) {
otrg_dialog_update_smp(context, 0.0);
context->smstate->nextExpected = OTRL_SMP_EXPECT1;
}
}
}
otrl_tlv_free(tlvs);
free(username);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment