Author: dzzinstant
Date: Wed Jun  4 23:31:07 2014
New Revision: 14

URL: http://svn.gna.org/viewcvs/pidgin-zrtp?rev=14&view=rev
Log:
Use zrtpfilter's GEnums for message strings

Removed:
    trunk/src/pidgin-plugin/simplezrtp/encrypt-zrtpMessages.h
Modified:
    trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c

Modified: trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c?rev=14&r1=13&r2=14&view=diff
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c   (original)
+++ trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c   Wed Jun  4 
23:31:07 2014
@@ -26,7 +26,6 @@
 #include "encrypt-backend-zrtp.h"
 #include "encrypt-backend-iface.h"
 #include "encrypt.h"
-#include "encrypt-zrtpMessages.h"
 
 #include "media/backend-fs2.h"
 #include "media-gst.h"
@@ -176,6 +175,69 @@
                }
        }
        return priv->fsconference;
+}
+
+static const gchar *
+get_zrtpmsg(gint severity, gint subCode, const gchar **desc,
+               const gchar **submsg, const gchar **subdesc)
+{
+       static GType severityType = 0;
+       static GType infoType = 0;
+       static GType warningType = 0;
+       static GType severeType = 0;
+       static GType errorType = 0;
+
+       gpointer klass = NULL;
+       GEnumValue *severityVal;
+       GEnumValue *subVal = NULL;
+       GType subType = 0;
+       const gchar *msg;
+       
+       if (!severityType)
+               severityType = g_type_from_name("GstZrtpMsgSeverity");
+       
+       klass = g_type_class_ref(severityType);
+       severityVal = g_enum_get_value(klass, severity);
+       g_type_class_unref(klass);
+       msg = severityVal->value_name;
+       if (desc)
+               *desc = severityVal->value_nick;
+
+       if (!submsg && !subdesc)
+               return msg;
+
+       if (!infoType) {
+               infoType = g_type_from_name("GstZrtpInfo");
+               warningType = g_type_from_name("GstZrtpWarning");
+               severeType = g_type_from_name("GstZrtpSevere");
+               errorType = g_type_from_name("GstZrtpError");
+       }
+
+       switch (msg[0]) {
+               case 'I':
+                       subType = infoType;
+                       break;
+               case 'W':
+                       subType = warningType;
+                       break;
+               case 'S':
+                       subType = severeType;
+                       break;
+               case 'Z':
+                       subType = errorType;
+                       break;
+               default:
+                       break;
+       }
+       klass = g_type_class_ref(subType);
+       subVal = g_enum_get_value(klass, subCode);
+       g_type_class_unref(klass);
+
+       if (subdesc)
+               *subdesc = subVal->value_nick;
+       if (submsg)
+               *submsg = subVal->value_name;
+       return msg;
 }
 
 /*
@@ -609,13 +671,6 @@
 /*
  * Signals from zrtpfilter elements
  */
-enum zrtp_MessageSeverity {
-       zrtp_Info = 1,                      /*!< Just an info message */
-       zrtp_Warning,                       /*!< A Warning message - security 
can be established */
-       zrtp_Severe,                        /*!< Severe error, security will 
not be established */
-       zrtp_ZrtpError                          /*!< ZRTP error, security will 
not be established  */
-};
-
 static gboolean
 set_enc_state(PurpleEncryptBackendZrtp *self,
                gboolean onoff)
@@ -652,7 +707,7 @@
 }
 
 static void
-zrtp_handleInfo(GstElement *element, gint subCode, ZrtpContext *data) 
+zrtp_handleInfo(GstElement *element, gint severity, gint subCode, ZrtpContext 
*data) 
 {
        PurpleEncryptBackendZrtp *self = 
PURPLE_ENCRYPT_BACKEND_ZRTP(data->backend);
 
@@ -672,16 +727,22 @@
 }
 
 static void
