1#  annotations.tcl --
2#
3#      This file is part of the jabberlib.
4#      It handles annotations about roster items and other entities,
5#      as described in XEP-0145
6#
7#  Copyright (c) 2009 Sebastian Reitenbach
8#
9# This file is distributed under BSD style license.
10#
11# $Id$
12#
13############################# USAGE ############################################
14#
15#   NAME
16#      annotations - convenience command library for the annotations
17#      storage extension.
18#
19#   SYNOPSIS
20#      jlib::annotations::init jlibName ?-opt value ...?
21#
22#   INSTANCE COMMANDS
23#      jlibname annotations send_get storagens callbackProc
24#      jlibname annotations send_set storagens subtags
25#
26################################################################################
27
28package require jlib::private
29
30package provide jlib::annotations 0.1
31
32namespace eval jlib::annotations {
33
34    # Rosternotes stored as {{jid Notes} ...}
35    variable rosternotes {}
36    variable xmlns
37    set xmlns(rosternotes) "storage:rosternotes"
38    set xmlns(coccinella) "storage:coccinella"
39    set xmlns(bookmarks) "storage:bookmarks"
40
41    # Note: jlib::ensamble_register is last in this file!
42}
43
44# jlib::annotations::init --
45#
46#       Creates a new instance of a annotations object.
47#
48# Arguments:
49#       jlibname:     name of existing jabberlib instance
50#       args:
51#
52# Results:
53#       namespaced instance command
54
55proc jlib::annotations::init {jlibname args} {
56
57    return
58}
59
60# jlib::annotations::cmdproc --
61#
62#       Just dispatches the command to the right procedure.
63#
64# Arguments:
65#       jlibname:   name of existing jabberlib instance
66#       cmd:
67#       args:       all args to the cmd procedure.
68#
69# Results:
70#       none.
71
72proc jlib::annotations::cmdproc {jlibname cmd args} {
73
74    # Which command? Just dispatch the command to the right procedure.
75    return [eval {$cmd $jlibname} $args]
76}
77
78# jlib::annotations::send_get --
79#
80#       It implements the get method of stored data, for
81#       for the given storage namespace.
82#
83# Arguments:
84#       storagens:  retrieve data in given storage xmlns, e.g. rosternotes
85#       cmd:        client command to be executed at the iq "result" element.
86#
87# Results:
88#       none.
89
90proc jlib::annotations::send_get {storagens cmd} {
91    variable xmlns
92
93    set attrlist [list xmlns $xmlns($storagens)]
94    set storageElem [wrapper::createtag "storage" -attrlist $attrlist]
95
96    ::jlib::private::send_get $storageElem $cmd
97}
98
99# jlib::annotations::send_set --
100#
101#       It implements the set method of stored data, for
102#       the given storage namespace.
103#
104# Arguments:
105#       storagens:   send data in given storage xmlns, e.g. rosternotes
106#       subtags:     the data to be stored
107#
108# Results:
109#       none.
110
111proc jlib::annotations::send_set {storagens subtags} {
112    variable xmlns
113
114    ::Debug 4 "jlib::annotations::send_set: storagens=$storagens subtags=$subtags"
115    set attrlist [list xmlns $xmlns($storagens)]
116    set storageElem [wrapper::createtag "storage" -attrlist $attrlist \
117        -subtags $subtags]
118
119    ::jlib::private::send_set $storageElem
120}
121
122# We have to do it here since need the initProc before doing this.
123
124namespace eval jlib::private {
125
126    jlib::ensamble_register private  \
127      [namespace current]::init    \
128      [namespace current]::cmdproc
129}
130