File: toc.tcl

package info (click to toggle)
tik 0.75-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 596 kB
  • ctags: 342
  • sloc: tcl: 5,971; makefile: 68; sh: 54
file content (877 lines) | stat: -rw-r--r-- 23,158 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# toc.tcl --
#
# This file contains routines to send toc messages
# and decode incoming message and call registered callbacks.
# Most routines are not commented, see doc/Protocol instead.
#
# $Revision: 1.48 $

# Copyright (c) 1998-9 America Online, Inc. All Rights Reserved.
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# OUTGOING:
# Since we handle having multiple toc connections the
# first argument to ALL toc_ methods is the connection
# "name".   This name doesn't have to be the screenname
# used by the connection, but that is usually a convient
# name to use.  We ALWAYS normalize the connection name 
# before using it.
#
# We have matching toc_ methods for all the toc_ methods mentioned
# in the doc/Protocol file, with the exact same arguments with two exceptions:
#    1) An extra first argument of the connection name (see above)
#    2) All variable length arguments are done with a tcl list
#
# All outgoing messages can be registered for using toc_register_func.
# The arguments and the function name to register for are the same
# as the toc function you are calling.
#
# INCOMING:
# Again since we support multiple toc connections all incoming
# message have a connection name.  You first must register
# what procedure you want called when a particular toc message
# is received.  You do this by calling toc_register_func
#
# We support all the incoming messages in doc/Protocol,
# and parse the arguments out before calling the registered
# procedure.  Again the first argument to the registered
# procedure will be the connection name, and variable
# length arguments are turned in to lists.

# Load the low level sflap routines.
source sflap.tcl

# Load the utility routines
source util.tcl

# toc_open -- 
#     Utility function that opens the sflap connection and sends 
#     the toc_signon message.
#
# Arguments:
#     connName - name to give the SFLAP connection
#     tochost  - hostname of TOC server
#     tocport  - port of TOC server
#     authhost - hostname of OSCAR authorizer
#     authport - port of OSCAR authorizer
#     sn       - user's screen name
#     pw       - user's password
#     lang     - language to use.
#     version  - client version string
#     proxy    - proxy to use
proc toc_open {connName tochost tocport authhost authport sn pw lang 
              {version "toc.tcl Unknown"} {proxy ""}} {

    # Have extra updates here for when toc.tcl is used for stress testing.
    update
    sflap::connect [normalize $connName] $tochost $tocport [normalize $sn] \
        $proxy
    update
    toc_signon $connName $authhost $authport $sn $pw $lang $version
    update

    incr ::TOCSTATS(toc_open)
}

#
# toc_close --
#     Just a matching for toc_open.  Close the TOC and SFLAP connection.
#
# Arguments:
#     connName - SFLAP connection name.

proc toc_close {connName} {
    set norm [normalize $connName]

    sflap::close $norm

    if {$::TOCSTATS($norm,ONLINE)} {
        incr ::TOCSTATS(ONLINE) -1
    } else {
        incr ::TOCSTATS(TOTAUTHFAIL)
    }

    unset ::TOCSTATS($norm,ONLINE)

    incr ::TOCSTATS(CONNECTED) -1
    incr ::TOCSTATS(toc_close)
}

# toc_register_func --
#     Register the proc to be called
#     when certain messages are received.  A connName of
#     "*" implies all connections should use that function
#
# Arguments:
#     connName - name of SFLAP connection or "*" = all
#     cmd      - the PROTOCOL cmd
#     func     - the callback that is executed when cmd is received.

proc toc_register_func {connName cmd func} {
    if {$connName != "*"} {
        set connName [normalize $connName]
    }

    lappend ::FUNCS($connName,$cmd) $func

    incr ::TOCSTATS(toc_register_func)
}

# toc_unregister_func --
#     Unregister the proc to be called when certain messages are received.
#     A connName of "*" implies all connections should unregister that function
#
# Arguments:
#     connName - name of SFLAP connection or "*" = all
#     cmd      - the PROTOCOL cmd
#     func     - the callback that is executed when cmd is received.

proc toc_unregister_func {connName cmd func} {
    if {$connName != "*"} {
        set connName [normalize $connName]
    }

    set i [lsearch -exact $::FUNCS($connName,$cmd) $func]
    if {$i != -1} {
        set ::FUNCS($connName,$cmd) [lreplace $::FUNCS($connName,$cmd) $i $i]
    }

    incr ::TOCSTATS(toc_unregister_func)
}

