Changeset 0c85c08 for otr.c


Ignore:
Timestamp:
2010-08-31T23:18:21Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
934db064
Parents:
f5c0d8e
Message:

Pluginify this thing a little bit. Not so much in the dynamically loadable
sense of the word, more in a way that core files don't have to include otr.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • otr.c

    rf5c0d8e r0c85c08  
    109109} pair_t;       
    110110
     111static OtrlMessageAppOps otr_ops;   /* collects interface functions required by OTR */
     112
    111113
    112114/** misc. helpers/subroutines: **/
     
    174176OtrlPrivKey *match_privkey(irc_t *irc, const char **args);
    175177
     178/* functions to be called for certain events */
     179static const struct irc_plugin otr_plugin;
     180
    176181
    177182/*** routines declared in otr.h: ***/
     
    182187       
    183188        /* fill global OtrlMessageAppOps */
    184         global.otr_ops.policy = &op_policy;
    185         global.otr_ops.create_privkey = &op_create_privkey;
    186         global.otr_ops.is_logged_in = &op_is_logged_in;
    187         global.otr_ops.inject_message = &op_inject_message;
    188         global.otr_ops.notify = NULL;
    189         global.otr_ops.display_otr_message = &op_display_otr_message;
    190         global.otr_ops.update_context_list = NULL;
    191         global.otr_ops.protocol_name = NULL;
    192         global.otr_ops.protocol_name_free = NULL;
    193         global.otr_ops.new_fingerprint = &op_new_fingerprint;
    194         global.otr_ops.write_fingerprints = &op_write_fingerprints;
    195         global.otr_ops.gone_secure = &op_gone_secure;
    196         global.otr_ops.gone_insecure = &op_gone_insecure;
    197         global.otr_ops.still_secure = &op_still_secure;
    198         global.otr_ops.log_message = &op_log_message;
    199         global.otr_ops.max_message_size = &op_max_message_size;
    200         global.otr_ops.account_name = &op_account_name;
    201         global.otr_ops.account_name_free = NULL;
     189        otr_ops.policy = &op_policy;
     190        otr_ops.create_privkey = &op_create_privkey;
     191        otr_ops.is_logged_in = &op_is_logged_in;
     192        otr_ops.inject_message = &op_inject_message;
     193        otr_ops.notify = NULL;
     194        otr_ops.display_otr_message = &op_display_otr_message;
     195        otr_ops.update_context_list = NULL;
     196        otr_ops.protocol_name = NULL;
     197        otr_ops.protocol_name_free = NULL;
     198        otr_ops.new_fingerprint = &op_new_fingerprint;
     199        otr_ops.write_fingerprints = &op_write_fingerprints;
     200        otr_ops.gone_secure = &op_gone_secure;
     201        otr_ops.gone_insecure = &op_gone_insecure;
     202        otr_ops.still_secure = &op_still_secure;
     203        otr_ops.log_message = &op_log_message;
     204        otr_ops.max_message_size = &op_max_message_size;
     205        otr_ops.account_name = &op_account_name;
     206        otr_ops.account_name_free = NULL;
    202207       
    203208        root_command_add( "otr", 1, cmd_otr, 0 );
    204 }
    205 
    206 otr_t *otr_new(void)
    207 {
    208         otr_t *otr = g_new0(otr_t, 1);
    209 
    210         otr->us = otrl_userstate_create();
    211        
    212         return otr;
    213 }
    214 
    215 void otr_free(otr_t *otr)
    216 {
     209        register_irc_plugin( &otr_plugin );
     210}
     211
     212gboolean otr_irc_new(irc_t *irc)
     213{
     214        set_t *s;
     215        GSList *l;
     216       
     217        irc->otr = g_new0(otr_t, 1);
     218        irc->otr->us = otrl_userstate_create();
     219       
     220        s = set_add( &irc->b->set, "otr_color_encrypted", "true", set_eval_bool, irc );
     221       
     222        s = set_add( &irc->b->set, "otr_policy", "oppurtunistic", set_eval_list, irc );
     223        l = g_slist_prepend( NULL, "never" );
     224        l = g_slist_prepend( l, "opportunistic" );
     225        l = g_slist_prepend( l, "manual" );
     226        l = g_slist_prepend( l, "always" );
     227        s->eval_data = l;
     228       
     229        return TRUE;
     230}
     231
     232void otr_irc_free(irc_t *irc)
     233{
     234        otr_t *otr = irc->otr;
    217235        otrl_userstate_free(otr->us);
    218236        if(otr->keygen) {
     
    339357        }
    340358       
    341         ignore_msg = otrl_message_receiving(irc->otr->us, &global.otr_ops, ic,
     359        ignore_msg = otrl_message_receiving(irc->otr->us, &otr_ops, ic,
    342360                ic->acc->user, ic->acc->prpl->name, handle, msg, &newmsg,
    343361                &tlvs, NULL, NULL);
     
    393411        }
    394412       
    395         st = otrl_message_sending(irc->otr->us, &global.otr_ops, ic,
     413        st = otrl_message_sending(irc->otr->us, &otr_ops, ic,
    396414                ic->acc->user, ic->acc->prpl->name, handle,
    397415                msg, NULL, &otrmsg, NULL, NULL);
     
    409427                        return 1;
    410428                }
    411                 st = otrl_message_fragment_and_send(&global.otr_ops, ic, ctx,
     429                st = otrl_message_fragment_and_send(&otr_ops, ic, ctx,
    412430                        otrmsg, OTRL_FRAGMENT_SEND_ALL, NULL);
    413431                otrl_message_free(otrmsg);
     
    420438        return st;
    421439}
     440
     441static const struct irc_plugin otr_plugin =
     442{
     443        otr_irc_new,
     444        otr_irc_free,
     445};
    422446
    423447static void cmd_otr(irc_t *irc, char **args)
     
    663687        }
    664688       
    665         otrl_message_disconnect(irc->otr->us, &global.otr_ops,
     689        otrl_message_disconnect(irc->otr->us, &otr_ops,
    666690                u->bu->ic, u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, u->bu->handle);
    667691       
     
    721745                        "SMP already in phase %d, sending abort before reinitiating",
    722746                        ctx->smstate->nextExpected+1);
    723                 otrl_message_abort_smp(irc->otr->us, &global.otr_ops, u->bu->ic, ctx);
     747                otrl_message_abort_smp(irc->otr->us, &otr_ops, u->bu->ic, ctx);
    724748                otrl_sm_state_free(ctx->smstate);
    725749        }
     
    729753        if(ctx->smstate->secret == NULL) {
    730754                irc_usermsg(irc, "smp: initiating with %s...", u->nick);
    731                 otrl_message_initiate_smp(irc->otr->us, &global.otr_ops,
     755                otrl_message_initiate_smp(irc->otr->us, &otr_ops,
    732756                        u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    733757                /* smp is now in EXPECT2 */
     
    736760                   received the SMP1, so let's issue a response */
    737761                irc_usermsg(irc, "smp: responding to %s...", u->nick);
    738                 otrl_message_respond_smp(irc->otr->us, &global.otr_ops,
     762                otrl_message_respond_smp(irc->otr->us, &otr_ops,
    739763                        u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    740764                /* smp is now in EXPECT3 */
     
    10501074        irc_t *irc = ic->bee->ui_data;
    10511075        OtrlUserState us = irc->otr->us;
    1052         OtrlMessageAppOps *ops = &global.otr_ops;
     1076        OtrlMessageAppOps *ops = &otr_ops;
    10531077        OtrlTLV *tlv = NULL;
    10541078        ConnContext *context;
Note: See TracChangeset for help on using the changeset viewer.