[jdev] how to generate vcard using Net::Jabber
koniczynek
koniczynek at uaznia.net
Fri Jan 20 03:25:56 CST 2006
Randall W, dnia 2006-01-20 00:51 napisal:
> Hi/
> I'm working on a jabber service (written in perl
> using the Net::Jabber modules) and have come to the
> point of needing to respond to vCard requests.
> Google is not helping me out here: The only possibles:
(..)
> Can give me a clue or point me to a working example?
I am doing this the simplest way: put you vCard XML into a file (this is
actually exact copy of vCard sent by Livedelu a Jobble automated
assistant (bot) ;) ):
<vCard xmlns='vcard-temp' prodid="-//HandGen//NONSGML vGen v1.0//EN"
version="2.0" >
<FN>Livedelu</FN>
<N>
<GIVEN/>
<MIDDLE/>
<FAMILY/>
</N>
<NICKNAME></NICKNAME>
<BDAY>2005-08-08</BDAY>
<GENDER>Female</GENDER>
<EMAIL>
<USERID/>
<INTERNET/>
</EMAIL>
<ADR>
<HOME/>
<STREET/>
<EXTADR/>
<EXTADD/>
<LOCALITY>Skawina</LOCALITY>
<REGION>malopolska</REGION>
<PCODE>32-050</PCODE>
<CTRY>Poland</CTRY>
<COUNTRY>Poland</COUNTRY>
</ADR>
<ADR>
<WORK/>
<STREET/>
<EXTADR/>
<EXTADD/>
<LOCALITY/>
<REGION/>
<PCODE/>
<CTRY/>
<COUNTRY/>
</ADR>
<ORG>
<ORGNAME>KrwawA UazniA TEAM</ORGNAME>
<ORGUNIT>Jobble Division</ORGUNIT>
</ORG>
<TITLE>Advisor</TITLE>
<ROLE>Public Relations</ROLE>
<URL>http://jobble.uaznia.net</URL>
<DESC/>
<PHOTO>
<TYPE>image/png</TYPE>
<BINVAL>(base64 encoded png image here)</BINVAL>
</PHOTO>
</vCard>
add proper event handling:
$Connection->SetXPathCallBacks(
(.. many other if needed ..)
'/iq[@type="get"]/*[@xmlns="vcard-temp"]' => \&InvCardSend,
(.. many other if needed ..)
);
and write a sub sendind your raw XML from file:
sub InvCardSend {
my $sid = shift;
my $iq = shift;
my $from = $iq->GetFrom();
my $to = $iq->GetTo();
my $id = $iq->GetID();
my $type = $iq->GetType();
my $query = $iq->GetQuery();
log3("vCard request recived.");
open(FILEREAD, "< ./vcard.xml");
my $IQ = new Net::Jabber::IQ();
$IQ->SetIQ( to => $from,
from => 'livedelu[ at ]jobble[ dot ]uaznia[ dot ]net',
id => $id,
type => 'result');
$IQ->InsertRawXML(<FILEREAD>);
$Connection->Send($IQ);
}
(JID antyspammed ;) )
and it works fine, if you want to try just request a vCard from Livedelu :)
--
koniczynek
More information about the JDev
mailing list