[Serusers] Re: problem for using the latest pa module

Klaus Darilion klaus.mailinglists at pernau.at
Fri May 28 17:39:20 CEST 2004


Hi Jamey!

Attached are the files which were modified by the student (Dimitre 
Tachkov). At the end of the email, there is also a "cvs diff".

I will shortly explain what the project was: An IPAQ with a GPS receiver 
received the GPS coordinates and they were transmitted with a PUBLISH to 
the server. The coordnates received from the GPS receiver are in the 
NMEA format:

$GPRMC,POS_UTC,POS_STAT,LAT,LAT_REF,LON,LON_REF,SPD,HDG,DATE,MAG_VAR,MAG_REF*CC<cr><lf>

e.g.
$GPRMC,105759.180,A,2821.7359,N,01923.7878,E,0.00,,190404,,*0C
                     ^^^^^x^^^^^  ^^^^y^^^^
x=28° 21.7359' (minutes)
y=...

The received x and y coordinates were put into the PUBLISH request in 
between <x> and <y> tags:

PUBLISH sip:tachkov at methusalix.ict.tuwien.ac.at SIP/2.0
Via: SIP/2.0/UDP methusalix.ict.tuwien.ac.at:5060;rport
From:
sip:tachkov at methusalix.ict.tuwien.ac.at;tag=8343f82348d1022ace010a43c363e58f
To: sip:tachkov at methusalix.ixt.tuwien.ac.at
Call-ID: f8b9ac03ca12a9ddd03aa4ef368fa46c at methusalix.ict.tuwien.ac.at
CSeq: 3961 PUBLISH
Max-Forwards: 30
Event: presence
Accept: aplpication/cpim-pidf+xml
Expires: 50
User-Agent: SIP Example Tester
Content-Type: application/cpim-pidf+xml
Content-Length: 280

<?xml version="1.0" encoding="UTF-8"?>
<presence xmlns="urn:ietf:params:xml:ns:pidf"
entity="pres:tachkov at methusalix.ict.tuwien.ac.at">
<tuple id="sg89ae">
<status>
<basic>offline</basic>
<geopriv><location-info><civilAddress>
<x>01923.7878</x>
<y>2821.7359</y>
</civilAddress></location-info></geopriv>
</status>
<contact priority="0.8">Dimitar Tashkov</contact>
</tuple>
</presence>

So, I guess the module which processes this request was modified to 
handle the x and y coordinates.

And now to the messenger part. I don't know the original problem with 
Messenger, I only know that it works now (my student showed it to me). 
Messenger transports the presence status in the msnsubstatus tags. This 
was extended to transport the coordinates, as following  (NOTIFY from 
ser to messenger with content-type application/xpidf+xml):

<?xml version="1.0"?>
<!DOCTYPE presence PUBLIC "//IETF//DTD RFCxxxx XPIDF 1.0//EN" "xpidf.dtd">
<presence>
<presentity uri="sip:tachkov at methusalix.ict.tuwien.ac.at;method=SUBSCRIBE"/>
<atom id="9r28r49">
<address uri="sip:tachkov at methusalix.ict.tuwien.ac.at;user=ip"
priority="0,800000">
<status status="open">
<msnsubstatus substatus="online"/>
<note>1923.7878 2821.7359</note>
</status>
</address>
</atom>
</presence>


The <note> tag can be read and written with the RTC API.

A problem was the "offline" status. Sending a NOTIFY with 
substatus="offline" does not work. To see a buddy as "offline" in 
Messenger, ser has to send a NOTIFY with Expires: 0 and empty body:

NOTIFY sip:128.131.80.101:13359 SIP/2.0
Via: SIP/2.0/UDP 128.131.80.174;branch=z9hG4bK2101.825b6a47.0
To: "messenger" 
<sip:messenger at methusalix.ict.tuwien.ac.at>;tag=2bbdb0d6-6a85
From: 
<sip:tachkov at methusalix.ict.tuwien.ac.at>;tag=a6a1c5f60faecf035a1ae5b6e
CSeq: 1 NOTIFY
Call-ID: c0013a85-47fe-41b4-8369-e2de22fd17cf at 128.131.80.101
Content-Length: 0
User-Agent: Sip EXpress router(0.8.13-dev-23-merged (i386/linux))
Event: presence
Content-Type: application/xpidf+xml
Subscription-State: terminated;reason=deactivated
Expires: 0

