This file is indexed.

/usr/share/perl5/Net/XMPP/Namespaces.pm is in libnet-xmpp-perl 1.02-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
##############################################################################
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Library General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library 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
#  Library General Public License for more details.
#
#  You should have received a copy of the GNU Library General Public
#  License along with this library; if not, write to the
#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA  02111-1307, USA.
#
#  Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/
#
##############################################################################

package Net::XMPP::Namespaces;

=head1 NAME

Net::XMPP::Namespaces - In depth discussion on how namespaces are handled

=head1 SYNOPSIS

  Net::XMPP::Namespaces provides an depth look at how Net::XMPP handles
  namespacs, and how to add your own custom ones.  It also serves as the
  storage bin for all of the Namespace information Net::XMPP requires.

=head1 DESCRIPTION

  XMPP as a protocol is very well defined.  There are three main top
  level packets (message, iq, and presence).  There is also a way to
  extend the protocol in a very clear and strucutred way, via namespaces.

  Two major ways that namespaces are used in Jabber is for making the
  <iq/> a generic wrapper, and as a way for adding data to any packet via
  a child tag <x/>.  We will use <x/> to represent the packet, but in
  reality it could be any child tag: <foo/>, <data/>, <error/>, etc.

  The Info/Query <iq/> packet uses namespaces to determine the type of
  information to access.  Usually there is a <query/> tag in the <iq/>
  that represents the namespace, but in fact it can be any tag.  The
  definition of the Query portion, is the first tag that has a namespace.

    <iq type="get"><query xmlns="..."/></iq>

      or

    <iq type="get"><foo xmlns="..."/></iq>

  After that Query stanza can be any number of other stanzas (<x/> tags)
  you want to include.  The Query packet is represented and available by
  calling GetQuery() or GetChild(), and the other namespaces are
  available by calling GetChild().

  The X tag is just a way to piggy back data on other packets.  Like
  embedding the timestamp for a message using jabber:x:delay, or signing
  you presence for encryption using jabber:x:signed.

  To this end, Net::XMPP has sought to find a way to easily, and clearly
  define the functions needed to access the XML for a namespace.  We will
  go over the full docs, and then show two examples of real namespaces so
  that you can see what we are talking about.

=head2 Overview

  To avoid a lot of nasty modules populating memory that are not used,
  and to avoid having to change 15 modules when a minor change is
  introduced, the Net::XMPP modules have taken AUTOLOADing to the
  extreme.  Namespaces.pm is nothing but a set of function calls that
  generates a big hash of hashes.  The hash is accessed by the Stanza.pm
  AUTOLOAD function to do something.  (This will make sense, I promise.)

  Before going on, I highly suggest you read a Perl book on AUTOLOAD and
  how it works.  From this point on I will assume that you understand it.

  When you create a Net::XMPP::IQ object and add a Query to it (NewChild)
  several things are happening in the background.  The argument to
  NewChild is the namespace you want to add. (custom-namespace)

  Now that you have a Query object to work with you will call the GetXXX
  functions, and SetXXX functions to set the data.  There are no defined
  GetXXX and SetXXXX functions.  You cannot look in the Namespaces.pm
  file and find them.  Instead you will find something like this:

  &add_ns(ns    => "mynamespace",
          tag   => "mytag",
          xpath => {
                    JID       => { type=>'jid', path => '@jid' },
                    Username  => { path => 'username/text()' },
                    Test      => { type => 'master' }
                   }
         );

  When the GetUsername() function is called, the AUTOLOAD function looks
  in the Namespaces.pm hash for a "Username" key.  Based on the "type" of
  the field (scalar being the default) it will use the "path" as an XPath
  to retrieve the data and call the XPathGet() method in Stanza.pm.

  Confused yet?