# toc_unregister_all --
#     Remove all the proc registrations for a particular connection.
#
# Arguments:
#     connName - name of SFLAP connection or "*" = all

proc toc_unregister_all {connName} {
    if {$connName != "*"} {
        set connName [normalize $connName]
    } else {
        set connName "\\\*"
    }

    foreach i [array names ::FUNCS "$connName,*"] {
        unset ::FUNCS($i)
    }

    incr ::TOCSTATS(toc_unregister_all)
}

#******************************************************
#******************OUTGOING PROTOCOL ******************
#******************************************************

# These are documented in the PROTOCOL document

proc toc_signon {connName authhost authport sn pw lang 
                 {version "toc.tcl Unknown"}} {

    if {[string  match "0x0x*" $pw]} {
        set cpw [string range $pw 2 end]
    } else {
        set cpw [roast_password $pw]
    }

    set norm [normalize $connName]

    set ::TOCSTATS($norm,ONLINE) 0

    set result [sflap::send $norm "toc_signon $authhost $authport \
                [normalize $sn] $cpw $lang [encode $version]"]

    if {$result} {
        incr ::TOCSTATS(CONNECTED)
        incr ::TOCSTATS(TOTCONNECTED)
    }
    incr ::TOCSTATS(toc_signon)

    return $result
}

proc toc_init_done {connName} {
    sflap::send [normalize $connName] "toc_init_done"

    set funcs [p_getFuncList $connName toc_init_done]
    foreach func $funcs {
        $func $connName
    }

    incr ::TOCSTATS(toc_init_done)
}

proc toc_send_im {connName nick msg {auto ""}} {
    sflap::send [normalize $connName] "toc_send_im [normalize $nick]\
                                       [encode $msg] $auto" 

    set funcs [p_getFuncList $connName toc_send_im]
    foreach func $funcs {
        $func $connName $nick $msg $auto
    }

    incr ::TOCSTATS(toc_send_im)
}

proc toc_add_buddy {connName blist} {
    set str "toc_add_buddy"
    foreach i $blist {
        append str " " [normalize $i]
    }
    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_add_buddy]
    foreach func $funcs {
        $func $connName $blist
    }

    incr ::TOCSTATS(toc_add_buddy)
}

proc toc_remove_buddy {connName blist} {
    set str "toc_remove_buddy"
    foreach i $blist {
        append str " " [normalize $i]
    }
    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_remove_buddy]
    foreach func $funcs {
        $func $connName $blist
    }

    incr ::TOCSTATS(toc_remove_buddy)
}

proc toc_set_config {connName config} {
    sflap::send [normalize $connName] "toc_set_config {$config}" 

    set funcs [p_getFuncList $connName toc_set_config]
    foreach func $funcs {
        $func $connName $config
    }

    incr ::TOCSTATS(toc_set_config)
}

proc toc_set_away {connName {msg ""}} {

    if {[string length $msg] == 0} {
        sflap::send [normalize $connName] "toc_set_away" 
    } else {
        sflap::send [normalize $connName] "toc_set_away [encode $msg]" 
    }

    set funcs [p_getFuncList $connName toc_set_config]
    foreach func $funcs {
        $func $connName $msg
    }

    incr ::TOCSTATS(toc_set_away)
}

proc toc_evil {connName nick {anon F}} {
    if {$anon == "T" || $anon == "anon"} {
        sflap::send [normalize $connName] "toc_evil [normalize $nick] anon" 
    } else {
        sflap::send [normalize $connName] "toc_evil [normalize $nick] norm" 
    }

    set funcs [p_getFuncList $connName toc_evil]
    foreach func $funcs {
        $func $connName $nick $anon
    }

    incr ::TOCSTATS(toc_evil)
}

proc toc_add_permit {connName {plist {}}} {
    set str "toc_add_permit"
    foreach i $plist {
        append str " " [normalize $i]
    }
    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_add_permit]
    foreach func $funcs {
        $func $connName $plist
    }

    incr ::TOCSTATS(toc_add_permit)
}

proc toc_add_deny {connName {dlist {}}} {
    set str "toc_add_deny"
    foreach i $dlist {
        append str " " [normalize $i]
    }
    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_add_deny]
    foreach func $funcs {
        $func $connName $dlist
    }

    incr ::TOCSTATS(toc_add_deny)
}

