File: xmpp.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (121 lines) | stat: -rw-r--r-- 2,698 bytes parent folder | download | duplicates (4)
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
#  xmpp.tcl --
#  
#      This is a skeleton to create a xmpp library from scratch.
#      The intention is to pick relevant parts from jabberlib and rewrite.
#      Dicts will be used extensively instead of arrays why we require Tcl 8.5.
#      
#  Copyright (c) 2008  Mats Bengtsson
#  
# This file is distributed under BSD style license.
#  
# $Id: xmpp.tcl,v 1.2 2008-09-20 02:32:55 sdevrieze Exp $

package require Tcl 8.5
package require sha1
package require autosocks       ;# wrapper for the 'socket' command.
package require xmpp::xmlns

package provide xmpp 0.1

namespace eval xmpp {

    # Running integer to number xmpp instances.
    variable uid
    
    # Dictionary that keeps track of instance specific things.
    variable state
    
    # Dictionary for registered transports.
    variable transport

    namespace import xmpp::xmlns::ns
}

#--- Static commands ---
#...


# xmpp::create --
#
#       Makes a new xmpp instance object.
#
# Arguments:
#
# Result:
#       A token for this instance which is the objects command.

proc xmpp::create {args} {
    variable state
    variable uid

    set this [namespace current]::[incr uid]
    
    # Just a dummy.
    dict set state $this this $this
    
    # Not sure we need all this. One enough?
    dict set state $this uid iq       1001
    dict set state $this uid presence 1001
    dict set state $this uid message  1001
    
    dict set state $this instream 0

    init_inst $this

    # Create the actual xmpp instance procedure.
    proc $this {cmd args}   \
      "eval xmpp::dispatch {$this} \$cmd \$args"
    
    return $this
}

# xmpp::init_inst --
#
#       This shall be called typically after logging out to reset some
#       state variables that are no longer valid.

proc xmpp::init_inst {this} {
    variable state
    
    dict set state $this my jid      ""
    dict set state $this my jidmap   ""
    dict set state $this my presence "unavailable"
    dict set state $this my status   ""
    dict set state $this my show     ""
    
    
    
}

proc xmpp::dispatch {this cmd args} {
    # Ensable commands???
    return [eval {$cmd $this} $args]   
}

proc xmpp::set_transport {this name initProc sendProc resetProc ipProc} {
    variable transport
    
    dict set transport $this name  $name
    dict set transport $this init  $initProc
    dict set transport $this send  $sendProc
    dict set transport $this reset $resetProc
    dict set transport $this ip    $ipProc
}

proc xmpp::transport {this} {
    variable transport
    return [dict get $transport $this name]
}

proc xmpp::delete {this} {
    variable state
    
    # Free all loaded sub packages.
    
    dict unset state $this
}