.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "AnyEvent::XMPP::Ext::VCard 3" .TH AnyEvent::XMPP::Ext::VCard 3 2024-07-13 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME AnyEvent::XMPP::Ext::VCard \- VCards (XEP\-0054 & XEP\-0084) .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use AnyEvent::XMPP::Ext::VCard; \& \& my $vcard = AnyEvent::XMPP::Ext::VCard\->new; \& $con\->reg_cb ( \& stream_ready => sub { $vcard\->hook_on ($con) } \& ); \& \& $vcard\->retrieve ($con, \*(Aqelmex@jabber.org\*(Aq, sub { \& my ($jid, $vcard, $error) = @_; \& \& if ($error) { \& warn "couldn\*(Aqt get vcard for elmex@jabber.org: " . $error\->string . "\en"; \& } else { \& print "vCard nick for elmex@jabber.org: ".$vcard\->{NICKNAME}."\en"; \& print "Avatar hash for elmex@jabber.org: ".$vcard\->{_avatar_hash}."\en"; \& } \& }); \& \& $vcard\->store ($con, undef, { NICKNAME => \*(Aqnet\-xmpp2\*(Aq }, sub { \& my ($error) = @_; \& if ($error) { \& warn "upload failed: " . $error\->string . "\en"; \& } else { \& print "upload successful\en"; \& } \& }); \& \& $disco\->enable_feature ($vcard\->disco_feature); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This extension handles setting and retrieval of the VCard and the VCard based avatars. .PP For example see the test suite of AnyEvent::XMPP. .SH METHODS .IX Header "METHODS" .IP "\fBnew (%args)\fR" 4 .IX Item "new (%args)" Creates a new vcard extension. It can take a \f(CW\*(C`cache\*(C'\fR argument, which should be a tied hash which should be able to save the retrieved vcards. If no \f(CW\*(C`cache\*(C'\fR is set a internal hash will be used and the vcards will be retrieved everytime the program is restarted. The keys will be the stringprepped bare JIDs of the people we got a vcard from and the value will be a non-cyclic hash/array datastructure representing the vcard. .Sp About this datastructure see below at \fBVCARD STRUCTURE\fR. .Sp If you want to support avatars correctly make sure you hook up the connection via the \f(CW\*(C`hook_on\*(C'\fR method. .ie n .IP "\fBhook_on ($con, \fR\fB$dont_retrieve_vcard\fR\fB)\fR" 4 .el .IP "\fBhook_on ($con, \fR\f(CB$dont_retrieve_vcard\fR\fB)\fR" 4 .IX Item "hook_on ($con, $dont_retrieve_vcard)" \&\f(CW$con\fR must be an object of the class AnyEvent::XMPP::Connection (or derived). Once the vCard extension has been hooked up on a connection it will add the avatar information to all outgoing presence stanzas. .Sp IMPORTANT: You need to hook on the connection \fBBEFORE\fR it was connected. The initial presence stanza needs to contain the information that we support avatars. The vcard will automatically retrieved if the session wasn't already started. Otherwise you will have to retrieve the vcard manually if you hook it up after the \f(CW\*(C`session_ready\*(C'\fR event was received. You can prevent the automatic retrieval by giving a true value in \f(CW$dont_retrieve_vcard\fR. However, just make sure to hook up on any connection before it is connected if you want to offer avatar support on it. .Sp Best is probably to do it like this: .Sp .Vb 4 \& my $vcard = AnyEvent::XMPP::Ext::VCard\->new; \& $con\->reg_cb ( \& stream_ready => sub { $vcard\->hook_on ($con) } \& ); .Ve .IP "\fBmy_vcard ($con)\fR" 4 .IX Item "my_vcard ($con)" This method returns the vcard for the account connected by \f(CW$con\fR. This only works if vcard was (successfully) retrieved. If the connection was hoooked up the vcard was automatically retrieved. .Sp Alternatively \f(CW$con\fR can also be a string reprensenting the JID of an account. .IP "\fBcache ([$newcache])\fR" 4 .IX Item "cache ([$newcache])" See also \f(CW\*(C`new\*(C'\fR about the meaning of cache hashes. If no argument is given the current cache is returned. .ie n .IP "\fBstore ($con, \fR\fB$vcard\fR\fB, \fR\fB$cb\fR\fB)\fR" 4 .el .IP "\fBstore ($con, \fR\f(CB$vcard\fR\fB, \fR\f(CB$cb\fR\fB)\fR" 4 .IX Item "store ($con, $vcard, $cb)" This method will store your \f(CW$vcard\fR on the connected server. \&\f(CW$cb\fR is called when either an error occured or the storage was successful. If an error occured the first argument is not undefined and contains an AnyEvent::XMPP::Error::IQ object. .Sp \&\f(CW$con\fR should be a AnyEvent::XMPP::Connection or an object from some derived class. .Sp \&\f(CW$vcard\fR has a datastructure as described below in \fBVCARD STRUCTURE\fR. .ie n .IP "\fBretrieve ($con, \fR\fB$jid\fR\fB, \fR\fB$cb\fR\fB)\fR" 4 .el .IP "\fBretrieve ($con, \fR\f(CB$jid\fR\fB, \fR\f(CB$cb\fR\fB)\fR" 4 .IX Item "retrieve ($con, $jid, $cb)" This method will retrieve the vCard for \f(CW$jid\fR via the connection \f(CW$con\fR. If \f(CW$jid\fR is undefined the vCard of yourself is retrieved. The callback \f(CW$cb\fR is called when an error occured or the vcard was retrieved. The first argument of the callback will be the JID to which the vCard belongs, the second argument is the vCard itself (as described in \fBVCARD STRUCTURE\fR below) and the thrid argument is the error, if an error occured (undef otherwise). .SH "VCARD STRUCTURE" .IX Header "VCARD STRUCTURE" As there are currently no nice DOM implementations in Perl and I strongly dislike the DOM API in general this module has a simple Perl datastructure without cycles to represent the vCard. .PP First an example: A fetched vCard hash may look like this: .PP .Vb 10 \& { \& \*(AqURL\*(Aq => [\*(Aqhttp://www.ta\-sa.org/\*(Aq], \& \*(AqORG\*(Aq => [{ \& \*(AqORGNAME\*(Aq => \*(Aqnethype GmbH\*(Aq \& }], \& \*(AqN\*(Aq => [{ \& \*(AqFAMILY\*(Aq => \*(AqRedeker\*(Aq \& }], \& \*(AqEMAIL\*(Aq => [\*(Aqelmex@ta\-sa.org\*(Aq], \& \*(AqBDAY\*(Aq => [\*(Aq1984\-06\-01\*(Aq], \& \*(AqFN\*(Aq => [\*(AqRobin\*(Aq], \& \*(AqADR\*(Aq => [ \& { \& HOME => undef, \& \*(AqCOUNTRY\*(Aq => \*(AqGermany\*(Aq \& }, \& { \& WORK => undef, \& COUNTRY => \*(AqGermany\*(Aq, \& LOCALITY => \*(AqKarlsruhe\*(Aq \& } \& ], \& \*(AqNICKNAME\*(Aq => [\*(Aqelmex\*(Aq], \& \*(AqROLE\*(Aq => [\*(AqProgrammer\*(Aq] \& } .Ve .PP The keys represent the toplevel element of a vCard, the values are always array references containig one or more values for the key. If the value is a hash reference again it's value will not be an array reference but either undef or plain values. .PP The values of the toplevel keys are all array references because fields like \f(CW\*(C`ADR\*(C'\fR may occur multiple times. .PP Consult XEP\-0054 for an explanation what these fields mean or contain. .PP There are special fields in this structure for handling avatars: \&\f(CW\*(C`_avatar\*(C'\fR contains the binary data for the avatar image. \&\f(CW\*(C`_avatar_hash\*(C'\fR contains the sha1 hexencoded hash of the binary image data. \&\f(CW\*(C`_avatar_type\*(C'\fR contains the mime type of the avatar. .PP If you want to store the vcard you only have to set \f(CW\*(C`_avatar\*(C'\fR and \f(CW\*(C`_avatar_type\*(C'\fR if you want to store an avatar. .SH EVENTS .IX Header "EVENTS" The vcard extension will emit these events: .SH TODO .IX Header "TODO" Implement caching, the cache stuff is just a storage hash at the moment. Or maybe drop it completly and let the application handle caching. .ie n .IP "retrieve_vcard_error => $iq_error" 4 .el .IP "retrieve_vcard_error => \f(CW$iq_error\fR" 4 .IX Item "retrieve_vcard_error => $iq_error" When a vCard retrieval was not successful, this event is emitted. This is neccessary as some retrievals may happen automatically. .ie n .IP "vcard => $jid, $vcard" 4 .el .IP "vcard => \f(CW$jid\fR, \f(CW$vcard\fR" 4 .IX Item "vcard => $jid, $vcard" Whenever a vCard is retrieved, either automatically or manually, this event is emitted with the retrieved vCard. .SH AUTHOR .IX Header "AUTHOR" Robin Redeker, \f(CW\*(C`\*(C'\fR, JID: \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2007, 2008 Robin Redeker, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.