After this NOTIFY, Messenger tries to SUBSCRIBE again. Therefore, the 
existing subscription must be terminated in ser after sending the NOTIFY 
with Expires: 0. Therefore, the methodes
   static inline int add_subs_state_hf(...)
   tatic inline int create_headers(...)
were extended with a "flag" which signals if a NOTIFY with Expires: 0 
should be sent.

Here some statements from the student about wrong implementations in the 
pa module:
- It does not differentiate between application/cpim-pidf+xml and 
application/pidf+xml
- ser didn't send a NOTIFY after a SUBSCRIBE message, only after 
received PUBLISH requests.
- The espires header in the publish request is not interpreted.
- The header field "SIP-If-Match" is not implemented in the pa module.

Finally, the received coordinates are displayed on a modified kphone 
(see the attached screenshot).

regards,
Klaus



cvs server: Diffing .
Index: notify.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/notify.c,v
retrieving revision 1.14
diff -r1.14 notify.c
120a121,125
 > // added from tachkov
 > #define EXPIRES_HEADER_0 "Expires: 0"
 > #define EXPIRES_HEADER_0_L (sizeof(EXPIRES_HEADER_0)-1)
 > // tachkov end
 >
247c252
< static inline int add_subs_state_hf(str* _h, int _l, subs_state_t _s, 
ss_reason_t _r, time_t _e)
---
 > static inline int add_subs_state_hf(str* _h, int _l, subs_state_t _s, 
ss_reason_t _r, time_t _e, int flag)
251,258c256,274
<
<       if (_l < SUBSCRIPTION_STATE_L + subs_states[_s].len + 
SS_EXPIRES_L +
<           SS_REASON_L + reason[_r].len + CRLF_L) {
<               paerrno = PA_SMALL_BUFFER;
<               LOG(L_ERR, "add_subs_state_hf(): Buffer too small\n");
<               return -1;
<       }
<
---
 >
 >     // modified by tachkov (EXPIRES_HEADER_0_L)
 >     if (flag) {
 >         if (_l < SUBSCRIPTION_STATE_L + EXPIRES_HEADER_0_L + 
subs_states[_s].len + SS_EXPIRES_L +
 >             SS_REASON_L + reason[_r].len + CRLF_L) {
 >                 paerrno = PA_SMALL_BUFFER;
 >                 LOG(L_ERR, "add_subs_state_hf(): Buffer too small\n");
 >                 return -1;
 >         }
 >     }
 >     else {
 >         if (_l < SUBSCRIPTION_STATE_L + subs_states[_s].len + 
SS_EXPIRES_L +
 >             SS_REASON_L + reason[_r].len + CRLF_L) {
 >                 paerrno = PA_SMALL_BUFFER;
 >                 LOG(L_ERR, "add_subs_state_hf(): Buffer too small\n");
 >                 return -1;
 >         }
 >     }
 >
279c295,299
<       return 0;
---
 >     // added from tachkov
 >     if (flag)
 >         str_append(_h, EXPIRES_HEADER_0 CRLF, EXPIRES_HEADER_0_L + 
CRLF_L);
 >     // tachkov end
 >     return 0;
283c303
< static inline int create_headers(struct watcher* _w)
---
 > static inline int create_headers(struct watcher* _w, int flag)
