Tkabber plugins

Check-in [6470c20ee5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use own procedures to store, discard and resend messages after refreshing broken OTR conversation. Moved drawing OTR message icon for outgoing messages to draw_message_hook where it is more appropriate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6470c20ee5ac6161a26766bd61a431fc46dce410
User & Date: sgolovan 2016-01-02 13:14:46
Context
2016-01-04
09:18
Reset the keys counter after the AKE completion in case when the correspondent's keys have been changed. check-in: 8db11eebd1 user: sgolovan tags: trunk
2016-01-02
13:14
Use own procedures to store, discard and resend messages after refreshing broken OTR conversation. Moved drawing OTR message icon for outgoing messages to draw_message_hook where it is more appropriate. check-in: 6470c20ee5 user: sgolovan tags: trunk
13:10
Fixed a small bug in returning "can't decrypt" message. Added -discardcommand and -resendcommand options to the otr::new procedure. They allow the caling application to replace built-in storing, discarding and resending routines. check-in: df5f8fe66e user: sgolovan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.

1
2
3
4





5
6
7
8
9
10
11
2016-01-02  Sergei Golovan  <sgolovan@nes.ru>

	* receipts/receipts.tcl: Adjusted priority for the icon drawing
	  procedure.






2015-12-27  Sergei Golovan  <sgolovan@nes.ru>

	* otr/otr.tcl: Display more appropriate error messages in case of
	  received OTR request but without any OTR key configured.

	* otr/msgs/ru.msg, otr/msgs/uk.msg: Updated Russian and Ukrainian




>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2016-01-02  Sergei Golovan  <sgolovan@nes.ru>

	* receipts/receipts.tcl: Adjusted priority for the icon drawing
	  procedure.

	* otr/otr.tcl: Use own procedures to store, discard and resend messages
	  after refreshing broken OTR conversation. Moved drawing OTR message
	  icon for outgoing messages to draw_message_hook where it is more
	  appropriate.

2015-12-27  Sergei Golovan  <sgolovan@nes.ru>

	* otr/otr.tcl: Display more appropriate error messages in case of
	  received OTR request but without any OTR key configured.

	* otr/msgs/ru.msg, otr/msgs/uk.msg: Updated Russian and Ukrainian

Changes to otr/otr.tcl.

149
150
151
152
153
154
155

156
157

158
159
160
161
162
163
164
165
166
167


168



169















170
171
172
173
174
175
176
177
    variable ns
    variable ctx

    if {$type ne "chat"} return

    set xlib [chat::get_xlib $chatid]
    set jid [chat::get_jid $chatid]


    if {![::xmpp::jid::equal $jid $from]} return


    foreach xe $x {
        ::xmpp::xml::split $xe tag xmlns attrs cdata subels

        if {$tag eq "" && $xmlns eq $ns} {
            set chatw [chat::chat_win $chatid]
            $chatw image create end -image [::xmpp::xml::getAttr $attrs icon]
            break
        }
    }


}



















hook::add draw_message_hook [namespace current]::otr::draw_encrypted 6

#############################################################################

proc otr::process_x_encrypted {rowvar bodyvar f x xlib from id type replyP} {
    variable ns
    variable ctx
    upvar 2 $rowvar row







>

|
>

|
|

|
<
|
|
|
|
>
>
|
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
    variable ns
    variable ctx

    if {$type ne "chat"} return

    set xlib [chat::get_xlib $chatid]
    set jid [chat::get_jid $chatid]
    set chatw [chat::chat_win $chatid]

    if {[::xmpp::jid::equal $jid $from]} {
        # Incoming message

        foreach xe $x {
            ::xmpp::xml::split $xe tag xmlns attrs cdata subels

            if {$tag eq "" && $xmlns eq $ns} {

                $chatw image create end -image [::xmpp::xml::getAttr $attrs icon]
                break
            }
        }
    } else {
        # Outgoing message

        set draw 1
        foreach xe $x {
            ::xmpp::xml::split $xe tag xmlns attrs cdata subels

            # Don't draw the icon for the messages from the log
            # TODO: store the OTR attribute in the log and draw
            # the icon for these messages as well
            if {$tag eq "" && $xmlns eq "tkabber:x:nolog"} {
                set draw 0
                break
            }
        }

        if {$draw && [msgstate:index $xlib $jid] > 0} {
            $chatw image create end -image [msgstate:icon $xlib $jid]
        }
    }
}

hook::add draw_message_hook [namespace current]::otr::draw_encrypted 5.4