-zrtp_handleWarning(GstElement *element, gint subCode, ZrtpContext *data) 
+zrtp_handleWarning(GstElement *element, gint severity, gint subCode, 
ZrtpContext *data) 
 {
        PurpleEncryptBackendZrtp *self = 
PURPLE_ENCRYPT_BACKEND_ZRTP(data->backend);
-
-       switch (subCode) {
-               case 4: /* No retained shared secrets available - must verify 
SAS */
-                       set_auth_state(self, FALSE);
-                       break;
-               default:
-                       break;
+       const gchar *submsg, *suffix;
+       
+       get_zrtpmsg(severity, subCode, NULL, &submsg, NULL);
+       g_return_if_fail(strlen(submsg) >= 7);
+
+       suffix = submsg + 7;
+       if (!strcmp("NoRSMatch", suffix)) {
+               purple_debug_info(PLUGIN_ID, "NoRSMatch!\n");
+               set_auth_state(self, FALSE);
+       }
+       else if (!strcmp("NoExpectedRSMatch", suffix)) {
+               purple_debug_info(PLUGIN_ID, "NoExpectedRSMatch!\n");
+               set_auth_state(self, FALSE);
        }
 }
 
@@ -689,29 +750,23 @@
 zrtp_statusInfo (GstElement *element, gint severity, gint subCode, ZrtpContext 
*data)  {
        PurpleEncryptBackendZrtp *self = 
PURPLE_ENCRYPT_BACKEND_ZRTP(data->backend);
        gchar *namestr = gst_element_get_name(element);
-
-       switch (severity) {
-               case zrtp_Info:
-                       purple_debug_info(PLUGIN_ID, "ZRTP status info message 
- %s: %s (%u)\n", 
-                                       namestr, InfoCodes[subCode], subCode);
-                       zrtp_handleInfo(element, subCode, data);
-                       break;
-
-               case zrtp_Warning:
-                       purple_debug_info(PLUGIN_ID, "ZRTP status warning 
message - %s: %s (%u)\n", 
-                                       namestr, WarningCodes[subCode], 
subCode);
-                       zrtp_handleWarning(element, subCode, data);
-                       break;
-
-               case zrtp_Severe:
-                       purple_debug_info(PLUGIN_ID, "ZRTP status severe 
message - %s: %s (%u)\n", 
-                                       namestr, SevereCodes[subCode], subCode);
+       const gchar *zrtpmsg, *desc, *submsg, *subdesc;
+
+       zrtpmsg = get_zrtpmsg(severity, subCode, &desc, &submsg, &subdesc);
+       purple_debug_info(PLUGIN_ID, "ZRTP %s (subCode=%u): %s (%s): %s\n",
+                  zrtpmsg, subCode, submsg, subdesc, namestr);
+
+       switch (zrtpmsg[0]) {
+               case 'I': /* Info */
+                       zrtp_handleInfo(element, severity, subCode, data);
+                       break;
+               case 'W': /* Warning */
+                       zrtp_handleWarning(element, severity, subCode, data);
+                       break;
+               case 'S': /* Severe */
                        set_enc_state(self, FALSE);
                        break;
-
-               case zrtp_ZrtpError:
-                       purple_debug_info(PLUGIN_ID, "ZRTP Error: severity - 
%s: %d, subcode: %u\n", 
-                                       namestr, severity, subCode*-1);
+               case 'Z': /* ZrtpError */
                        set_enc_state(self, FALSE);
                        break;
                default:
@@ -741,7 +796,10 @@
 
 static void
 zrtp_negotiationFail (GstElement *element, gint severity, gint subCode, 
ZrtpContext *data)  {
-       purple_debug_warning(PLUGIN_ID, "ZRTP status severe message: %s 
(subcode %d)\n", SevereCodes[subCode], subCode);
+       const gchar *submsg, *desc;
+       
+       get_zrtpmsg(severity, subCode, NULL, &submsg, &desc);
+       purple_debug_warning(PLUGIN_ID, "ZRTP status severe message: %s - %s 
(subcode %d)\n", submsg, desc, subCode);
 
        set_enc_state(PURPLE_ENCRYPT_BACKEND_ZRTP(data->backend), FALSE);
 }

Removed: trunk/src/pidgin-plugin/simplezrtp/encrypt-zrtpMessages.h
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/encrypt-zrtpMessages.h?rev=13&view=auto
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/encrypt-zrtpMessages.h   (original)
+++ trunk/src/pidgin-plugin/simplezrtp/encrypt-zrtpMessages.h   (removed)
@@ -1,47 +0,0 @@
-static const char* InfoCodes[] =
-{
-       "EMPTY",
-       "Hello received, preparing a Commit",
-       "Commit: Generated a public DH key",
-       "Responder: Commit received, preparing DHPart1",
-       "DH1Part: Generated a public DH key",
-       "Initiator: DHPart1 received, preparing DHPart2",
-       "Responder: DHPart2 received, preparing Confirm1",
-       "Initiator: Confirm1 received, preparing Confirm2",
-       "Responder: Confirm2 received, preparing Conf2Ack",
-       "At least one retained secrets matches - security OK",
-       "Entered secure state",
-       "No more security for this session"
-};
-
-/**
- * Sub-codes for Warning
- */
-static const char* WarningCodes [] =
-{
-       "EMPTY",
-       "Commit contains an AES256 cipher but does not offer a Diffie-Hellman 
4096",
-       "Received a GoClear message",
-       "Hello offers an AES256 cipher but does not offer a Diffie-Hellman 
4096",
-       "No retained shared secrets available - must verify SAS",
-       "Internal ZRTP packet checksum mismatch - packet dropped",
-       "Dropping packet because SRTP authentication failed!",
-       "Dropping packet because SRTP replay check failed!",
-       "Valid retained shared secrets availabe but no matches found - must 
verify SAS"
-};
-
-/**
- * Sub-codes for Severe
- */
-static const char* SevereCodes[] =
-{
-       "EMPTY",
-       "Hash HMAC check of Hello failed!",
-       "Hash HMAC check of Commit failed!",
-       "Hash HMAC check of DHPart1 failed!",
-       "Hash HMAC check of DHPart2 failed!",
-       "Cannot send data - connection or peer down?",
-       "Internal protocol error occured!",
-       "Cannot start a timer - internal resources exhausted?",
-       "Too many retries during ZRTP negotiation - connection or peer down?"
-};


_______________________________________________
Pidgin-zrtp-commits mailing list
Pidgin-zrtp-commits@gna.org
https://mail.gna.org/listinfo/pidgin-zrtp-commits

Reply via email to