proc toc_chat_join {connName exchange loc} {
    sflap::send [normalize $connName] "toc_chat_join $exchange [encode $loc]"

    set funcs [p_getFuncList $connName toc_chat_join]
    foreach func $funcs {
        $func $connName $exchange $loc
    }

    incr ::TOCSTATS(toc_chat_join)
}

proc toc_chat_send {connName roomid msg} {
    sflap::send [normalize $connName] "toc_chat_send $roomid [encode $msg]"

    set funcs [p_getFuncList $connName toc_chat_send]
    foreach func $funcs {
        $func $connName $roomid $msg
    }

    incr ::TOCSTATS(toc_chat_send)
}

proc toc_chat_whisper {connName roomid user msg} {
    sflap::send [normalize $connName] "toc_chat_whisper $roomid\
                                       [normalize $user] [encode $msg]"

    set funcs [p_getFuncList $connName toc_chat_whisper]
    foreach func $funcs {
        $func $connName $roomid $user $msg
    }

    incr ::TOCSTATS(toc_chat_whisper)
}

proc toc_chat_invite {connName roomid msg people} {
    sflap::send [normalize $connName] "toc_chat_invite $roomid\
                                       [encode $msg] $people"

    set funcs [p_getFuncList $connName toc_chat_invite]
    foreach func $funcs {
        $func $connName $roomid $msg $people
    }

    incr ::TOCSTATS(toc_chat_invite)
}

proc toc_chat_leave {connName roomid} {
    sflap::send [normalize $connName] "toc_chat_leave $roomid"

    set funcs [p_getFuncList $connName toc_chat_leave]
    foreach func $funcs {
        $func $connName $roomid
    }

    incr ::TOCSTATS(toc_chat_leave)
}

proc toc_chat_accept {connName roomid} {
    sflap::send [normalize $connName] "toc_chat_accept $roomid"

    set funcs [p_getFuncList $connName toc_chat_accept]
    foreach func $funcs {
        $func $connName $roomid
    }

    incr ::TOCSTATS(toc_chat_accept)
}

proc toc_get_info {connName nick} {
    sflap::send [normalize $connName] "toc_get_info [normalize $nick]" 
    p_simpleFunc $connName $nick toc_get_info
    incr ::TOCSTATS(toc_get_info)
}

proc toc_set_info {connName info} {
    sflap::send [normalize $connName] "toc_set_info [encode $info]" 

    p_simpleFunc $connName $info toc_set_info

    incr ::TOCSTATS(toc_set_info)
}

proc toc_set_idle {connName idlesecs} {
    sflap::send [normalize $connName] "toc_set_idle $idlesecs" 

    set funcs [p_getFuncList $connName toc_set_idle]
    foreach func $funcs {
        $func $connName $idlesecs
    }

    incr ::TOCSTATS(toc_set_idle)
}

proc toc_get_dir {connName nick} {
    sflap::send [normalize $connName] "toc_get_dir [normalize $nick]"
    p_simpleFunc $connName $nick toc_get_dir

    incr ::TOCSTATS(toc_get_dir)
}

proc toc_set_dir {connName dir_info} {
    sflap::send [normalize $connName] "toc_set_dir [encode $dir_info]"
    p_simpleFunc $connName $dir_info toc_set_dir

    incr ::TOCSTATS(toc_set_dir)
}

proc toc_dir_search {connName dir_info} {
    sflap::send [normalize $connName] "toc_dir_search [encode $dir_info]"
    p_simpleFunc $connName $dir_info toc_dir_search

    incr ::TOCSTATS(toc_dir_search)
}

proc toc_set_caps {connName clist} {
    set str "toc_set_caps"
    foreach i $clist {
        append str " " $i
    }
    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_set_caps]
    foreach func $funcs {
        $func $connName $clist
    }

    incr ::TOCSTATS(toc_set_caps)
}

proc toc_rvous_accept {connName nick cookie service tlvlist} {
    set str "toc_rvous_accept [normalize $nick] $cookie $service" 

    foreach i $tlvlist {
        append str " " $i
    }

    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_rvous_accept]
    foreach func $funcs {
        $func $connName $nick $cookie $service $tlvlist
    }

    incr ::TOCSTATS(toc_rvous_accept)
}