#############################################################################

proc otr::process_x_encrypted {rowvar bodyvar f x xlib from id type replyP} {
    variable ns
    variable ctx
    upvar 2 $rowvar row
230
231
232
233
234
235
236
237


238
239
240
241
242
243
244
                                                       $xlib $jid]] \
                -smpstatecommand [namespace code [list on_smpstate_change \
                                                       $xlib $jid]] \
                -smpprogresscommand [namespace code [list progress_smp \
                                                          $xlib $jid]] \
                -infocommand [namespace code [list show_info $xlib $jid]] \
                -errorcommand [namespace code [list show_error $xlib $jid]] \
                -sendcommand [namespace code [list send $xlib $jid]]]


    return 1
}

proc otr::clear {xlib jid} {
    variable ctx

    if {[info exists ctx($xlib,$jid)]} {







|
>
>







251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
                                                       $xlib $jid]] \
                -smpstatecommand [namespace code [list on_smpstate_change \
                                                       $xlib $jid]] \
                -smpprogresscommand [namespace code [list progress_smp \
                                                          $xlib $jid]] \
                -infocommand [namespace code [list show_info $xlib $jid]] \
                -errorcommand [namespace code [list show_error $xlib $jid]] \
                -sendcommand [namespace code [list send $xlib $jid]] \
                -discardcommand [namespace code [list discard $xlib $jid]] \
                -resendcommand [namespace code [list resend $xlib $jid]]]
    return 1
}