=head2 Net::XMPP private namespaces

  Now this is where this starts to get a little sticky.  When you see a
  namespace with __netxmpp__, or __netjabber__ from Net::Jabber, at the
  beginning it is usually something custom to Net::XMPP and NOT part of
  the actual XMPP protocol.

  There are some places where the structure of the XML allows for
  multiple children with the same name.  The main places you will see
  this behavior is where you have multiple tags with the same name and
  those have children under them (jabber:iq:roster).

  In jabber:iq:roster, the <item/> tag can be repeated multiple times,
  and is sort of like a mini-namespace in itself.  To that end, we treat
  it like a separate namespace and defined a __netxmpp__:iq:roster:item
  namespace to hold it.  What happens is this, in my code I define that
  the <item/>s tag is "item" and anything with that tag name is to create
  a new Net::XMPP::Stanza object with the namespace
  __netxmpp__:iq:roster:item which then becomes a child of the
  jabber:iq:roster Stanza object.  Also, when you want to add a new item
  to a jabber:iq:roster project you call NewQuery with the private
  namespace.

  I know this sounds complicated.  And if after reading this entire
  document it is still complicated, email me, ask questions, and I will
  monitor it and adjust these docs to answer the questions that people
  ask.

=head2 add_ns()

  To repeat, here is an example call to add_ns():

    &add_ns(ns    => "mynamespace",
            tag   => "mytag",
            xpath => {
                      JID       => { type=>'jid', path => '@jid' },
                      Username  => { path => 'username/text()' },
                      Test      => { type => 'master' }
                     }
           );

  ns - This is the new namespace that you are trying to add.

  tag - This is the root tag to use for objects based on this namespace.

  xpath - The hash reference passed in the add_ns call to each name of
  entry tells Net::XMPP how to handle subsequent GetXXXX(), SetXXXX(),
  DefinedXXXX(), RemoveXXXX(), AddXXXX() calls.  The basic options you
  can pass in are:

     type - This tells Stanza how to handle the call.  The possible
            values are:

           array - The value to set and returned is an an array
                   reference.  For example, <group/> in jabber:iq:roster.

           child - This tells Stanza that it needs to look for the
                   __netxmpp__ style namesapced children.  AddXXX() adds
                   a new child, and GetXXX() will return a new Stanza
                   object representing the packet.

           flag - This is for child elements that are tags by themselves:
                  <foo/>.  Since the presence of the tag is what is
                  important, and there is no cdata to store, we just call
                  it a flag.

           jid - The value is a Jabber ID.  GetXXX() will return a
                 Net::XMPP::JID object unless you pass it "jid", then it
                 returns a string.

           master - The GetXXX() and SetXXX() calls return and take a
                    hash representing all of the GetXXX() and SetXXX()
                    calls.  For example:

                      SetTest(foo=>"bar",
                              bar=>"baz");

                    Translates into:

                      SetFoo("bar");
                      SetBar("baz");

                    GetTest() would return a hash containing what the
                    packet contains:

                      { foo=>"bar",  bar=>"baz" }

           raw - This will stick whatever raw XML you specify directly
                 into the Stanza at the point where the path specifies.

           scalar - This will set and get a scalar value.  This is the
                    main workhorse as attributes and CDATA is represented
                    by a scalar.  This is the default setting if you do
                    not provide one.

           special - The special type is unique in that instead of a
                     string "special", you actually give it an array:

                       [ "special" , <subtype> ]

                     This allows Net::XMPP to be able to handle the
                     SetXXXX() call in a special manner according to your
                     choosing.  Right now this is mainly used by
                     jabber:iq:time to automatically set the time info in
                     the correct format, and jabber:iq:version to set the
                     machine OS and add the Net::Jabber version to the
                     return packet.  You will likely NOT need to use
                     this, but I wanted to mention it.

           timestamp - If you call SetXXX() but do not pass it anything,
                       or pass it "", then Net::XMPP will place a
                       timestamp in the xpath location.

     path - This is the XPath path to where the bit data lives.  The
            difference.  Now, this is not full XPath due to the nature
            of how it gets used.  Instead of providing a rooted path
            all the way to the top, it's a relative path ignoring what
            the parent is.  For example, if the "tag" you specified was
            "foo", and the path is "bar/text()", then the XPath will be
            rooted in the XML of the <foo/> packet.  It will set and get
            the CDATA from:

               <foo><bar>xxxxx</bar></foo>

            For a flag and a child type, just specify the child element.
            Take a look at the code in this file for more help on what
            this means.  Also, read up on XPath if you don't already know
            what it is.

     child - This is a hash reference that tells Net::XMPP how to handle
             adding and getting child objects.  The keys for the hash are
             as follows:

             ns - the real or custom (__netxmpp__) namesapce to use for
                  this child packet.

             skip_xmlns => 1 - this tells Net::XMPP not to add an
                               xmlns='' into the XML for the child
                               object.

             specify_name => 1 - allows you to call NewChild("ns","tag")
                                 and specify the tag to use for the child
                                 object.  This, IMHO, is BAD XML
                                 practice.  You should always know what
                                 the tag of the child is and use an
                                 attribute or CDATA to change the type
                                 of the stanza.  You do not want to use
                                 this.

             tag - If you use specify_name, then this is the default tag
                   to use.  You do not want to use this.

     calls - Array reference telling Net::XMPP what functions to create
             for this name.  For most of the types above you will get
             Get, Set, Defined, and Remove.  For child types you need to
             decide how you API will look and specify them yourself:

               ["Get","Defined"]
               ["Add"]
               ["Get","Add","Defined"]

            It all depends on how you want your API to look.

  Once more... The following:

    &add_ns(ns    => "mynamespace",
            tag   => "mytag",
            xpath => {
                      JID       => { type=>'jid', path => '@jid' },
                      Username  => { path => 'username/text()' },
                      Test      => { type => 'master' }
                     }
           );

  generates the following API calls:

    GetJID()
    SetJID()
    DefinedJID()
    RemoveJID()
    GetUsername()
    SetUsername()
    DefinedUsername()
    RemoveUsername()
    GetTest()
    SetTest()