proc toc_rvous_cancel {connName nick cookie service tlvlist} {
    set str "toc_rvous_cancel [normalize $nick] $cookie $service" 

    foreach i $tlvlist {
        append str " " $i
    }

    sflap::send [normalize $connName] $str

    set funcs [p_getFuncList $connName toc_rvous_cancel]
    foreach func $funcs {
        $func $connName $nick $cookie $service $tlvlist
    }

    incr ::TOCSTATS(toc_rvous_cancel)
}

proc toc_format_nickname {connName new_name} {
    sflap::send [normalize $connName] "toc_format_nickname {$new_name}"

    set funcs [p_getFuncList $connName toc_format_nickname]
    foreach func $funcs {
        $func $connName $new_name
    }

    incr ::TOCSTATS(toc_format_nickname)
}

proc toc_change_passwd {connName old_passwd new_passwd} {
    sflap::send [normalize $connName] "toc_change_passwd {$old_passwd} {$new_passwd}"

    set funcs [p_getFuncList $connName toc_change_passwd]
    foreach func $funcs {
        $func $connName $old_passwd $new_passwd
    }

    incr ::TOCSTATS(toc_change_passwd)
}

#******************************************************
#******************INCOMING PROTOCOL ******************
#******************************************************

# These are documented in the PROTOCOL document

proc p_getFuncList {connName func} {
    if {[catch {set al $::FUNCS(*,$func)}] != 0} {
        set al [list]
    }

    if {[catch {set l $::FUNCS($connName,$func)}] == 0} {
        return [concat $al $l]
    }

    return $al
}

proc p_simpleFunc {connName data func} {
    set funcs [p_getFuncList $connName $func]
    foreach func $funcs {
        $func $connName $data
    }
}

proc scmd_SIGN_ON {connName data} {
    incr ::TOCSTATS(SIGN_ON)

    if {! $::TOCSTATS($connName,ONLINE)} {
        set ::TOCSTATS($connName,ONLINE) 1
        incr ::TOCSTATS(ONLINE)
        incr ::TOCSTATS(TOTONLINE)
    }
    p_simpleFunc $connName $data SIGN_ON
}

proc scmd_CONFIG {connName data} {
    incr ::TOCSTATS(CONFIG)

    p_simpleFunc $connName $data CONFIG
}

proc scmd_NICK {connName data} {
    incr ::TOCSTATS(NICK)

    p_simpleFunc $connName $data NICK
}

proc scmd_IM_IN {connName data} {
    incr ::TOCSTATS(IM_IN)

    set args [split $data ":"]
    set source [lindex $args 0]
    set sourcel [string length $source]
    set auto [lindex $args 1]
    set msg [string range $data [expr $sourcel + 3] end]

    set funcs [p_getFuncList $connName IM_IN]
    foreach func $funcs {
        $func $connName $source $msg $auto
    }
}

proc scmd_UPDATE_BUDDY {connName data} {
    incr ::TOCSTATS(UPDATE_BUDDY)

    set args [split $data ":"]
    set user   [lindex $args 0]
    set online [lindex $args 1]
    set evil   [lindex $args 2]
    set signon [lindex $args 3]
    set idle   [lindex $args 4]
    set uclass [lindex $args 5]

    set funcs [p_getFuncList $connName UPDATE_BUDDY]
    foreach func $funcs {
        $func $connName $user $online $evil $signon $idle $uclass
    }
}

proc scmd_ERROR {connName data} {
    incr ::TOCSTATS(ERROR)

    set args [split $data ":"]
    set code [string range $args 0 2]
    if {[string length $data] > 4} {
        set args [string range $args 4 end]
    } else {
        set args ""
    }

    set funcs [p_getFuncList $connName ERROR]
    foreach func $funcs {
        $func $connName $code $args
    }
}

proc scmd_EVILED {connName data} {
    incr ::TOCSTATS(EVILED)

    set args [split $data ":"]
    set level [lindex $args 0]
    set eviler [lindex $args 1]

    set funcs [p_getFuncList $connName EVILED]
    foreach func $funcs {
        $func $connName $level $eviler
    }
}

proc scmd_CHAT_JOIN {connName data} {
    incr ::TOCSTATS(CHAT_JOIN)

    set args [split $data ":"]
    set id [lindex $args 0]
    set loc [lindex $args 1]

    set funcs [p_getFuncList $connName CHAT_JOIN]
    foreach func $funcs {
        $func $connName $id $loc
    }
}

