PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/linkedfs/usr/lib/perl5/vendor_perl/5.8.4/Net/Jabber/Protocol.pm

https://bitbucket.org/harakiri/trk
Perl | 5203 lines | 3848 code | 616 blank | 739 comment | 210 complexity | d025d29b6a5082a5a1478879b6db137d MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. ##############################################################################
  2. #
  3. # This library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Library General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2 of the License, or (at your option) any later version.
  7. #
  8. # This library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Library General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Library General Public
  14. # License along with this library; if not, write to the
  15. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. # Boston, MA 02111-1307, USA.
  17. #
  18. # Jabber
  19. # Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
  20. #
  21. ##############################################################################
  22. package Net::Jabber::Protocol;
  23. =head1 NAME
  24. Net::Jabber::Protocol - Jabber Protocol Library
  25. =head1 SYNOPSIS
  26. Net::Jabber::Protocol is a module that provides a developer easy
  27. access to the Jabber Instant Messaging protocol. It provides high
  28. level functions to the Net::Jabber Client, Component, and Server
  29. objects. These functions are automatically indluded in those modules
  30. through AUTOLOAD and delegates.
  31. =head1 DESCRIPTION
  32. Protocol.pm seeks to provide enough high level APIs and automation of
  33. the low level APIs that writing a Jabber Client/Transport in Perl is
  34. trivial. For those that wish to work with the low level you can do
  35. that too, but those functions are covered in the documentation for
  36. each module.
  37. Net::Jabber::Protocol provides functions to login, send and receive
  38. messages, set personal information, create a new user account, manage
  39. the roster, and disconnect. You can use all or none of the functions,
  40. there is no requirement.
  41. For more information on how the details for how Net::Jabber is written
  42. please see the help for Net::Jabber itself.
  43. For more information on writing a Client see Net::Jabber::Client.
  44. For more information on writing a Transport see Net::Jabber::Transport.
  45. =head2 Modes
  46. Several of the functions take a mode argument that let you specify how
  47. the function should behave:
  48. block - send the packet with an ID, and then block until an answer
  49. comes back. You can optionally specify a timeout so that
  50. you do not block forever.
  51. nonblock - send the packet with an ID, but then return that id and
  52. control to the master program. Net::Jabber is still
  53. tracking this packet, so you must use the CheckID function
  54. to tell when it comes in. (This might not be very
  55. useful...)
  56. passthru - send the packet with an ID, but do NOT register it with
  57. Net::Jabber, then return the ID. This is useful when
  58. combined with the XPath function because you can register
  59. a one shot function tied to the id you get back.
  60. =head2 Basic Functions
  61. use Net::Jabber qw( Client );
  62. $Con = new Net::Jabber::Client(); # From
  63. $status = $Con->Connect(hostname=>"jabber.org"); # Net::Jabber::Client
  64. or
  65. use Net::Jabber qw( Component );
  66. $Con = new Net::Jabber::Component(); #
  67. $status = $Con->Connect(hostname=>"jabber.org", # From
  68. secret=>"bob"); # Net::Jabber::Component
  69. $Con->SetCallBacks(send=>\&sendCallBack,
  70. receive=>\&receiveCallBack,
  71. message=>\&messageCallBack,
  72. iq=>\&handleTheIQTag);
  73. $Con->SetMessageCallBacks(normal=>\&messageNormalCB,
  74. chat=>\&messageChatCB);
  75. $Con->SetPresenceCallBacks(available=>\&presenceAvailableCB,
  76. unavailable=>\&presenceUnavailableCB);
  77. $Con->SetIQCallBacks("jabber:iq:roster"=>
  78. {
  79. get=>\&iqRosterGetCB,
  80. set=>\&iqRosterSetCB,
  81. result=>\&iqRosterResultCB,
  82. },
  83. etc...
  84. );
  85. $Con->SetXPathCallBacks("/message[@type='chat']"=>&messageChatCB,
  86. "/message[@type='chat']"=>&otherMessageChatCB,
  87. ...
  88. );
  89. $Con->RemovePathCallBacks("/message[@type='chat']"=>&otherMessageChatCB);
  90. $Con->Info(name=>"Jarl",
  91. version=>"v0.6000");
  92. $error = $Con->GetErrorCode();
  93. $Con->SetErrorCode("Timeout limit reached");
  94. $status = $Con->Process();
  95. $status = $Con->Process(5);
  96. $Con->Send($object);
  97. $Con->Send("<tag>XML</tag>");
  98. $Con->Send($object,1);
  99. $Con->Send("<tag>XML</tag>",1);
  100. $Con->Disconnect();
  101. =head2 ID Functions
  102. $id = $Con->SendWithID($sendObj);
  103. $id = $Con->SendWithID("<tag>XML</tag>");
  104. $receiveObj = $Con->SendAndReceiveWithID($sendObj);
  105. $receiveObj = $Con->SendAndReceiveWithID($sendObj,
  106. 10);
  107. $receiveObj = $Con->SendAndReceiveWithID("<tag>XML</tag>");
  108. $receiveObj = $Con->SendAndReceiveWithID("<tag>XML</tag>",
  109. 5);
  110. $yesno = $Con->ReceivedID($id);
  111. $receiveObj = $Con->GetID($id);
  112. $receiveObj = $Con->WaitForID($id);
  113. $receiveObj = $Con->WaitForID($id,
  114. 20);
  115. =head2 Namespace Functions
  116. $Con->DefineNamespace(xmlns=>"foo:bar",
  117. type=>"Query",
  118. functions=>[{name=>"Foo",
  119. get=>"foo",
  120. set=>["scalar","foo"],
  121. defined=>"foo",
  122. hash=>"child-data"},
  123. {name=>"Bar",
  124. get=>"bar",
  125. set=>["scalar","bar"],
  126. defined=>"bar",
  127. hash=>"child-data"},
  128. {name=>"FooBar",
  129. get=>"__netjabber__:master",
  130. set=>["master"]}]);
  131. =head2 Message Functions
  132. $Con->MessageSend(to=>"bob@jabber.org",
  133. subject=>"Lunch",
  134. body=>"Let's go grab some...\n",
  135. thread=>"ABC123",
  136. priority=>10);
  137. =head2 Presence Functions
  138. $Con->PresenceSend();
  139. $Con->PresenceSend(type=>"unavailable");
  140. $Con->PresenceSend(show=>"away");
  141. $Con->PresenceSend(signature=>...signature...);
  142. =head2 Subscription Functions
  143. $Con->Subscription(type=>"subscribe",
  144. to=>"bob@jabber.org");
  145. $Con->Subscription(type=>"unsubscribe",
  146. to=>"bob@jabber.org");
  147. $Con->Subscription(type=>"subscribed",
  148. to=>"bob@jabber.org");
  149. $Con->Subscription(type=>"unsubscribed",
  150. to=>"bob@jabber.org");
  151. =head2 Presence DB Functions
  152. $Con->PresenceDBParse(Net::Jabber::Presence);
  153. $Con->PresenceDBDelete("bob\@jabber.org");
  154. $Con->PresenceDBDelete(Net::Jabber::JID);
  155. $Con->PresenceDBClear();
  156. $presence = $Con->PresenceDBQuery("bob\@jabber.org");
  157. $presence = $Con->PresenceDBQuery(Net::Jabber::JID);
  158. @resources = $Con->PresenceDBResources("bob\@jabber.org");
  159. @resources = $Con->PresenceDBResources(Net::Jabber::JID);
  160. =head2 IQ Functions
  161. =head2 Agents Functions
  162. %agents = $Con->AgentsGet();
  163. %agents = $Con->AgentsGet(to=>"transport.jabber.org");
  164. =head2 Auth Functions
  165. @result = $Con->AuthSend();
  166. @result = $Con->AuthSend(username=>"bob",
  167. password=>"bobrulez",
  168. resource=>"Bob");
  169. =head2 Browse Functions
  170. %hash = $Con->BrowseRequest(jid=>"jabber.org");
  171. %hash = $Con->BrowseRequest(jid=>"jabber.org",
  172. timeout=>10);
  173. $id = $Con->BrowseRequest(jid=>"jabber.org",
  174. mode=>"nonblock");
  175. $id = $Con->BrowseRequest(jid=>"jabber.org",
  176. mode=>"passthru");
  177. =head2 Browse DB Functions
  178. $Con->BrowseDBDelete("jabber.org");
  179. $Con->BrowseDBDelete(Net::Jabber::JID);
  180. $presence = $Con->BrowseDBQuery(jid=>"bob\@jabber.org");
  181. $presence = $Con->BrowseDBQuery(jid=>Net::Jabber::JID);
  182. $presence = $Con->BrowseDBQuery(jid=>"users.jabber.org",
  183. timeout=>10);
  184. $presence = $Con->BrowseDBQuery(jid=>"conference.jabber.org",
  185. refresh=>1);
  186. =head2 Bystreams Functions
  187. %hash = $Con->ByteStreamsProxyRequest(jid=>"proxy.server");
  188. %hash = $Con->ByteStreamsProxyRequest(jid=>"proxy.server",
  189. timeout=>10);
  190. $id = $Con->ByteStreamsProxyRequest(jid=>"proxy.server",
  191. mode=>"nonblock");
  192. $id = $Con->ByteStreamsProxyRequest(jid=>"proxy.server",
  193. mode=>"passthru");
  194. %hash = $Con->ByteStreamsProxyParse($query);
  195. $status = $Con->ByteStreamsProxyActivate(sid=>"stream_id",
  196. jid=>"proxy.server");
  197. $status = $Con->ByteStreamsProxyActivate(sid=>"stream_id",
  198. jid=>"proxy.server",
  199. timeout=>10);
  200. $id = $Con->ByteStreamsProxyActivate(sid=>"stream_id",
  201. jid=>"proxy.server",
  202. mode=>"nonblock");
  203. $id = $Con->ByteStreamsProxyActivate(sid=>"stream_id",
  204. jid=>"proxy.server",
  205. mode=>"passthru");
  206. $jid = $Con->ByteStreamsOffer(sid=>"stream_id",
  207. streamhosts=>[{jid=>"jid",
  208. host=>"host",
  209. port=>"port",
  210. zeroconf=>"zero",
  211. },
  212. ...
  213. ],
  214. jid=>"bob\@jabber.org");
  215. $jid = $Con->ByteStreamsOffer(sid=>"stream_id",
  216. streamhosts=>[{},{},...],
  217. jid=>"bob\@jabber.org",
  218. timeout=>10);
  219. $id = $Con->ByteStreamsOffer(sid=>"stream_id",
  220. streamhosts=>[{},{},...],
  221. jid=>"bob\@jabber.org",
  222. mode=>"nonblock");
  223. $id = $Con->ByteStreamsOffer(sid=>"stream_id",
  224. streamhosts=>[{},{},...],
  225. jid=>"bob\@jabber.org",
  226. mode=>"passthru");
  227. =head2 Disco Functions
  228. %hash = $Con->DiscoInfoRequest(jid=>"jabber.org");
  229. %hash = $Con->DiscoInfoRequest(jid=>"jabber.org",
  230. node=>"node...");
  231. %hash = $Con->DiscoInfoRequest(jid=>"jabber.org",
  232. node=>"node...",
  233. timeout=>10);
  234. $id = $Con->DiscoInfoRequest(jid=>"jabber.org",
  235. mode=>"nonblock");
  236. $id = $Con->DiscoInfoRequest(jid=>"jabber.org",
  237. node=>"node...",
  238. mode=>"nonblock");
  239. $id = $Con->DiscoInfoRequest(jid=>"jabber.org",
  240. mode=>"passthru");
  241. $id = $Con->DiscoInfoRequest(jid=>"jabber.org",
  242. node=>"node...",
  243. mode=>"passthru");
  244. %hash = $Con->DiscoInfoParse($query);
  245. %hash = $Con->DiscoItemsRequest(jid=>"jabber.org");
  246. %hash = $Con->DiscoItemsRequest(jid=>"jabber.org",
  247. timeout=>10);
  248. $id = $Con->DiscoItemsRequest(jid=>"jabber.org",
  249. mode=>"nonblock");
  250. $id = $Con->DiscoItemsRequest(jid=>"jabber.org",
  251. mode=>"passthru");
  252. %hash = $Con->DiscoItemsParse($query);
  253. =head2 Feature Negotiation Functions
  254. %hash = $Con->FeatureNegRequest(jid=>"jabber.org",
  255. features=>{ feat1=>["opt1","opt2",...],
  256. feat2=>["optA","optB",...]
  257. }
  258. );
  259. %hash = $Con->FeatureNegRequest(jid=>"jabber.org",
  260. features=>{ ... },
  261. timeout=>10);
  262. $id = $Con->FeatureNegRequest(jid=>"jabber.org",
  263. features=>{ ... },
  264. mode=>"nonblock");
  265. $id = $Con->FeatureNegRequest(jid=>"jabber.org",
  266. features=>{ ... },
  267. mode=>"passthru");
  268. my $query = $self->FeatureNegQuery(\{ ... });
  269. $iq->AddQuery($query);
  270. %hash = $Con->FeatureNegParse($query);
  271. =head2 File Transfer Functions
  272. $method = $Con->FileTransferOffer(jid=>"bob\@jabber.org",
  273. sid=>"stream_id",
  274. filename=>"/path/to/file",
  275. methods=>["http://jabber.org/protocol/si/profile/bytestreams",
  276. "jabber:iq:oob",
  277. ...
  278. ]
  279. );
  280. $method = $Con->FileTransferOffer(jid=>"bob\@jabber.org",
  281. sid=>"stream_id",
  282. filename=>"/path/to/file",
  283. methods=>\@methods,
  284. timeout=>"10");
  285. $id = $Con->FileTransferOffer(jid=>"bob\@jabber.org",
  286. sid=>"stream_id",
  287. filename=>"/path/to/file",
  288. methods=>\@methods,
  289. mode=>"nonblock");
  290. $id = $Con->FileTransferOffer(jid=>"bob\@jabber.org",
  291. sid=>"stream_id",
  292. filename=>"/path/to/file",
  293. methods=>\@methods,
  294. mode=>"passthru");
  295. =head2 Last Functions
  296. $Con->LastQuery();
  297. $Con->LastQuery(to=>"bob@jabber.org");
  298. %result = $Con->LastQuery(mode=>"block");
  299. %result = $Con->LastQuery(to=>"bob@jabber.org",
  300. mode=>"block");
  301. %result = $Con->LastQuery(to=>"bob@jabber.org",
  302. mode=>"block",
  303. timeout=>10);
  304. %result = $Con->LastQuery(mode=>"block",
  305. timeout=>10);
  306. $Con->LastSend(to=>"bob@jabber.org");
  307. $seconds = $Con->LastActivity();
  308. =head2 Register Functions
  309. %hash = $Con->RegisterRequest();
  310. %hash = $Con->RegisterRequest(to=>"transport.jabber.org");
  311. %hash = $Con->RegisterRequest(to=>"transport.jabber.org",
  312. timeout=>10);
  313. @result = $Con->RegisterSend(to=>"somewhere",
  314. username=>"newuser",
  315. resource=>"New User",
  316. password=>"imanewbie",
  317. email=>"newguy@new.com",
  318. key=>"some key");
  319. @result = $Con->RegisterSendData("users.jabber.org",
  320. first=>"Bob",
  321. last=>"Smith",
  322. nick=>"bob",
  323. email=>"foo@bar.net");
  324. =head2 Roster Functions
  325. %roster = $Con->RosterParse($iq);
  326. %roster = $Con->RosterGet();
  327. $Con->RosterRequest();
  328. $Con->RosterAdd(jid=>"bob\@jabber.org",
  329. name=>"Bob");
  330. $Con->RosterRemove(jid=>"bob@jabber.org");
  331. =head2 RPC Functions
  332. $query = $Con->RPCEncode(type=>"methodCall",
  333. methodName=>"methodName",
  334. params=>[param,param,...]);
  335. $query = $Con->RPCEncode(type=>"methodResponse",
  336. params=>[param,param,...]);
  337. $query = $Con->RPCEncode(type=>"methodResponse",
  338. faultCode=>4,
  339. faultString=>"Too many params");
  340. @response = $Con->RPCParse($iq);
  341. @response = $Con->RPCCall(to=>"dataHouse.jabber.org",
  342. methodname=>"numUsers",
  343. params=>[ param,param,... ]
  344. );
  345. $Con->RPCResponse(to=>"you\@jabber.org",
  346. params=>[ param,param,... ]);
  347. $Con->RPCResponse(to=>"you\@jabber.org",
  348. faultCode=>"4",
  349. faultString=>"Too many parameters"
  350. );
  351. $Con->RPCSetCallBacks(myMethodA=>\&methoda,
  352. myMethodB=>\&do_somthing,
  353. etc...
  354. );
  355. =head2 Search Functions
  356. %fields = $Con->SearchRequest();
  357. %fields = $Con->SearchRequest(to=>"users.jabber.org");
  358. %fields = $Con->SearchRequest(to=>"users.jabber.org",
  359. timeout=>10);
  360. $Con->SearchSend(to=>"somewhere",
  361. name=>"",
  362. first=>"Bob",
  363. last=>"",
  364. nick=>"bob",
  365. email=>"",
  366. key=>"some key");
  367. $Con->SearchSendData("users.jabber.org",
  368. first=>"Bob",
  369. last=>"",
  370. nick=>"bob",
  371. email=>"");
  372. =head2 Time Functions
  373. $Con->TimeQuery();
  374. $Con->TimeQuery(to=>"bob@jabber.org");
  375. %result = $Con->TimeQuery(mode=>"block");
  376. %result = $Con->TimeQuery(to=>"bob@jabber.org",
  377. mode=>"block");
  378. $Con->TimeSend(to=>"bob@jabber.org");
  379. =head2 Version Functions
  380. $Con->VersionQuery();
  381. $Con->VersionQuery(to=>"bob@jabber.org");
  382. %result = $Con->VersionQuery(mode=>"block");
  383. %result = $Con->VersionQuery(to=>"bob@jabber.org",
  384. mode=>"block");
  385. $Con->VersionSend(to=>"bob@jabber.org",
  386. name=>"Net::Jabber",
  387. ver=>"1.0a",
  388. os=>"Perl");
  389. =head2 Multi-User Chat Functions
  390. $Con->MUCJoin(room=>"jabber",
  391. server=>"conference.jabber.org",
  392. nick=>"nick");
  393. $Con->MUCJoin(room=>"jabber",
  394. server=>"conference.jabber.org",
  395. nick=>"nick",
  396. password=>"secret");
  397. =head1 METHODS
  398. =head2 Basic Functions
  399. GetErrorCode() - returns a string that will hopefully contain some
  400. useful information about why a function returned
  401. an undef to you.
  402. SetErrorCode(string) - set a useful error message before you return
  403. an undef to the caller.
  404. SetCallBacks(message=>function, - sets the callback functions for
  405. presence=>function, the top level tags listed. The
  406. iq=>function) available tags to look for are
  407. SetCallBacks(xdb=>function, <message/>, <presence/>, and
  408. db:verify=>function, <iq/>. If a packet is received
  409. db:result=>function) with an ID which is found in the
  410. SetCallBacks(send=>function, registerd ID list (see RegisterID
  411. receive=>function, below) then it is not sent to
  412. update=>function) these functions, instead it
  413. is inserted into a LIST and can
  414. be retrieved by some functions
  415. we will mention later.
  416. send and receive are used to
  417. log what XML is sent and received.
  418. update is used as way to update
  419. your program while waiting for
  420. a packet with an ID to be
  421. returned (useful for GUI apps).
  422. A major change that came with
  423. the last release is that the
  424. session id is passed to the
  425. callback as the first argument.
  426. This was done to facilitate
  427. the Server module.
  428. The next argument depends on
  429. which callback you are talking
  430. about. message, presence, iq,
  431. xdb, db:verify, and db:result
  432. all get passed in Net::Jabber
  433. objects that match those types.
  434. send and receive get passed in
  435. strings. update gets passed
  436. nothing, not even the session id.
  437. If you set the function to undef,
  438. then the callback is removed from
  439. the list.
  440. SetPresenceCallBacks(type=>function - sets the callback functions for
  441. etc...) the specified presence type. The
  442. function takes types as the main
  443. key, and lets you specify a
  444. function for each type of packet
  445. you can get.
  446. "available"
  447. "unavailable"
  448. "subscribe"
  449. "unsubscribe"
  450. "subscribed"
  451. "unsubscribed"
  452. "probe"
  453. "error"
  454. When it gets a <presence/> packet
  455. it checks the type='' for a defined
  456. callback. If there is one then it
  457. calls the function with two
  458. arguments:
  459. the session ID, and the
  460. Net::Jabber::Presence object.
  461. If you set the function to undef,
  462. then the callback is removed from
  463. the list.
  464. NOTE: If you use this, which is a cleaner method,
  465. then you must *NOT* specify a callback for
  466. presence in the SetCallBacks function.
  467. Net::Jabber defines a few default
  468. callbacks for various types:
  469. "subscribe" -
  470. replies with subscribed
  471. "unsubscribe" -
  472. replies with unsubscribed
  473. "subscribed" -
  474. replies with subscribed
  475. "unsubscribed" -
  476. replies with unsubscribed
  477. SetMessageCallBacks(type=>function, - sets the callback functions for
  478. etc...) the specified message type. The
  479. function takes types as the main
  480. key, and lets you specify a
  481. function for each type of packet
  482. you can get.
  483. "normal"
  484. "chat"
  485. "groupchat"
  486. "headline"
  487. "error"
  488. When it gets a <message/> packet
  489. it checks the type='' for a
  490. defined callback. If there is one
  491. then it calls the function with
  492. two arguments:
  493. the session ID, and the
  494. Net::Jabber::Message object.
  495. If you set the function to undef,
  496. then the callback is removed from
  497. the list.
  498. NOTE: If you use this, which is a cleaner method,
  499. then you must *NOT* specify a callback for
  500. message in the SetCallBacks function.
  501. SetIQCallBacks(namespace=>{ - sets the callback functions for
  502. get=>function, the specified namespace. The
  503. set=>function, function takes namespaces as the
  504. result=>function main key, and lets you specify a
  505. }, function for each type of packet
  506. etc...) you can get.
  507. "get"
  508. "set"
  509. "result"
  510. When it gets an <iq/> packet it
  511. checks the type='' and the
  512. xmlns='' for a defined callback.
  513. If there is one then it calls
  514. the function with two arguments:
  515. the session ID, and the
  516. Net::Jabber::xxxx object.
  517. If you set the function to undef,
  518. then the callback is removed from
  519. the list.
  520. NOTE: If you use this, which is a cleaner method,
  521. then you must *NOT* specify a callback for
  522. iq in the SetCallBacks function.
  523. Net::Jabber defines a few default
  524. callbacks for various types and
  525. namespaces:
  526. jabber:iq:last(get) -
  527. replies with the current last
  528. activity
  529. jabber:iq:last(result) -
  530. reformats the <iq/> into a
  531. <message/> and submits it as
  532. if the packet was received.
  533. jabber:iq:rpc(set) -
  534. calls the rpc method and
  535. returns the response
  536. jabber:iq:time(get) -
  537. replys with the current time
  538. jabber:iq:time(result) -
  539. reformats the <iq/> into a
  540. <message/> and submits it as
  541. if the packet was received.
  542. jabber:iq:version(get) -
  543. replys with the info for the
  544. Client/Component (as defined
  545. in the Info function)
  546. jabber:iq:version(result) -
  547. reformats the <iq/> into a
  548. <message/> and submits it as
  549. if the packet was received.
  550. SetXPathCallBacks(xpath=>function, - registers a callback function for
  551. etc...) each xpath specified. If
  552. Net::Jabber matches the xpath,
  553. then it calls the function with
  554. two arguments:
  555. the session ID, and the
  556. Net::Jabber::Message object.
  557. Xpaths are rooted at each packet:
  558. /message[@type="chat"]
  559. /iq/*[xmlns="jabber:iq:roster"][1]
  560. ...
  561. RemoveXPathCallBacks(xpath=>function, - unregisters a callback function
  562. etc...) for each xpath specified.
  563. Info(name=>string, - Set some information so that Net::Jabber
  564. version=>string) can auto-reply to some packets for you to
  565. reduce the work you have to do.
  566. NOTE: This requires that you use the
  567. SetIQCallBacks methodology and not the
  568. SetCallBacks for <iq/> packets.
  569. Process(integer) - takes the timeout period as an argument. If no
  570. timeout is listed then the function blocks until
  571. a packet is received. Otherwise it waits that
  572. number of seconds and then exits so your program
  573. can continue doing useful things. NOTE: This is
  574. important for GUIs. You need to leave time to
  575. process GUI commands even if you are waiting for
  576. packets. The following are the possible return
  577. values, and what they mean:
  578. 1 - Status ok, data received.
  579. 0 - Status ok, no data received.
  580. undef - Status not ok, stop processing.
  581. IMPORTANT: You need to check the output of every
  582. Process. If you get an undef then the connection
  583. died and you should behave accordingly.
  584. Send(object, - takes either a Net::Jabber::xxxxx object or
  585. ignoreActivity) an XML string as an argument and sends it to
  586. Send(string, the server. If you set ignoreActivty to 1,
  587. ignoreActivity) then the XML::Stream module will not record
  588. this packet as couting towards user activity.
  589. =head2 ID Functions
  590. SendWithID(object) - takes either a Net::Jabber::xxxxx object or an
  591. SendWithID(string) XML string as an argument, adds the next
  592. available ID number and sends that packet to
  593. the server. Returns the ID number assigned.
  594. SendAndReceiveWithID(object, - uses SendWithID and WaitForID to
  595. timeout) provide a complete way to send and
  596. SendAndReceiveWithID(string, receive packets with IDs. Can take
  597. timeout) either a Net::Jabber::xxxxx object
  598. or an XML string. Returns the
  599. proper Net::Jabber::xxxxx object
  600. based on the type of packet
  601. received. The timeout is passed
  602. on to WaitForID, see that function
  603. for how the timeout works.
  604. ReceivedID(integer) - returns 1 if a packet has been received with
  605. specified ID, 0 otherwise.
  606. GetID(integer) - returns the proper Net::Jabber::xxxxx object based
  607. on the type of packet received with the specified
  608. ID. If the ID has been received the GetID returns
  609. 0.
  610. WaitForID(integer, - blocks until a packet with the ID is received.
  611. timeout) Returns the proper Net::Jabber::xxxxx object
  612. based on the type of packet received. If the
  613. timeout limit is reached then if the packet
  614. does come in, it will be discarded.
  615. NOTE: Only <iq/> officially support ids, so sending a <message/>, or
  616. <presence/> with an id is a risk. The server will ignore the
  617. id tag and pass it through, so both clients must support the
  618. id tag for these functions to be useful.
  619. =head2 Namespace Functions
  620. DefineNamespace(xmlns=>string, - This function is very complex.
  621. type=>string, It is a little too complex to
  622. functions=>array) discuss within the confines of
  623. this small paragraph. Please
  624. refer to the man page for
  625. Net::Jabber::Namespaces for the
  626. full documentation on this
  627. subject.
  628. =head2 Message Functions
  629. MessageSend(hash) - takes the hash and passes it to SetMessage in
  630. Net::Jabber::Message (refer there for valid
  631. settings). Then it sends the message to the
  632. server.
  633. =head2 Presence Functions
  634. PresenceSend() - no arguments will send an empty
  635. PresenceSend(hash, Presence to the server to tell it
  636. signature=>string) that you are available. If you
  637. provide a hash, then it will pass
  638. that hash to the SetPresence()
  639. function as defined in the
  640. Net::Jabber::Presence module.
  641. Optionally, you can specify a
  642. signature and a jabber:x:signed
  643. will be placed in the <presence/>.
  644. =head2 Subscription Functions
  645. Subscription(hash) - taks the hash and passes it to SetPresence in
  646. Net::Jabber::Presence (refer there for valid
  647. settings). Then it sends the subscription to
  648. server.
  649. The valid types of subscription are:
  650. subscribe - subscribe to JID's presence
  651. unsubscribe - unsubscribe from JID's presence
  652. subscribed - response to a subscribe
  653. unsubscribed - response to an unsubscribe
  654. =head2 Presence DB Functions
  655. PresenceDBParse(Net::Jabber::Presence) - for every presence that you
  656. receive pass the Presence
  657. object to the DB so that
  658. it can track the resources
  659. and priorities for you.
  660. Returns either the presence
  661. passed in, if it not able
  662. to parsed for the DB, or the
  663. current presence as found by
  664. the PresenceDBQuery
  665. function.
  666. PresenceDBDelete(string|Net::Jabber::JID) - delete thes JID entry
  667. from the DB.
  668. PresenceDBClear() - delete all entries in the database.
  669. PresenceDBQuery(string|Net::Jabber::JID) - returns the NJ::Presence
  670. that was last received for
  671. the highest priority of
  672. this JID. You can pass
  673. it a string or a NJ::JID
  674. object.
  675. PresenceDBResources(string|Net::Jabber::JID) - returns an array of
  676. resources in order
  677. from highest priority
  678. to lowest.
  679. =head2 IQ Functions
  680. =head2 Agents Functions
  681. AgentsGet(to=>string, - takes all of the information and
  682. AgentsGet() builds a Net::Jabber::IQ::Agents packet.
  683. It then sends that packet either to the
  684. server, or to the specified transport,
  685. with an ID and waits for that ID to return.
  686. Then it looks in the resulting packet and
  687. builds a hash that contains the values
  688. of the agent list. The hash is layed out
  689. like this: (NOTE: the jid is the key to
  690. distinguish the various agents)
  691. $hash{<JID>}->{order} = 4
  692. ->{name} = "ICQ Transport"
  693. ->{transport} = "ICQ #"
  694. ->{description} = "ICQ..blah.."
  695. ->{service} = "icq"
  696. ->{register} = 1
  697. ->{search} = 1
  698. etc...
  699. The order field determines the order that
  700. it came from the server in... in case you
  701. care. For more info on the valid fields
  702. see the Net::Jabber::Query jabber:iq:agent
  703. namespace.
  704. =head2 Auth Functions
  705. AuthSend(username=>string, - takes all of the information and
  706. password=>string, builds a Net::Jabber::IQ::Auth packet.
  707. resource=>string) It then sends that packet to the
  708. server with an ID and waits for that
  709. ID to return. Then it looks in
  710. resulting packet and determines if
  711. authentication was successful for not.
  712. The array returned from AuthSend looks
  713. like this:
  714. [ type , message ]
  715. If type is "ok" then authentication
  716. was successful, otherwise message
  717. contains a little more detail about the
  718. error.
  719. =head2 Browse Functions
  720. BrowseRequest(jid=>string, - sends a jabber:iq:browse request to
  721. mode=>string, the jid passed as an argument.
  722. timeout=>int) Returns a hash with the resulting
  723. tree if mode is set to "block":
  724. $browse{'category'} = "conference"
  725. $browse{'children'}->[0]
  726. $browse{'children'}->[1]
  727. $browse{'children'}->[11]
  728. $browse{'jid'} = "conference.jabber.org"
  729. $browse{'name'} = "Jabber.org Conferencing Center"
  730. $browse{'ns'}->[0]
  731. $browse{'ns'}->[1]
  732. $browse{'type'} = "public"
  733. The ns array is an array of the
  734. namespaces that this jid supports.
  735. The children array points to hashs
  736. of this form, and represent the fact
  737. that they can be browsed to.
  738. See MODES above for using the mode
  739. and timeout.
  740. =head2 Browse DB Functions
  741. BrowseDBDelete(string|Net::Jabber::JID) - delete thes JID browse
  742. data from the DB.
  743. BrowseDBQuery(jid=>string | NJ::JID, - returns the browse data
  744. timeout=>integer, for the requested JID. If
  745. refresh=>0|1) the DB does not contain
  746. the data for the JID, then
  747. it attempts to fetch the
  748. data via BrowseRequest().
  749. The timeout is passed to
  750. the BrowseRequest() call,
  751. and refresh tells the DB
  752. to request the data, even
  753. if it already has some.
  754. =head2 Bytestreams Functions
  755. ByteStreamsProxyRequest(jid=>string, - sends a bytestreams request
  756. mode=>string, to the jid passed as an
  757. timeout=>int) argument. Returns an array
  758. ref with the resulting tree
  759. if mode is set to "block".
  760. See ByteStreamsProxyParse
  761. for the format of the
  762. resulting tree.
  763. See MODES above for using
  764. the mode and timeout.
  765. ByteStreamsProxyParse(Net::Jabber::Query) - parses the query and
  766. returns an array ref
  767. to the resulting tree:
  768. $host[0]->{jid} = "bytestreams1.proxy.server";
  769. $host[0]->{host} = "proxy1.server";
  770. $host[0]->{port} = "5006";
  771. $host[1]->{jid} = "bytestreams2.proxy.server";
  772. $host[1]->{host} = "proxy2.server";
  773. $host[1]->{port} = "5007";
  774. ...
  775. ByteStreamsProxyActivate(jid=>string, - sends a bytestreams activate
  776. sid=>string, to the jid passed as an
  777. mode=>string, argument. Returns 1 if the
  778. timeout=>int) proxy activated (undef if
  779. it did not) if mode is set
  780. to "block".
  781. sid is the stream id that
  782. is being used to talk about
  783. this stream.
  784. See MODES above for using
  785. the mode and timeout.
  786. ByteStreamsOffer(jid=>string, - sends a bytestreams offer
  787. sid=>string, to the jid passed as an
  788. streamhosts=>arrayref argument. Returns the jid
  789. mode=>string, of the streamhost that the
  790. timeout=>int) user selected if mode is set
  791. to "block".
  792. streamhosts is the same
  793. format as the array ref
  794. returned from
  795. ByteStreamsProxyParse.
  796. See MODES above for using
  797. the mode and timeout.
  798. =head2 Disco Functions
  799. DiscoInfoRequest(jid=>string, - sends a disco#info request to
  800. node=>string, the jid passed as an argument,
  801. mode=>string, and the node if specified.
  802. timeout=>int) Returns a hash with the resulting
  803. tree if mode is set to "block".
  804. See DiscoInfoParse for the format
  805. of the resulting tree.
  806. See MODES above for using the mode
  807. and timeout.
  808. DiscoInfoParse(Net::Jabber::Query) - parses the query and
  809. returns a hash ref
  810. to the resulting tree:
  811. $info{identity}->[0]->{category} = "groupchat";
  812. $info{identity}->[0]->{name} = "Public Chatrooms";
  813. $info{identity}->[0]->{type} = "public";
  814. $info{identity}->[1]->{category} = "groupchat";
  815. $info{identity}->[1]->{name} = "Private Chatrooms";
  816. $info{identity}->[1]->{type} = "private";
  817. $info{feature}->{http://jabber.org/protocol/disco#info} = 1;
  818. $info{feature}->{http://jabber.org/protocol/muc#admin} = 1;
  819. DiscoItemsRequest(jid=>string, - sends a disco#items request to
  820. mode=>string, the jid passed as an argument.
  821. timeout=>int) Returns a hash with the resulting
  822. tree if mode is set to "block".
  823. See DiscoItemsParse for the format
  824. of the resulting tree.
  825. See MODES above for using the mode
  826. and timeout.
  827. DiscoItemsParse(Net::Jabber::Query) - parses the query and
  828. returns a hash ref
  829. to the resulting tree:
  830. $items{jid}->{node} = name;
  831. $items{"proxy.server"}->{""} = "Bytestream Proxy Server";
  832. $items{"conf.server"}->{"public"} = "Public Chatrooms";
  833. $items{"conf.server"}->{"private"} = "Private Chatrooms";
  834. =head2 Feature Negotiation Functions
  835. FeatureNegRequest(jid=>string, - sends a feature negotiation to
  836. features=>hash ref, the jid passed as an argument,
  837. mode=>string, using the features specified.
  838. timeout=>int) Returns a hash with the resulting
  839. tree if mode is set to "block".
  840. See DiscoInfoQuery for the format
  841. of the features hash ref.
  842. See DiscoInfoParse for the format
  843. of the resulting tree.
  844. See MODES above for using the mode
  845. and timeout.
  846. FeatureNegParse(Net::Jabber::Query) - parses the query and
  847. returns a hash ref
  848. to the resulting tree:
  849. $features->{feat1} = ["opt1","opt2",...];
  850. $features->{feat2} = ["optA","optB",...];
  851. ....
  852. If this is a result:
  853. $features->{feat1} = "opt2";
  854. $features->{feat2} = "optA";
  855. ....
  856. FeatureNeqQuery(hash ref) - takes a hash ref and turns it into a
  857. feature negotiation query that you can
  858. AddQuery into your packaet. The format
  859. of the hash ref is as follows:
  860. $features->{feat1} = ["opt1","opt2",...];
  861. $features->{feat2} = ["optA","optB",...];
  862. ....
  863. =head2 File Transfer Functions
  864. FileTransferOffer(jid=>string, - sends a file transfer stream
  865. sid=>string, initiation to the jid passed

Large files files are truncated, but you can click here to view the full file