=head2 Wrap Up

  Well.  I hope that I have not scared you off from writing a custom
  namespace for you application and use Net::XMPP.  Look in the
  Net::XMPP::Protocol manpage for an example on using the add_ns()
  function to register your custom namespace so that Net::XMPP can
  properly handle it.

=head1 AUTHOR

Ryan Eatmon

=head1 COPYRIGHT

This module is free software, you can redistribute it and/or modify it
under the LGPL.

=cut

use vars qw ( %NS %SKIPNS );

$SKIPNS{'__netxmpp__'} = 1;

#------------------------------------------------------------------------------
# __netxmpp__:child:test
#------------------------------------------------------------------------------
{
    &add_ns(ns    => "__netxmpptest__:child:test",
            tag   => "test",
            xpath => {
                      Bar  => { path => 'bar/text()' },
                      Foo  => { path => '@foo' },
                      Test => { type => 'master' }
                     }
           );
}

#------------------------------------------------------------------------------
# __netxmpp__:child:test:two
#------------------------------------------------------------------------------
{
    &add_ns(ns    => "__netxmpptest__:child:test:two",
            tag   => "test",
            xpath => {
                      Bob  => { path => 'owner/@bob' },
                      Joe  => { path => 'joe/text()' },
                      Test => { type => 'master' }
                     }
           );
}

#-----------------------------------------------------------------------------
# urn:ietf:params:xml:ns:xmpp-bind
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "urn:ietf:params:xml:ns:xmpp-bind",
            tag   => "bind",
            xpath => {
                      JID      => { type => 'jid',
                                    path => 'jid/text()',
                                  },
                      Resource => { path => 'resource/text()' },
                      Bind     => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# urn:ietf:params:xml:ns:xmpp-session
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "urn:ietf:params:xml:ns:xmpp-session",
            tag   => "session",
            xpath => { Session => { type => 'master' } },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# jabber:iq:auth
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "jabber:iq:auth",
            tag   => "query",
            xpath => {
                      Digest   => { path => 'digest/text()' },
                      Hash     => { path => 'hash/text()' },
                      Password => { path => 'password/text()' },
                      Resource => { path => 'resource/text()' },
                      Sequence => { path => 'sequence/text()' },
                      Token    => { path => 'token/text()' },
                      Username => { path => 'username/text()' },
                      Auth     => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# jabber:iq:privacy
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "jabber:iq:privacy",
            tag   => "query",
            xpath => {
                      Active  => { path => 'active/@name' },
                      Default => { path => 'default/@name' },
                      List    => {
                                  type  => 'child',
                                  path  => 'list',
                                  child => { ns => '__netxmpp__:iq:privacy:list', },
                                  calls => [ 'Add' ],
                                 },
                      Lists   => {
                                  type  => 'child',
                                  path  => 'list',
                                  child => { ns => '__netxmpp__:iq:privacy:list', },
                                 },
                      Privacy => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# __netxmpp__:iq:privacy:list
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => '__netxmpp__:iq:privacy:list',
            xpath => {
                      Name  => { path => '@name' },
                      Item  => {
                                type  => 'child',
                                path  => 'item',
                                child => { ns => '__netxmpp__:iq:privacy:list:item', },
                                calls => [ 'Add' ],
                               },
                      Items => {
                                type  => 'child',
                                path  => 'item',
                                child => { ns => '__netxmpp__:iq:privacy:item', },
                               },
                      List  => { type => 'master' },
                    },
            docs  => {
                      module => 'Net::XMPP',
                      name   => 'jabber:iq:privacy - list objects',
                     },
           );
}

#-----------------------------------------------------------------------------
# __netxmpp__:iq:privacy:list:item
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => '__netxmpp__:iq:privacy:list:item',
            xpath => {
                      Action      => { path => '@action' },
                      IQ          => {
                                      type => 'flag',
                                      path => 'iq',
                                     },
                      Message     => {
                                      type => 'flag',
                                      path => 'message',
                                     },
                      Order       => { path => '@order' },
                      PresenceIn  => {
                                      type => 'flag',
                                      path => 'presence-in',
                                     },
                      PresenceOut => {
                                      type => 'flag',
                                      path => 'presence-out',
                                     },
                      Type        => { path => '@type' },
                      Value       => { path => '@value' },
                      Item        => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                      name   => 'jabber:iq:privacy - item objects',
                     },
           );
}