proc scmd_CHAT_IN {connName data} {
    incr ::TOCSTATS(CHAT_IN)

    set args [split $data ":"]
    set id [lindex $args 0]
    set idl [string length $id]
    set source [lindex $args 1]
    set sourcel [string length $source]
    set whisper [lindex $args 2]
    set msg [string range $data [expr $idl + $sourcel + 4] end]

    set funcs [p_getFuncList $connName CHAT_IN]
    foreach func $funcs {
        $func $connName $id $source $whisper $msg
    }
}

proc scmd_CHAT_UPDATE_BUDDY {connName data} {
    incr ::TOCSTATS(CHAT_UPDATE_BUDDY)

    set args [split $data ":"]
    set id [lindex $args 0]
    set online [lindex $args 1]
    set argsl [llength $args]

    set blist [list]
    for {set i 2} {$i < $argsl} {incr i} {
        set p [lindex $args $i]
        lappend blist $p
    }

    set funcs [p_getFuncList $connName CHAT_UPDATE_BUDDY]
    foreach func $funcs {
        $func $connName $id $online $blist
    }
}

proc scmd_CHAT_INVITE {connName data} {
    incr ::TOCSTATS(CHAT_INVITE)

    set args [split $data ":"]
    set loc [lindex $args 0]
    set locl [string length $loc]
    set id [lindex $args 1]
    set idl [string length $id]
    set sender [lindex $args 2]
    set senderl [string length $sender]
    set msg [string range $data [expr $locl + $idl + $senderl + 3] end]

    set funcs [p_getFuncList $connName CHAT_INVITE]
    foreach func $funcs {
        $func $connName $loc $id $sender $msg
    }
}

proc scmd_CHAT_LEFT {connName data} {
    incr ::TOCSTATS(CHAT_LEFT)

    p_simpleFunc $connName $data CHAT_LEFT
}

proc scmd_GOTO_URL {connName data} {
    incr ::TOCSTATS(GOTO_URL)

    set args [split $data ":"]
    set window [lindex $args 0]
    set windowl [string length $window]
    incr windowl
    set url [string range $data $windowl end]

    set funcs [p_getFuncList $connName GOTO_URL]
    foreach func $funcs {
        $func $connName $window $url 
    }
}

proc scmd_PAUSE {connName data} {
    incr ::TOCSTATS(PAUSE)

    p_simpleFunc $connName $data PAUSE
}

proc scmd_CONNECTION_CLOSED {connName reason} {
    incr ::TOCSTATS(CONNECTION_CLOSED)

    p_simpleFunc $connName $reason CONNECTION_CLOSED
    if {$::TOCSTATS($connName,ONLINE)} {
        incr ::TOCSTATS(ONLINE) -1
    } else {
        incr ::TOCSTATS(TOTAUTHFAIL)
    }
    unset ::TOCSTATS($connName,ONLINE)
    incr ::TOCSTATS(CONNECTED) -1
}

proc scmd_DIR_STATUS {connName data} {
    incr ::TOCSTATS(DIR_STATUS)

    set args [split $data ":"]
    set code [string range $args 0 2]
    if {[string length $data] > 4} {
        set args [string range $args 4 end]
    } else {
        set args ""
    }

    set funcs [p_getFuncList $connName DIR_STATUS]
    foreach func $funcs {
        $func $connName $code $args
    }
}

proc scmd_ADMIN_NICK_STATUS {connName data} {
    incr ::TOCSTATS(ADMIN_NICK_STATUS)

    set args [split $data ":"]
    set code [string range $args 0 2]
    if {[string length $data] > 4} {
        set args [string range $args 4 end]
    } else {
        set args ""
    }

    set funcs [p_getFuncList $connName ADMIN_NICK_STATUS]
    foreach func $funcs {
        $func $connName $code $args
    }
}

proc scmd_ADMIN_PASSWD_STATUS {connName data} {
    incr ::TOCSTATS(ADMIN_PASSWD_STATUS)

    set args [split $data ":"]
    set code [string range $args 0 2]
    if {[string length $data] > 4} {
        set args [string range $args 4 end]
    } else {
        set args ""
    }

    set funcs [p_getFuncList $connName ADMIN_PASSWD_STATUS]
    foreach func $funcs {
        $func $connName $code $args
    }
}

