use-otr-v4.diff
changeset 87 78238d26911a
parent 86 ac5fed257211
child 88 0a87df8ad9c1
equal deleted inserted replaced
86:ac5fed257211 87:78238d26911a
     1 # HG changeset patch
       
     2 # Parent 1b31bdb72d83850b146a0e1e135eba35bad73d29
       
     3 Switch to libotr v4 API
       
     4 
       
     5 diff -r 1b31bdb72d83 mcabber/configure.ac
       
     6 --- a/mcabber/configure.ac	Sun Jan 13 04:35:32 2013 +0200
       
     7 +++ b/mcabber/configure.ac	Fri Jan 18 11:23:47 2013 +0200
       
     8 @@ -183,16 +183,26 @@
       
     9  
       
    10  # Check for otr
       
    11  AC_ARG_ENABLE(otr,
       
    12 -              AC_HELP_STRING([--enable-otr],
       
    13 -                             [enable OTR (Off-the-Record) messaging support]),
       
    14 -              enable_otr=$enableval, otr="")
       
    15 +    AC_HELP_STRING([--enable-otr],
       
    16 +                   [enable OTR (Off-the-Record) messaging support]),
       
    17 +    enable_otr=$enableval,
       
    18 +    otr="")
       
    19  if test "x$enable_otr" = "xyes"; then
       
    20 -  # Look for libgcrypt and libotr
       
    21 -  AM_PATH_LIBGCRYPT(1.2.2, [
       
    22 -          AM_PATH_LIBOTR(3.1.0, ,
       
    23 -                         AC_MSG_ERROR(libotr 3.1.0 or newer is required.))
       
    24 -      ], AC_MSG_ERROR(libgcrypt 1.2.2 or newer is required.)
       
    25 -  )
       
    26 +    # Look for libgcrypt and libotr
       
    27 +    AM_PATH_LIBGCRYPT(1.2.2, [
       
    28 +        AM_PATH_LIBOTR(4.0.0, [
       
    29 +            AC_DEFINE([HAVE_LIBOTR], 1, [Define if you use libotr])
       
    30 +        ], [
       
    31 +            AM_PATH_LIBOTR(3.1.0, [
       
    32 +                AC_DEFINE([HAVE_LIBOTR], 1, [Define if you use libotr])
       
    33 +                AC_DEFINE([HAVE_LIBOTR3], 1, [Define if you use libotr v3])
       
    34 +            ], [
       
    35 +                AC_MSG_ERROR(libotr 3.1.0 or newer is required.)
       
    36 +            ])
       
    37 +        ])
       
    38 +    ], [
       
    39 +        AC_MSG_ERROR(libgcrypt 1.2.2 or newer is required.)
       
    40 +    ])
       
    41  fi
       
    42  
       
    43  # Check for Enchant stuff
       
    44 @@ -289,3 +299,4 @@
       
    45                   mcabber.pc
       
    46                   Makefile])
       
    47  AC_OUTPUT
       
    48 +dnl vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2:  For Vim users...
       
    49 diff -r 1b31bdb72d83 mcabber/mcabber/otr.c
       
    50 --- a/mcabber/mcabber/otr.c	Sun Jan 13 04:35:32 2013 +0200
       
    51 +++ b/mcabber/mcabber/otr.c	Fri Jan 18 11:23:47 2013 +0200
       
    52 @@ -56,6 +56,20 @@
       
    53                                           const char *protocol,
       
    54                                           const char *recipient,
       
    55                                           const char *message);
       
    56 +static void       cb_update_context_list(void *opdata);
       
    57 +static void       cb_new_fingerprint    (void *opdata, OtrlUserState us,
       
    58 +                                         const char *accountname,
       
    59 +                                         const char *protocol,
       
    60 +                                         const char *username,
       
    61 +                                         unsigned char fingerprint[20]);
       
    62 +static void       cb_write_fingerprints (void *opdata);
       
    63 +static void       cb_gone_secure        (void *opdata, ConnContext *context);
       
    64 +static void       cb_gone_insecure      (void *opdata, ConnContext *context);
       
    65 +static void       cb_still_secure       (void *opdata, ConnContext *context,
       
    66 +                                         int is_reply);
       
    67 +static int        cb_max_message_size   (void *opdata, ConnContext *context);
       
    68 +
       
    69 +#ifdef HAVE_LIBOTR3
       
    70  static void       cb_notify             (void *opdata,
       
    71                                           OtrlNotifyLevel level,
       
    72                                           const char *accountname,
       
    73 @@ -69,22 +83,26 @@
       
    74                                           const char *protocol,
       
    75                                           const char *username,
       
    76                                           const char *msg);
       
    77 -static void       cb_update_context_list(void *opdata);
       
    78  static const char *cb_protocol_name     (void *opdata, const char *protocol);
       
    79  static void       cb_protocol_name_free (void *opdata,
       
    80                                           const char *protocol_name);
       
    81 -static void       cb_new_fingerprint    (void *opdata, OtrlUserState us,
       
    82 -                                         const char *accountname,
       
    83 -                                         const char *protocol,
       
    84 -                                         const char *username,
       
    85 -                                         unsigned char fingerprint[20]);
       
    86 -static void       cb_write_fingerprints (void *opdata);
       
    87 -static void       cb_gone_secure        (void *opdata, ConnContext *context);
       
    88 -static void       cb_gone_insecure      (void *opdata, ConnContext *context);
       
    89 -static void       cb_still_secure       (void *opdata, ConnContext *context,
       
    90 -                                         int is_reply);
       
    91  static void       cb_log_message        (void *opdata, const char *message);
       
    92 -static int        cb_max_message_size   (void *opdata, ConnContext *context);
       
    93 +
       
    94 +static void       otr_handle_smp_tlvs   (OtrlTLV *tlvs, ConnContext *ctx);
       
    95 +#else /* HAVE_LIBOTR3 */
       
    96 +static char *tagfile = NULL;
       
    97 +static guint otr_timer_source = 0;
       
    98 +
       
    99 +static void       cb_handle_smp_event   (void *opdata, OtrlSMPEvent event,
       
   100 +                                         ConnContext *context, unsigned short percent,
       
   101 +                                         char *question);
       
   102 +static void       cb_handle_msg_event   (void *opdata, OtrlMessageEvent event,
       
   103 +                                         ConnContext *context, const char *message,
       
   104 +                                         gcry_error_t err);
       
   105 +static void       cb_create_instag      (void *opdata, const char *accountname,
       
   106 +                                         const char *protocol);
       
   107 +static void       cb_timer_control      (void *opdata, unsigned int interval);
       
   108 +#endif /* HAVE_LIBOTR3 */
       
   109  
       
   110  static OtrlMessageAppOps ops =
       
   111  {
       
   112 @@ -92,26 +110,44 @@
       
   113    cb_create_privkey,
       
   114    cb_is_logged_in,
       
   115    cb_inject_message,
       
   116 +#ifdef HAVE_LIBOTR3
       
   117    cb_notify,
       
   118    cb_display_otr_message,
       
   119 +#endif
       
   120    cb_update_context_list,
       
   121 +#ifdef HAVE_LIBOTR3
       
   122    cb_protocol_name,
       
   123    cb_protocol_name_free,
       
   124 +#endif
       
   125    cb_new_fingerprint,
       
   126    cb_write_fingerprints,
       
   127    cb_gone_secure,
       
   128    cb_gone_insecure,
       
   129    cb_still_secure,
       
   130 +#ifdef HAVE_LIBOTR3
       
   131    cb_log_message,
       
   132 +#endif
       
   133    cb_max_message_size,
       
   134 -  NULL, /*account_name*/
       
   135 -  NULL  /*account_name_free*/
       
   136 +  NULL, /* account_name */
       
   137 +  NULL, /* account_name_free */
       
   138 +#ifndef HAVE_LIBOTR3
       
   139 +  NULL, /* received_symkey */
       
   140 +  NULL, /* otr_error_message */
       
   141 +  NULL, /* otr_error_message_free */
       
   142 +  NULL, /* resent_msg_prefix */
       
   143 +  NULL, /* resent_msg_prefix_free */
       
   144 +  cb_handle_smp_event,
       
   145 +  cb_handle_msg_event,
       
   146 +  cb_create_instag,
       
   147 +  NULL, /* convert_msg */
       
   148 +  NULL, /* convert_free */
       
   149 +  cb_timer_control,
       
   150 +#endif
       
   151  };
       
   152  
       
   153  static void otr_message_disconnect(ConnContext *ctx);
       
   154  static ConnContext *otr_get_context(const char *buddy);
       
   155  static void otr_startstop(const char *buddy, int start);
       
   156 -static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx);
       
   157  
       
   158  static char *otr_get_dir(void);
       
   159  
       
   160 @@ -135,7 +171,6 @@
       
   161    account = jidtodisp(fjid);
       
   162    keyfile = g_strdup_printf("%s%s.key", root, account);
       
   163    fprfile = g_strdup_printf("%s%s.fpr", root, account);
       
   164 -  g_free(root);
       
   165  
       
   166    if (otrl_privkey_read(userstate, keyfile)){
       
   167      scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
       
   168 @@ -145,6 +180,14 @@
       
   169      scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
       
   170                   fprfile);
       
   171    }
       
   172 +#ifndef HAVE_LIBOTR3
       
   173 +  tagfile = g_strdup_printf("%s%s.tag", root, account);
       
   174 +  if (otrl_instag_read(userstate, tagfile)) {
       
   175 +    scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR instance tag from %s", tagfile);
       
   176 +    cb_create_instag(NULL, account, OTR_PROTOCOL_NAME);
       
   177 +  }
       
   178 +#endif
       
   179 +  g_free(root);
       
   180  }
       
   181  
       
   182  void otr_terminate(void)
       
   183 @@ -154,6 +197,13 @@
       
   184    if (!otr_is_enabled)
       
   185      return;
       
   186  
       
   187 +#ifndef HAVE_LIBOTR3
       
   188 +  if (otr_timer_source > 0) {
       
   189 +    g_source_remove (otr_timer_source);
       
   190 +    otr_timer_source = 0;
       
   191 +  }
       
   192 +#endif
       
   193 +
       
   194    for (ctx = userstate->context_root; ctx; ctx = ctx->next)
       
   195      if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
       
   196        otr_message_disconnect(ctx);
       
   197 @@ -175,6 +225,12 @@
       
   198    userstate = NULL;
       
   199    g_free(keyfile);
       
   200    keyfile = NULL;
       
   201 +  g_free(fprfile);
       
   202 +  fprfile = NULL;
       
   203 +#ifndef HAVE_LIBOTR3
       
   204 +  g_free(tagfile);
       
   205 +  tagfile = NULL;
       
   206 +#endif
       
   207  }
       
   208  
       
   209  static char *otr_get_dir(void)
       
   210 @@ -206,7 +262,12 @@
       
   211  
       
   212    mc_strtolower(lowcasebuddy);
       
   213    ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME,
       
   214 +#ifdef HAVE_LIBOTR3
       
   215                            1, &null, NULL, NULL);
       
   216 +#else
       
   217 +                          // INSTAG XXX
       
   218 +                          OTRL_INSTAG_BEST, 1, &null, NULL, NULL);
       
   219 +#endif
       
   220    g_free(lowcasebuddy);
       
   221    return ctx;
       
   222  }
       
   223 @@ -216,7 +277,12 @@
       
   224    if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
       
   225      cb_gone_insecure(NULL, ctx);
       
   226    otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname,
       
   227 +#ifdef HAVE_LIBOTR3
       
   228                            ctx->protocol, ctx->username);
       
   229 +#else
       
   230 +                          // INSTAG XXX
       
   231 +                          ctx->protocol, ctx->username, OTRL_INSTAG_BEST);
       
   232 +#endif
       
   233  }
       
   234  
       
   235  static void otr_startstop(const char *buddy, int start)
       
   236 @@ -283,6 +349,8 @@
       
   237    cb_write_fingerprints(NULL);
       
   238  }
       
   239  
       
   240 +#ifdef HAVE_LIBOTR3
       
   241 +
       
   242  static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx)
       
   243  {
       
   244    OtrlTLV *tlv = NULL;
       
   245 @@ -354,6 +422,130 @@
       
   246    }
       
   247  }
       
   248  
       
   249 +#else /* HAVE_LIBOTR3 */
       
   250 +
       
   251 +static void cb_handle_smp_event(void *opdata, OtrlSMPEvent event,
       
   252 +                                ConnContext *context, unsigned short percent,
       
   253 +                                char *question)
       
   254 +{
       
   255 +  const char *msg = NULL;
       
   256 +  char *freeme = NULL;
       
   257 +  switch (event) {
       
   258 +    case OTRL_SMPEVENT_ASK_FOR_SECRET:
       
   259 +      msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: "
       
   260 +                                     "Received SMP Initiation.\n"
       
   261 +                                     "Answer with /otr smpr %s $secret",
       
   262 +                                     context->username);
       
   263 +      break;
       
   264 +    case OTRL_SMPEVENT_ASK_FOR_ANSWER:
       
   265 +      msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: "
       
   266 +                                     "Received SMP Initiation.\n"
       
   267 +                                     "Answer with /otr smpr %s $secret\n"
       
   268 +                                     "Question: %s", context->username,
       
   269 +                                     question);
       
   270 +      break;
       
   271 +    case OTRL_SMPEVENT_CHEATED:
       
   272 +      msg = "OTR: Socialist Millionaires' Protocol: Correspondent cancelled negotiation!";
       
   273 +      otrl_message_abort_smp(userstate, &ops, opdata, context);
       
   274 +      break;
       
   275 +    case OTRL_SMPEVENT_IN_PROGRESS:
       
   276 +      scr_log_print(LPRINT_DEBUG, "OTR: Socialist Millionaires' Protocol: "
       
   277 +                                  "Negotiation is in pogress...");
       
   278 +      break;
       
   279 +    case OTRL_SMPEVENT_SUCCESS:
       
   280 +      msg = "OTR: Socialist Millionaires' Protocol: Success!";
       
   281 +      break;
       
   282 +    case OTRL_SMPEVENT_FAILURE:
       
   283 +      msg = "OTR: Socialist Millionaires' Protocol: Failure.";
       
   284 +      break;
       
   285 +    case OTRL_SMPEVENT_ABORT:
       
   286 +      msg = "OTR: Socialist Millionaires' Protocol: Aborted.";
       
   287 +      break;
       
   288 +    case OTRL_SMPEVENT_ERROR:
       
   289 +      msg = "OTR: Socialist Millionaires' Protocol: Error occured, aborting negotiations!";
       
   290 +      otrl_message_abort_smp(userstate, &ops, opdata, context);
       
   291 +      break;
       
   292 +    default:
       
   293 +      break;
       
   294 +  }
       
   295 +
       
   296 +  if (msg) {
       
   297 +    scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0);
       
   298 +    g_free(freeme);
       
   299 +  }
       
   300 +}
       
   301 +
       
   302 +static void cb_handle_msg_event(void *opdata, OtrlMessageEvent event,
       
   303 +                                ConnContext *context, const char *message,
       
   304 +                                gcry_error_t err)
       
   305 +{
       
   306 +  const char *msg = NULL;
       
   307 +  char *freeme = NULL;
       
   308 +  switch (event) {
       
   309 +    case OTRL_MSGEVENT_ENCRYPTION_REQUIRED:
       
   310 +      msg = "OTR: Policy requires encryption on message!";
       
   311 +      break;
       
   312 +    case OTRL_MSGEVENT_ENCRYPTION_ERROR:
       
   313 +      msg = "OTR: Encryption error! Message not sent.";
       
   314 +      break;
       
   315 +    case OTRL_MSGEVENT_CONNECTION_ENDED:
       
   316 +      msg = "OTR: Connection closed by remote end, message lost. "
       
   317 +            "Close or refresh connection.";
       
   318 +      break;
       
   319 +    case OTRL_MSGEVENT_SETUP_ERROR:
       
   320 +      // FIXME
       
   321 +      msg = freeme = g_strdup_printf("OTR: Error setting up private conversation: %u",
       
   322 +                                     err);
       
   323 +      break;
       
   324 +    case OTRL_MSGEVENT_MSG_REFLECTED:
       
   325 +      msg = "OTR: Received own OTR message!";
       
   326 +      break;
       
   327 +    case OTRL_MSGEVENT_MSG_RESENT:
       
   328 +      msg = "OTR: Previous message was resent.";
       
   329 +      break;
       
   330 +    case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE:
       
   331 +      msg = "OTR: Received encrypted message, but connection is not established " \
       
   332 +            "yet! Message lost.";
       
   333 +      break;
       
   334 +    case OTRL_MSGEVENT_RCVDMSG_UNREADABLE:
       
   335 +      msg = "OTR: Unable to read incoming message!";
       
   336 +      break;
       
   337 +    case OTRL_MSGEVENT_RCVDMSG_MALFORMED:
       
   338 +      msg = "OTR: Malformed incoming message!";
       
   339 +      break;
       
   340 +    case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD:
       
   341 +      scr_log_print(LPRINT_DEBUG, "OTR: Received heartbeat.");
       
   342 +      break;
       
   343 +    case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT:
       
   344 +      scr_log_print(LPRINT_DEBUG, "OTR: Sent heartbeat.");
       
   345 +      break;
       
   346 +    case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR:
       
   347 +      msg = freeme = g_strdup_printf("OTR: Received general otr error: %s",
       
   348 +                                     message);
       
   349 +      break;
       
   350 +    case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
       
   351 +      msg = freeme = g_strdup_printf("OTR: Received unencrypted message: %s",
       
   352 +                                     message);
       
   353 +      break;
       
   354 +    case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
       
   355 +      msg = "OTR: Unable to determine type of received OTR message!";
       
   356 +      break;
       
   357 +    case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE:
       
   358 +      // XXX
       
   359 +      scr_log_print(LPRINT_DEBUG, "OTR: Received message for other instance.");
       
   360 +      break;
       
   361 +    default:
       
   362 +      break;
       
   363 +  }
       
   364 +
       
   365 +  if (msg) {
       
   366 +    scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0);
       
   367 +    g_free(freeme);
       
   368 +  }
       
   369 +}
       
   370 +
       
   371 +#endif /* HAVE_LIBOTR3 */
       
   372 +
       
   373  /*
       
   374   * returns whether a otr_message was received
       
   375   * sets *otr_data to NULL, when it was an internal otr message
       
   376 @@ -362,8 +554,10 @@
       
   377  {
       
   378    int ignore_message;
       
   379    char *newmessage = NULL;
       
   380 +#ifdef HAVE_LIBOTR3
       
   381    OtrlTLV *tlvs = NULL;
       
   382    OtrlTLV *tlv = NULL;
       
   383 +#endif
       
   384    ConnContext *ctx;
       
   385  
       
   386    ctx = otr_get_context(buddy);
       
   387 @@ -371,8 +565,8 @@
       
   388    ignore_message = otrl_message_receiving(userstate, &ops, NULL,
       
   389                                            ctx->accountname, ctx->protocol,
       
   390                                            ctx->username, *otr_data,
       
   391 -                                          &newmessage, &tlvs,NULL, NULL);
       
   392 -
       
   393 +#ifdef HAVE_LIBOTR3
       
   394 +                                          &newmessage, &tlvs, NULL, NULL);
       
   395  
       
   396    tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
       
   397    if (tlv) {
       
   398 @@ -387,6 +581,9 @@
       
   399  
       
   400    if (tlvs != NULL)
       
   401      otrl_tlv_free(tlvs);
       
   402 +#else
       
   403 +                                          &newmessage, NULL, NULL, NULL, NULL);
       
   404 +#endif
       
   405  
       
   406    if (ignore_message)
       
   407      *otr_data = NULL;
       
   408 @@ -410,13 +607,27 @@
       
   409  
       
   410    if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT)
       
   411      err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
       
   412 +#ifdef HAVE_LIBOTR3
       
   413                                 ctx->protocol, ctx->username, *msg, NULL,
       
   414                                 &newmessage, NULL, NULL);
       
   415 +#else
       
   416 +                               // INSTAG XXX
       
   417 +                               ctx->protocol, ctx->username, OTRL_INSTAG_BEST,
       
   418 +                               *msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
       
   419 +                               NULL, NULL, NULL);
       
   420 +#endif
       
   421    else {
       
   422      htmlmsg = html_escape(*msg);
       
   423      err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname,
       
   424 +#ifdef HAVE_LIBOTR3
       
   425                                 ctx->protocol, ctx->username, htmlmsg, NULL,
       
   426                                 &newmessage, NULL, NULL);
       
   427 +#else
       
   428 +                               // INSTAG XXX
       
   429 +                               ctx->protocol, ctx->username, OTRL_INSTAG_BEST,
       
   430 +                               htmlmsg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP,
       
   431 +                               NULL, NULL, NULL);
       
   432 +#endif
       
   433      g_free(htmlmsg);
       
   434    }
       
   435  
       
   436 @@ -648,42 +859,6 @@
       
   437                    LM_MESSAGE_SUB_TYPE_NOT_SET, NULL);
       
   438  }
       
   439  
       
   440 -/* Display a notification message for a particular
       
   441 - * accountname / protocol / username conversation. */
       
   442 -static void cb_notify(void *opdata, OtrlNotifyLevel level,
       
   443 -                      const char *accountname, const char *protocol,
       
   444 -                      const char *username, const char *title,
       
   445 -                      const char *primary, const char *secondary)
       
   446 -{
       
   447 -  char *type;
       
   448 -  char *sbuf = NULL;
       
   449 -  switch (level) {
       
   450 -    case OTRL_NOTIFY_ERROR:   type = "error";   break;
       
   451 -    case OTRL_NOTIFY_WARNING: type = "warning"; break;
       
   452 -    case OTRL_NOTIFY_INFO:    type = "info";    break;
       
   453 -    default:                  type = "unknown";
       
   454 -  }
       
   455 -  sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary);
       
   456 -  scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
       
   457 -  g_free(sbuf);
       
   458 -}
       
   459 -
       
   460 -/* Display an OTR control message for a particular
       
   461 - * accountname / protocol / username conversation.  Return 0 if you are able
       
   462 - * to successfully display it.  If you return non-0 (or if this
       
   463 - * function is NULL), the control message will be displayed inline,
       
   464 - * as a received message, or else by using the above notify()
       
   465 - * callback. */
       
   466 -static int cb_display_otr_message(void *opdata, const char *accountname,
       
   467 -                                  const char *protocol, const char *username,
       
   468 -                                  const char *msg)
       
   469 -{
       
   470 -  char *strippedmsg = html_strip(msg);
       
   471 -  scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0);
       
   472 -  g_free(strippedmsg);
       
   473 -  return 0;
       
   474 -}
       
   475 -
       
   476  /* When the list of ConnContexts changes (including a change in
       
   477   * state), this is called so the UI can be updated. */
       
   478  static void cb_update_context_list(void *opdata)
       
   479 @@ -692,19 +867,6 @@
       
   480     * then use this function (?!)*/
       
   481  }
       
   482  
       
   483 -/* Return a newly allocated string containing a human-friendly name
       
   484 - * for the given protocol id */
       
   485 -static const char *cb_protocol_name(void *opdata, const char *protocol)
       
   486 -{
       
   487 -  return protocol;
       
   488 -}
       
   489 -
       
   490 -/* Deallocate a string allocated by protocol_name */
       
   491 -static void cb_protocol_name_free (void *opdata, const char *protocol_name)
       
   492 -{
       
   493 -  /* We didn't allocated memory, so we don't have to free anything :p */
       
   494 -}
       
   495 -
       
   496  /* A new fingerprint for the given user has been received. */
       
   497  static void cb_new_fingerprint(void *opdata, OtrlUserState us,
       
   498                                 const char *accountname, const char *protocol,
       
   499 @@ -748,12 +910,92 @@
       
   500                             HBB_PREFIX_INFO, 0);
       
   501  }
       
   502  
       
   503 +#ifdef HAVE_LIBOTR3
       
   504 +
       
   505 +/* Display a notification message for a particular
       
   506 + * accountname / protocol / username conversation. */
       
   507 +static void cb_notify(void *opdata, OtrlNotifyLevel level,
       
   508 +                      const char *accountname, const char *protocol,
       
   509 +                      const char *username, const char *title,
       
   510 +                      const char *primary, const char *secondary)
       
   511 +{
       
   512 +  char *type;
       
   513 +  char *sbuf = NULL;
       
   514 +  switch (level) {
       
   515 +    case OTRL_NOTIFY_ERROR:   type = "error";   break;
       
   516 +    case OTRL_NOTIFY_WARNING: type = "warning"; break;
       
   517 +    case OTRL_NOTIFY_INFO:    type = "info";    break;
       
   518 +    default:                  type = "unknown";
       
   519 +  }
       
   520 +  sbuf = g_strdup_printf("OTR %s:%s\n%s\n%s",type,title, primary, secondary);
       
   521 +  scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0);
       
   522 +  g_free(sbuf);
       
   523 +}
       
   524 +
       
   525 +/* Display an OTR control message for a particular
       
   526 + * accountname / protocol / username conversation.  Return 0 if you are able
       
   527 + * to successfully display it.  If you return non-0 (or if this
       
   528 + * function is NULL), the control message will be displayed inline,
       
   529 + * as a received message, or else by using the above notify()
       
   530 + * callback. */
       
   531 +static int cb_display_otr_message(void *opdata, const char *accountname,
       
   532 +                                  const char *protocol, const char *username,
       
   533 +                                  const char *msg)
       
   534 +{
       
   535 +  char *strippedmsg = html_strip(msg);
       
   536 +  scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0);
       
   537 +  g_free(strippedmsg);
       
   538 +  return 0;
       
   539 +}
       
   540 +
       
   541 +/* Return a newly allocated string containing a human-friendly name
       
   542 + * for the given protocol id */
       
   543 +static const char *cb_protocol_name(void *opdata, const char *protocol)
       
   544 +{
       
   545 +  return protocol;
       
   546 +}
       
   547 +
       
   548 +/* Deallocate a string allocated by protocol_name */
       
   549 +static void cb_protocol_name_free (void *opdata, const char *protocol_name)
       
   550 +{
       
   551 +  /* We didn't allocated memory, so we don't have to free anything :p */
       
   552 +}
       
   553 +
       
   554  /* Log a message.  The passed message will end in "\n". */
       
   555  static void cb_log_message(void *opdata, const char *message)
       
   556  {
       
   557    scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message);
       
   558  }
       
   559  
       
   560 +#else /* HAVE_LIBOTR3 */
       
   561 +
       
   562 +/* Generate unique instance tag for account. */
       
   563 +static void cb_create_instag(void *opdata, const char *accountname,
       
   564 +                             const char *protocol)
       
   565 +{
       
   566 +  if (otrl_instag_generate(userstate, tagfile, accountname, protocol)) {
       
   567 +    scr_LogPrint(LPRINT_LOGNORM, "OTR instance tag generation failed!");
       
   568 +  }
       
   569 +}
       
   570 +
       
   571 +static gboolean otr_timer_cb(gpointer userdata)
       
   572 +{
       
   573 +  otrl_message_poll(userstate, &ops, userdata);
       
   574 +  return TRUE;
       
   575 +}
       
   576 +
       
   577 +static void cb_timer_control(void *opdata, unsigned int interval)
       
   578 +{
       
   579 +  if (otr_timer_source > 0) {
       
   580 +    g_source_remove(otr_timer_source);
       
   581 +    otr_timer_source = 0;
       
   582 +  }
       
   583 +  if (interval > 0)
       
   584 +    otr_timer_source = g_timeout_add_seconds(interval, otr_timer_cb, opdata);
       
   585 +}
       
   586 +
       
   587 +#endif /* HAVE_LIBOTR3 */
       
   588 +
       
   589  /* Find the maximum message size supported by this protocol. */
       
   590  static int cb_max_message_size(void *opdata, ConnContext *context)
       
   591  {
       
   592 diff -r 1b31bdb72d83 mcabber/mcabber/otr.h
       
   593 --- a/mcabber/mcabber/otr.h	Sun Jan 13 04:35:32 2013 +0200
       
   594 +++ b/mcabber/mcabber/otr.h	Fri Jan 18 11:23:47 2013 +0200
       
   595 @@ -5,6 +5,9 @@
       
   596  
       
   597  #ifdef HAVE_LIBOTR
       
   598  
       
   599 +#ifndef HAVE_LIBOTR3
       
   600 +# include <libotr/instag.h>
       
   601 +#endif
       
   602  #include <libotr/proto.h>
       
   603  #include <libotr/message.h>
       
   604  #include <libotr/privkey.h>