#-----------------------------------------------------------------------------
# jabber:iq:register
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "jabber:iq:register",
            tag   => "query",
            xpath => {
                      Address      => { path => 'address/text()' },
                      City         => { path => 'city/text()' },
                      Date         => { path => 'date/text()' },
                      Email        => { path => 'email/text()' },
                      First        => { path => 'first/text()' },
                      Instructions => { path => 'instructions/text()' },
                      Key          => { path => 'key/text()' },
                      Last         => { path => 'last/text()' },
                      Misc         => { path => 'misc/text()' },
                      Name         => { path => 'name/text()' },
                      Nick         => { path => 'nick/text()' },
                      Password     => { path => 'password/text()' },
                      Phone        => { path => 'phone/text()' },
                      Registered   => {
                                       type => 'flag',
                                       path => 'registered',
                                      },
                      Remove       => {
                                       type => 'flag',
                                       path => 'remove',
                                      },
                      State        => { path => 'state/text()' },
                      Text         => { path => 'text/text()' },
                      URL          => { path => 'url/text()' },
                      Username     => { path => 'username/text()' },
                      Zip          => { path => 'zip/text()' },
                      Register     => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# jabber:iq:roster
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => 'jabber:iq:roster',
            tag   => "query",
            xpath => {
                      Item  => {
                                type  => 'child',
                                path  => 'item',
                                child => { ns => '__netxmpp__:iq:roster:item', },
                                calls => [ 'Add' ],
                               },
                      Items => {
                                type  => 'child',
                                path  => 'item',
                                child => { ns => '__netxmpp__:iq:roster:item', },
                                calls => [ 'Get' ],
                               },
                      Roster => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                     },
           );
}

#-----------------------------------------------------------------------------
# __netxmpp__:iq:roster:item
#-----------------------------------------------------------------------------
{
    &add_ns(ns    => "__netxmpp__:iq:roster:item",
            xpath => {
                      Ask          => { path => '@ask' },
                      Group        => {
                                       type => 'array',
                                       path => 'group/text()',
                                      },
                      JID          => {
                                       type => 'jid',
                                       path => '@jid',
                                      },
                      Name         => { path => '@name' },
                      Subscription => { path => '@subscription' },
                      Item         => { type => 'master' },
                     },
            docs  => {
                      module => 'Net::XMPP',
                      name   => 'jabber:iq:roster - item objects',
                     },
           );
}



sub add_ns
{
    my (%args) = @_;

    # XXX error check...

    $NS{$args{ns}}->{tag} = $args{tag} if exists($args{tag});
    $NS{$args{ns}}->{xpath} = $args{xpath};
    if (exists($args{docs}))
    {
        $NS{$args{ns}}->{docs} = $args{docs};
        $NS{$args{ns}}->{docs}->{name} = $args{ns}
            unless exists($args{docs}->{name});
    }
}


1;