proc otr::clear {xlib jid} {
    variable ctx

    if {[info exists ctx($xlib,$jid)]} {
358
359
360
361
362
363
364
























































365
366
367
368
369
370
371
    if {[info exists type] && $type eq "chat"} {
        set targs [list -type $type]
    } else {
        set targs {}
    }
    ::xmpp::sendMessage $xlib $jid -body $message {*}$targs
}

























































#############################################################################

proc otr::update_heartbeat {args} {
    variable options
    variable ctx








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
    if {[info exists type] && $type eq "chat"} {
        set targs [list -type $type]
    } else {
        set targs {}
    }
    ::xmpp::sendMessage $xlib $jid -body $message {*}$targs
}

#############################################################################

proc otr::store {xlib jid isid id istype type issubject subject
                 isbody body iserr err isthread thread isx x} {
    variable ctx

    if {[info exists ctx($xlib,$jid)]} {
        # Store only the last message

        set ctx(stored,$xlib,$jid) \
            [list $isid $id $istype $type $issubject $subject \
                  $isbody $body $iserr $err $isthread $thread $isx $x]
    }
}

proc otr::discard {xlib jid} {
    variable ctx

    if {[info exists ctx($xlib,$jid)]} {
        set ctx(stored,$xlib,$jid) {}
    }
}

proc otr::resend {xlib jid} {
    variable ctx

    if {[info exists ctx($xlib,$jid)] && [info exists ctx(stored,$xlib,$jid)]} {
        set opts {}
        foreach {isid id istype type issubject subject isbody body
                 iserr err isthread thread isx x} $ctx(stored,$xlib,$jid) {
            if {$isid} {
                lappend opts -id $id
            }
            if {$istype} {
                lappend opts -type $type
            }
            if {$issubject} {
                lappend opts -subject $subject
            }
            if {$isbody} {
                lappend opts -body $body
            }
            if {$iserr} {
                lappend opts -error $err
            }
            if {$isthread} {
                lappend opts -thread $thread
            }
            if {$isx} {
                lappend opts -xlist $x
            }
            ::message::send_msg $xlib $jid {*}$opts
        }
    }
}

#############################################################################

proc otr::update_heartbeat {args} {
    variable options
    variable ctx

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136














1137
1138
1139
1140
1141
1142


1143



1144
1145
1146
1147
1148
1149
1150
1151
1152






















1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
    return
}

hook::add process_message_hook [namespace current]::otr::discard_message 0.1

###############################################################################

proc otr::rewrite_outgoing_message_body \
     {vxlib vto vid vtype vsubject vbody verr vthread vx} {
    upvar 2 $vxlib xlib
    upvar 2 $vto to
    upvar 2 $vtype type
    upvar 2 $vbody body
    variable ctx















    # Only chat and normal messages are subject to OTR
    if {[info exists type] &&
        $type ne "" && $type ne "normal" && $type ne "chat"} return

    # Only messages with body are subject to OTR


    if {![info exists body]} return




    if {![once_only $xlib $to]} return

    # Only the message body is encrypted if appropriate
    set result [::otr::outgoingMessage $ctx($xlib,$to) $body]

    debugmsg otr "OUTGOING MESSAGE: $xlib; $to; $result;"

    array set res $result























    if {[info exists res(message)]} {
        set body $res(message)
    } else {
        # Disable sending
        hook::unset_flag rewrite_outgoing_message_hook send

        # Don't show this message in the chat log window
        # This flag makes sense only for chat messages, but causes no harm for
        # normal ones
        hook::unset_flag chat_send_message_hook draw
    }
    return
}

hook::add rewrite_outgoing_message_hook \
          [namespace current]::otr::rewrite_outgoing_message_body 10

proc otr::add_icon_to_chat_window \
     {vxlib vto vid vtype vsubject vbody verr vthread vx} {
    upvar 2 $vxlib xlib
    upvar 2 $vto to
    upvar 2 $vtype type

    if {![hook::is_flag rewrite_outgoing_message_hook send]} return

    if {[info exists type] && $type eq "chat" &&
                              [msgstate:index $xlib $to] > 0} {
        set chatid [chat::chatid $xlib $to]
        set chatw [chat::chat_win $chatid]
        if {[winfo exists $chatw]} {
            $chatw image create end -image [msgstate:icon $xlib $to]
        }
    }
    return
}

hook::add rewrite_outgoing_message_hook \
          [namespace current]::otr::add_icon_to_chat_window 90

###############################################################################

proc otr::disable_log {chatid from type body x} {
    set xlib [chat::get_xlib $chatid]
    set jid [chat::get_jid $chatid]

    if {[log_is_disabled $xlib $jid]} {







|






>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>

>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290






















1291
1292
1293
1294
1295
1296
1297
    return
}

hook::add process_message_hook [namespace current]::otr::discard_message 0.1

###############################################################################

proc otr::store_original_message_body \
     {vxlib vto vid vtype vsubject vbody verr vthread vx} {
    upvar 2 $vxlib xlib
    upvar 2 $vto to
    upvar 2 $vtype type
    upvar 2 $vbody body
    variable ctx

    if {![info exists body]} return
    if {![info exists ctx($xlib,$to)]} return

    set ctx(original_message_body,$xlib,$to) $body
}

hook::add rewrite_outgoing_message_hook \
          [namespace current]::otr::store_original_message_body 1

proc otr::rewrite_outgoing_message_body \
     {vxlib vto vid vtype vsubject vbody verr vthread vx} {
    variable ctx
    upvar 2 $vtype type

    # Only chat and normal messages are subject to OTR
    if {[info exists type] &&
        $type ne "" && $type ne "normal" && $type ne "chat"} return

    # Only messages with body are subject to OTR
    upvar 2 $vbody body

    if {![info exists body]} return

    upvar 2 $vxlib xlib
    upvar 2 $vto to

    if {![once_only $xlib $to]} return

    # Only the message body is encrypted if appropriate
    set result [::otr::outgoingMessage $ctx($xlib,$to) $body]

    debugmsg otr "OUTGOING MESSAGE: $xlib; $to; $result;"

    array set res $result

    if {[info exists res(store)] && $res(store)} {
        upvar 2 $vid id
        upvar 2 $vsubject subject
        upvar 2 $verr err
        upvar 2 $vthread thread
        upvar 2 $vx x

        foreach v {id type subject err thread x} {
            if {[info exists $v]} {
                set is$v 1
                set n$v [set $v]
            } else {
                set is$v 0
                set n$v ""
            }
        }

        store $xlib $to $isid $nid $istype $ntype $issubject $nsubject \
              1 $ctx(original_message_body,$xlib,$to) \
              $iserr $nerr $isthread $nthread $isx $nx
    }

    if {[info exists res(message)]} {
        set body $res(message)
    } else {
        # Disable sending
        hook::unset_flag rewrite_outgoing_message_hook send

        # Don't show this message in the chat log window
        # This flag makes sense only for chat messages, but causes no harm for
        # normal ones
        hook::unset_flag chat_send_message_hook draw
    }
    return
}

hook::add rewrite_outgoing_message_hook \
          [namespace current]::otr::rewrite_outgoing_message_body 10























###############################################################################

proc otr::disable_log {chatid from type body x} {
    set xlib [chat::get_xlib $chatid]
    set jid [chat::get_jid $chatid]

    if {[log_is_disabled $xlib $jid]} {