proc scmd_RVOUS_PROPOSE {connName data} {
    incr ::TOCSTATS(RVOUS_PROPOSE)

    set args [split $data ":"]

    set user [lindex $args 0]
    set uuid [lindex $args 1]
    set cookie [lindex $args 2]
    set seq [lindex $args 3]
    set rip [lindex $args 4]
    set pip [lindex $args 5]
    set vip [lindex $args 6]
    set port [lindex $args 7]

    set ltlvs ""

    set largs [llength $args]
    set i 8
    while {$i < $largs} {
        set num [lindex $args $i]
        incr i
        set value [lindex $args $i]
        incr i

        lappend ltlvs $num
        lappend ltlvs [fromBase64 $value]
    }

    set funcs [p_getFuncList $connName RVOUS_PROPOSE]
    foreach func $funcs {
        $func $connName $user $uuid $cookie $seq $rip $pip $vip $port $ltlvs
    }
}

# We keep stats that are used by the testing tools.  These aren't
# need for TiK, so I guess we could remove them. :-)
set ::TOCSTATS(toc_open) 0
set ::TOCSTATS(toc_close) 0
set ::TOCSTATS(toc_register_func) 0
set ::TOCSTATS(toc_unregister_func) 0
set ::TOCSTATS(toc_unregister_all) 0
set ::TOCSTATS(TOTCONNECTED) 0
set ::TOCSTATS(CONNECTED) 0
set ::TOCSTATS(TOTONLINE) 0
set ::TOCSTATS(ONLINE) 0
set ::TOCSTATS(TOTAUTHFAIL) 0
set ::TOCSTATS(toc_signon) 0
set ::TOCSTATS(toc_init_done) 0
set ::TOCSTATS(toc_send_im) 0
set ::TOCSTATS(toc_add_buddy) 0
set ::TOCSTATS(toc_remove_buddy) 0
set ::TOCSTATS(toc_set_config) 0
set ::TOCSTATS(toc_set_away) 0
set ::TOCSTATS(toc_evil) 0
set ::TOCSTATS(toc_add_permit) 0
set ::TOCSTATS(toc_add_deny) 0
set ::TOCSTATS(toc_chat_join) 0
set ::TOCSTATS(toc_chat_send) 0
set ::TOCSTATS(toc_chat_whisper) 0
set ::TOCSTATS(toc_chat_invite) 0
set ::TOCSTATS(toc_chat_leave) 0
set ::TOCSTATS(toc_chat_accept) 0
set ::TOCSTATS(toc_get_info) 0
set ::TOCSTATS(toc_set_info) 0
set ::TOCSTATS(toc_set_idle) 0
set ::TOCSTATS(toc_get_dir) 0
set ::TOCSTATS(toc_set_dir) 0
set ::TOCSTATS(toc_dir_search) 0
set ::TOCSTATS(toc_set_caps) 0
set ::TOCSTATS(toc_rvous_accept) 0
set ::TOCSTATS(toc_rvous_cancel) 0
set ::TOCSTATS(toc_format_nickname) 0
set ::TOCSTATS(toc_change_passwd) 0

set ::TOCSTATS(SIGN_ON) 0
set ::TOCSTATS(CONFIG) 0
set ::TOCSTATS(NICK) 0
set ::TOCSTATS(IM_IN) 0
set ::TOCSTATS(UPDATE_BUDDY) 0
set ::TOCSTATS(ERROR) 0
set ::TOCSTATS(EVILED) 0
set ::TOCSTATS(CHAT_JOIN) 0
set ::TOCSTATS(CHAT_IN) 0
set ::TOCSTATS(CHAT_UPDATE_BUDDY) 0
set ::TOCSTATS(CHAT_INVITE) 0
set ::TOCSTATS(CHAT_LEFT) 0
set ::TOCSTATS(GOTO_URL) 0
set ::TOCSTATS(PAUSE) 0
set ::TOCSTATS(CONNECTION_CLOSED) 0
set ::TOCSTATS(DIR_STATUS) 0
set ::TOCSTATS(RVOUS_PROPOSE) 0
set ::TOCSTATS(ADMIN_NICK_STATUS) 0
set ::TOCSTATS(ADMIN_PASSWD_STATUS) 0