File: ICQ.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (121 lines) | stat: -rw-r--r-- 3,169 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
# ICQ.tcl --
# 
#       Provides some specific ICQ handling elements.
#
#  Copyright (c) 2007 Mats Bengtsson
#  
#   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 3 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, see <http://www.gnu.org/licenses/>.
#       
# $Id: ICQ.tcl,v 1.18 2007-12-20 14:01:25 matben Exp $

namespace eval ::ICQ {
    
    component::define ICQ "Use ICQ nickname in roster"
}

proc ::ICQ::Init { } {
    global  this
    
    ::Debug 2 "::ICQ::Init"
    
    # Add all hooks we need.
    ::hooks::register discoInfoGatewayIcqHook   ::ICQ::DiscoInfoHook
    ::hooks::register logoutHook                ::ICQ::LogoutHook
    
    component::register ICQ

    # Cache for vCard nickname.
    variable vcardnick
}

proc ::ICQ::DiscoInfoHook {type from subiq args} {
    InvestigateRoster
}

proc ::ICQ::InvestigateRoster { } {
    variable vcardnick
    
    set server [::Jabber::GetServerJid]
    set icqHosts [::Jabber::Jlib disco getjidsforcategory "gateway/icq"]
    
    ::Debug 4 "::ICQ::InvestigateRoster icqHosts=$icqHosts"

    # We must loop through all roster items to search for ICQ users.

    foreach jid [::Jabber::RosterCmd getusers] {
	set mjid [jlib::jidmap $jid]
	jlib::splitjidex $mjid node host res
	
	# Not a user.
	if {$node eq ""} {
	    continue
	}
	
	# Allready got it.
	if {[info exists vcardnick($mjid)]} {
	    continue
	}
	
	# Exclude jid's that belong to our login jabber server.
	if {[string equal $server $host]} {
	    continue
	}
	if {[lsearch -exact $icqHosts $host] >= 0} {
	    set name [::Jabber::RosterCmd getname $mjid]
	    if {$name eq ""} {
		
		# Get vCard
		::Jabber::Jlib vcard send_get $jid \
		  [list [namespace current]::VCardGetCB $jid]
	    }
	}	
    }   
}

proc ::ICQ::VCardGetCB {from jlibName type subiq} {
    variable vcardnick
    
    ::Debug 4 "::ICQ::VCardGetCB from=$from, type=$type"

    if {$type eq "error"} {
	::Jabber::AddErrorLog $from "Failed getting vCard: [lindex $subiq 1]"
    } else {
	set name [::Jabber::RosterCmd getname $from]
	
	# Do not override any previous roster name (?)
	if {$name eq ""} {

	    # Find any NICKNAME element.
	    set nickElem [wrapper::getfirstchildwithtag $subiq "NICKNAME"]
	    set nick     [wrapper::getcdata $nickElem]
	    set vcardnick($from) $name
	    jlib::splitjid $from jid2 res
	    ::Jabber::Jlib roster send_set $jid2 -name $nick
	}
    }
}

proc ::ICQ::RosterSetCB {args} {
    
    # puts "++++++++args='$args'"
}

proc ::ICQ::LogoutHook { } {
    variable vcardnick
    
    # Cleanup.
    unset -nocomplain vcardnick
}

#-------------------------------------------------------------------------------