289,292c309,312
<
<       if (add_event_hf(&headers, BUF_LEN, _w->accept) < 0) {
<               LOG(L_ERR, "create_headers(): Error while adding Event 
header field\n");
<               return -1;
---
 >
 >     if (add_event_hf(&headers, BUF_LEN, _w->accept) < 0) {
 >         LOG(L_ERR, "create_headers(): Error while adding Event header 
field\n");
 >         return -1;
296,297c316,317
<               LOG(L_ERR, "create_headers(): Error while adding 
Content-Type header field\n");
<               return -2;
---
 >         LOG(L_ERR, "create_headers(): Error while adding Content-Type 
header field\n");
 >         return -2;
299c319
<
---
 >
309,313c329,353
<       if (add_subs_state_hf(&headers, BUF_LEN - headers.len, s, 
SR_TIMEOUT, t) < 0) {
<               LOG(L_ERR, "create_headers(): Error while adding 
Subscription-State\n");
<               return -3;
<       }
<
---
 >     // modified by tachkov
 >     /*
 >     if (!flag) {
 >         if (add_subs_state_hf(&headers, BUF_LEN - headers.len, s, 
SR_TIMEOUT, t,0) < 0) {
 >                 LOG(L_ERR, "create_headers(): Error while adding 
Subscription-State\n");
 >                 return -3;
 >         }
 >     }
 >     else
 >       str_append(&headers, EXPIRES_HEADER_0 CRLF, EXPIRES_HEADER_0_L 
+ CRLF_L);
 >     */
 >
 >     if (flag) {
 >         if (add_subs_state_hf(&headers, BUF_LEN - headers.len, 
SS_TERMINATED, SR_DEACTIVATED, 0,1) < 0) {
 >                 LOG(L_ERR, "create_headers(): Error while adding 
Subscription-State\n");
 >                 return -3;
 >         }
 >     }
 >     else {
 >         if (add_subs_state_hf(&headers, BUF_LEN - headers.len, s, 
SR_TIMEOUT, t,0) < 0) {
 >                 LOG(L_ERR, "create_headers(): Error while adding 
Subscription-State\n");
 >                 return -3;
 >         }
 >     }
 >
328c368,372
<
---
 >   // modified by tachkov (by offline state don't add body into NOTIFY 
Request
 >   // (Microsoft Messanger compatibillity)
 >   int offline = 1;
 >   if (tuple->state == PS_ONLINE) {
 >     offline = 0;
345,348c389,400
<               if (xpidf_add_address(&body, BUF_LEN - body.len, 
&_p->uri, st) < 0) {
<                       LOG(L_ERR, "send_xpidf_notify(): 
xpidf_add_address failed\n");
<                       return -3;
<               }
---
 >         // modified by tachkov
 >         //if (st != XPIDF_ST_CLOSED) {
 >           double _x = -1;
 >           double _y = -1;
 >           if (tuple->location.x) _x = tuple->location.x;
 >           if (tuple->location.y) _y = tuple->location.y;
 >
 >           if (xpidf_add_address(&body, BUF_LEN - body.len, &_p->uri, 
_x, _y, st) < 0) {
 >                   LOG(L_ERR, "send_xpidf_notify(): xpidf_add_address 
failed\n");
 >                   return -3;
 >                 }
 >         //}
351,352c403,404
<       }
<       if (end_xpidf_doc(&body, BUF_LEN - body.len) < 0) {
---
 >        }
 >        if (end_xpidf_doc(&body, BUF_LEN - body.len) < 0) {
355c407,408
<       }
---
 >        }
 >    } // end create body
357c410,411
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >     if (create_headers(_w,offline) < 0) {
362a417,436
 >
 >     // added from tachkov
 >     int et = EVENT_PRESENCE;  // can be changed & implemented to 
process other events too
 >     if (offline) {
 >         if (et == EVENT_PRESENCE) {
 >           if (remove_watcher(_p, _w) < 0) {
 >             LOG(L_ERR, "send_xpidf_notify(): Error while deleting 
winfo watcher\n");
 >             return -7;
 >           }
 >       }
 >       else {
 >           if (remove_winfo_watcher(_p, _w) < 0) {
 >             LOG(L_ERR, "send_xpidf_notify(): Error while deleting 
winfo watcher\n");
 >             return -8;
 >           }
 >       }
 >       return -99;
 >     }
 >     // tachkov end
 >
392c466,467
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >       if (create_headers(_w,0) < 0) {
458c533,534
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >       if (create_headers(_w,0) < 0) {
501c577,578
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >       if (create_headers(_w,0) < 0) {
535c612,613
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >       if (create_headers(_w,0) < 0) {
580c658,659
<       if (create_headers(_w) < 0) {
---
 >     // modified by tachkov
 >       if (create_headers(_w,0) < 0) {
Index: pdomain.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/pdomain.c,v
retrieving revision 1.10
diff -r1.10 pdomain.c
164c164
<               if (timer_presentity(ptr) < 0) {
---
 >               if (timer_presentity(ptr, _d) < 0) {
Index: presentity.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/presentity.c,v
retrieving revision 1.11
diff -r1.11 presentity.c
463c463,464
< int timer_presentity(presentity_t* _p)
---
 > // modified by tachkov
 > int timer_presentity(presentity_t* _p, struct pdomain *_d)
493c494
<               notify_watchers(_p);
---
 >               notify_watchers(_p,_d);
588c589,590
< int notify_watchers(presentity_t* _p)
---
 > // modified by tachkov
 > int notify_watchers(presentity_t* _p, struct pdomain *_d)
593a596,597
 >     // added & modified by tachkov
 >     int remove = 0;
595c599,605
<               send_notify(_p, ptr);
---
 >         remove = 0;
 >               remove = send_notify(_p, ptr);
 >         if (remove == -99) {
 >         if (!_p->watchers && !_p->winfo_watchers)
 >               remove_presentity(_d, _p);
 >           ptr->expires = 0;   /* The watcher will be freed after 
NOTIFY is sent */
 >         }
759a770,771
 >
 >
Index: presentity.h
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/presentity.h,v
retrieving revision 1.10
diff -r1.10 presentity.h
120c120
< int timer_presentity(presentity_t* _p);
---
 > int timer_presentity(presentity_t* _p, struct pdomain *_d);
163c163,164
< int notify_watchers(presentity_t* _p);
---
 > // modified by tachkov
 > int notify_watchers(presentity_t* _p, struct pdomain *_d);
Index: xpidf.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/xpidf.c,v
retrieving revision 1.7
diff -r1.7 xpidf.c
66c66
< #define PRESENTITY_START "<presentity uri=\""
---
 > #define PRESENTITY_START "<presentity uri=\"sip:"
75c75
< #define ADDRESS_START "<address uri=\""
---
 > #define ADDRESS_START "<address uri=\"sip:"
77c77
<
---
 > /*
79a80,85
 > */
 >
 > // tachkov
 > #define ADDRESS_END ";user=ip\" priority=\"0,800000\">"
 > #define ADDRESS_END_L (sizeof(ADDRESS_END) - 1)
 > // tachkov end
80a87
 > /*
88a96,118
 > */
 >
 > // tachkov
 > #define STATUS_OPEN "<status status=\"open\">\r\n"
 > #define STATUS_OPEN_L (sizeof(STATUS_OPEN) - 1)
 >
 > #define STATUS_CLOSED "<status status=\"closed\">\r\n"
 > #define STATUS_CLOSED_L (sizeof(STATUS_CLOSED) - 1)
 >
 > #define STATUS_INUSE "<status status=\"inuse\">\r\n"
 > #define STATUS_INUSE_L (sizeof(STATUS_INUSE) - 1)
 >
 > #define MSNSUBSTATUS_ONLINE "<msnsubstatus substatus=\"online\"/>\r\n"
 > #define MSNSUBSTATUS_ONLINE_L (sizeof(MSNSUBSTATUS_ONLINE)-1)
 >
 > #define MSNSUBSTATUS_OFFLINE "<msnsubstatus substatus=\"offline\"/>\r\n"
 > #define MSNSUBSTATUS_OFFLINE_L (sizeof(MSNSUBSTATUS_OFFLINE)-1)
 >
 > #define NOTE_BEGIN "<note>"
 > #define NOTE_BEGIN_L (sizeof(NOTE_BEGIN)-1)
 >
 > #define NOTE_END "</note>\r\n"
 > #define NOTE_END_L (sizeof(NOTE_END)-1)
89a120,122
 > #define STATUS_END "</status>"
 > #define STATUS_END_L (sizeof(STATUS_END)-1)
 > // tachkov end
135c168,169
< int xpidf_add_address(str* _b, int _l, str* _addr, xpidf_status_t _st)
---
 > // modified by tachkov (x & y information will be send too)
 > int xpidf_add_address(str* _b, int _l, str* _addr, double _x, double 
_y, xpidf_status_t _st)
140,144c174,191
<       switch(_st) {
<       case XPIDF_ST_OPEN:   p = STATUS_OPEN;   len = STATUS_OPEN_L; 
break;
<       case XPIDF_ST_CLOSED: p = STATUS_CLOSED; len = STATUS_CLOSED_L; 
break;
<       case XPIDF_ST_INUSE:  p = STATUS_INUSE;  len = STATUS_INUSE_L; 
break;
<       default:              p = STATUS_CLOSED; len = STATUS_CLOSED_L; 
break; /* Makes gcc happy */
---
 >     // tachkov
 >     int len_available = 0;
 >     char * available;
 >     // tachkov end
 >
 >       switch(_st) { // modified by tachkov
 >       case XPIDF_ST_OPEN:      p = STATUS_OPEN;   len = STATUS_OPEN_L;
 >                                                available = 
MSNSUBSTATUS_ONLINE; len_available = MSNSUBSTATUS_ONLINE_L;
 >                                                break;
 >       case XPIDF_ST_CLOSED: p = STATUS_CLOSED; len = STATUS_CLOSED_L;
 >                                                available = 
MSNSUBSTATUS_OFFLINE; len_available = MSNSUBSTATUS_OFFLINE_L;
 >                                                break;
 >       case XPIDF_ST_INUSE:     p = STATUS_INUSE;  len = STATUS_INUSE_L;
 >                                                available = 
MSNSUBSTATUS_OFFLINE; len_available = MSNSUBSTATUS_OFFLINE_L;
 >                                                break;
 >       default:                                p = STATUS_CLOSED; len 
= STATUS_CLOSED_L;
 >                                                available = 
MSNSUBSTATUS_OFFLINE; len_available = MSNSUBSTATUS_OFFLINE_L;
 >                                                break; /* Makes gcc 
happy */
146a194,203
 >     // added from tachkov
 >     char buf_x[128];
 >     int len_x = 0;
 >     char buf_y[128];
 >     int len_y = 0;
 >
 >     len_x = sprintf(buf_x, "%.4f", _x);
 >     len_y = sprintf(buf_y, "%.4f", _y);
 >     // tachkov end
 >
153c210,217
<                 len +
---
 >                 len +
 >           len_available +  // added from tachkov
 >           NOTE_BEGIN_L + // added from tachkov
 >           len_x +             // added from tachkov
 >           1 +                   // one space between x and y coords
 >           len_y +             // added from tachkov
 >           NOTE_END_L + // added from tachkov
 >           STATUS_END_L +   // added from tachkov
169a234,242
 >     // tachkov
 >     str_append(_b,available, len_available);
 >     str_append(_b,NOTE_BEGIN, NOTE_BEGIN_L);
 >     str_append(_b,buf_x,len_x);
 >     str_append(_b," ",1);
 >     str_append(_b,buf_y,len_y);
 >     str_append(_b,NOTE_END,NOTE_END_L);
 >     str_append(_b,STATUS_END,STATUS_END_L);
 >     // tachkov end
Index: xpidf.h
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/pa/xpidf.h,v
retrieving revision 1.3
diff -r1.3 xpidf.h
58c58
< int xpidf_add_address(str* _b, int _l, str* _addr, xpidf_status_t _st);
---
 > int xpidf_add_address(str* _b, int _l, str* _addr, double _x, double 
_y, xpidf_status_t _st);
cvs server: Diffing doc


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: notify.c
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pdomain.c
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: presentity.c
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment-0001.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: presentity.h
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: xpidf.c
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment-0002.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: xpidf.h
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment-0002.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kphone-screenshot.gif
Type: image/gif
Size: 102568 bytes
Desc: not available
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20040528/8a94c46d/attachment.gif>


More information about the sr-users mailing list