- fixed malformed 489 Bad Event reply , added Allow-Events header.
authorAnca Vamanu <anca@voice-system.ro>
Wed, 4 Jul 2007 10:06:10 +0000 (10:06 +0000)
committerAnca Vamanu <anca@voice-system.ro>
Wed, 4 Jul 2007 10:06:10 +0000 (10:06 +0000)
- updated documentation

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2396 689a6050-402a-0410-94f2-e92a70836424

modules_k/presence/README
modules_k/presence/doc/presence_devel.sgml
modules_k/presence/publish.c
modules_k/presence/subscribe.c
modules_k/presence/utils_func.c
modules_k/presence/utils_func.h

index 5ac5254..b34e230 100644 (file)
@@ -48,8 +48,9 @@ Anca-Maria Vamanu
         2.3. apply_auth_nbody
         2.4. is_watcher_allowed
         2.5. agg_nbody
-        2.6. evs_publ_handl
-        2.7. evs_subs_handl
+        2.6. free_body
+        2.7. evs_publ_handl
+        2.8. evs_subs_handl
 
    3. Frequently Asked Questions
 
@@ -392,6 +393,7 @@ typedef struct ev
         agg_nbody_t* agg_nbody;
         publ_handling_t  * evs_publ_handl;
         subs_handling_t  * evs_subs_handl;
+        free_body_t*    free_body;
 
 /* this two should not be filed when the structure is given as a
         parmeter for add_event function */
@@ -442,7 +444,21 @@ typedef str* (agg_nbody_t)(str** body_array, int n, int off_index);
 ..
      _________________________________________________________
 
-2.6. evs_publ_handl
+2.6. free_body
+
+   This field must be field in if subsequent processing is
+   performed on the info from database before beeing inserted in
+   Notify message body(if agg_nbody or apply_auth_nbody fields
+   are filled in). It should match the allocation function used
+   when processing the body.
+
+   Filed type:
+...
+typedef void(free_body_t)(char* body);
+..
+     _________________________________________________________
+
+2.7. evs_publ_handl
 
    This function is called when handling Publish requests. Most
    contain body correctitude check.
@@ -452,7 +468,7 @@ typedef int (publ_handling_t)(struct sip_msg*);
 ..
      _________________________________________________________
 
-2.7. evs_subs_handl
+2.8. evs_subs_handl
 
    It is not compulsory. Should contain event specific handling
    for Subscription requests.
index 4c277d5..041268a 100644 (file)
@@ -64,6 +64,7 @@ typedef struct ev
        agg_nbody_t* agg_nbody;
        publ_handling_t  * evs_publ_handl;
        subs_handling_t  * evs_subs_handl;
+       free_body_t*    free_body;
 
 /* this two should not be filed when the structure is given as a
        parmeter for add_event function */
@@ -130,7 +131,27 @@ typedef int (is_allowed_t)(struct subscription* subs);
 typedef str* (agg_nbody_t)(str** body_array, int n, int off_index);
 ..
                        </programlisting>
-                       </para>
+               </para>
+</section>     
+
+<section>
+               <title>
+                       <function moreinfo="none">free_body</function>
+               </title>
+               <para>
+                       This field must be field in if subsequent processing is performed on the info
+                       from database before beeing inserted in Notify message body(if agg_nbody
+                       or apply_auth_nbody fields are filled in). It should match the allocation 
+                       function used when processing the body.  
+               </para>
+               <para>
+               Filed type:
+                       <programlisting format="linespecific">
+...
+typedef void(free_body_t)(char* body);
+..
+                       </programlisting>
+               </para>
 </section>     
 
 <section>
index 7ee883d..a5c2960 100644 (file)
@@ -53,9 +53,6 @@ extern int startup_time;
 
 static str pu_400a_rpl = str_init("Bad request");
 static str pu_400b_rpl = str_init("Invalid request");
-static str pu_489_rpl  = str_init("Bad Event");
-
-
 
 void msg_presentity_clean(unsigned int ticks,void *param)
 {
@@ -534,18 +531,17 @@ error:
        return error_ret;
 
 unsupported_event:
-
+       
        LOG(L_ERR, "PRESENCE: handle_publish:Missing or unsupported event"
                        " header field value\n");
-
+               
        if(msg->event && msg->event->body.s && msg->event->body.len>0)
                LOG(L_ERR, "\tevent=[%.*s]\n", msg->event->body.len,
                        msg->event->body.s);
+       
+       if(reply_bad_event(msg)< 0)
+               return -1;
 
-       if (slb.reply(msg, 489, &pu_489_rpl) == -1)
-       {
-               LOG(L_ERR, "PRESENCE: handle_publish: Error while sending reply\n");
-       }
        return 0;
 
 }
index 9d64868..0821ac0 100644 (file)
@@ -26,7 +26,6 @@
  *  2006-08-15  initial version (anca)
  */
 
-
 #include "../../ut.h"
 #include "../../usr_avp.h"
 #include "../../data_lump_rpl.h"
@@ -47,7 +46,6 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, unsigned int* remote_cs
 static str su_200_rpl  = str_init("OK");
 static str pu_481_rpl  = str_init("Subscription does not exist");
 static str pu_400_rpl  = str_init("Bad request");
-static str pu_489_rpl  = str_init("Bad Event");
 
 int send_202ok(struct sip_msg * msg, int lexpire, str *rtag, str* local_contact)
 {
@@ -1531,11 +1529,9 @@ bad_event:
 
        LOG(L_ERR, "PRESENCE: handle_subscribe:Missing or unsupported event"
                " header field value\n");
-       if (slb.reply(msg, 489, &pu_489_rpl) == -1)
-       {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR while sending"
-                       " reply\n");
-       }
+       if(reply_bad_event(msg)< 0)
+               return -1;
+
        error_ret = 0;
 
 error:
index 2237c2a..ec31b3a 100644 (file)
  *  2006-08-15  initial version (anca)
  */
 
-#include "utils_func.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include "../../mem/mem.h"
 #include "../../dprint.h"
-#include <ctype.h>
+#include "../../ut.h"
+#include "../../data_lump_rpl.h"
+#include "utils_func.h"
+#include "event_list.h"
+
+static str pu_489_rpl  = str_init("Bad Event");
 
 static const char base64digits[] =
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -79,53 +84,58 @@ void to64frombits(unsigned char *out, const unsigned char *in, int inlen)
                
 }
 
+int a_to_i (char *s,int len)
+{
+       int n = 0, i= 0;
+       
+       while( i<len  )         
+               n=n*10+( s[i++] -'0');
+       
+       return n;
+}
 
-
-/*
-str* int_to_str(long int n)
+int reply_bad_event(struct sip_msg * msg)
 {
-       str* n_str;
-       int m = n, i=0;
-       if(m==0)
-               i=1;
+       str hdr_append;
+       char buffer[256];
+       int i;
+       ev_t* ev= EvList->events;
 
-       while( m>0 )
+       hdr_append.s = buffer;
+       hdr_append.s[0]='\0';
+       hdr_append.len = sprintf(hdr_append.s, "Allow-Events: ");
+       if(hdr_append.len < 0)
        {
-               m= m/10;
-               i++;
+               LOG(L_ERR, "PRESENCE:handle_publish: ERROR unsuccessful sprintf\n");
+               return -1;
        }
 
-       n_str = (str*)pkg_malloc(sizeof(str));
-       if(n_str == NULL)
+       for(i= 0; i< EvList->ev_count; i++)
        {
-               LOG(L_ERR,"PRESENCE:int_to_str: ERROR while allocating memory\n");
-               return NULL;
-       }       
-       n_str->s = (char*)pkg_malloc( (i+1) * sizeof(char));
-       if(n_str->s == NULL)
+               if(i> 0)
+               {
+                       memcpy(hdr_append.s+ hdr_append.len, ", ", 2);
+                       hdr_append.len+= 2;
+               }       
+               memcpy(hdr_append.s+ hdr_append.len, ev->stored_name.s, ev->stored_name.len );
+               hdr_append.len+= ev->stored_name.len ;
+               ev= ev->next;
+       }
+       memcpy(hdr_append.s+ hdr_append.len, CRLF, CRLF_LEN);
+       hdr_append.len+=  CRLF_LEN;
+       hdr_append.s[hdr_append.len]= '\0';
+               
+       if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"PRESENCE:int_to_str: ERROR while allocating memory\n");
-               return NULL;
+               LOG(L_ERR,"PRESENCE: handle_publish:ERROR unable to add lump_rl\n");
+               return -1;
        }
-       
-       n_str->len = i;
-       n_str->s[i] = 0;        
-       while( i>0 )
+
+       if (slb.reply(msg, 489, &pu_489_rpl) == -1)
        {
-               i--;
-               n_str->s[i]=n%10 + '0';
-               n = n/10;
+               LOG(L_ERR, "PRESENCE: handle_publish: Error while sending reply\n");
+               return -1;
        }
-       return n_str;
-}
-*/
-int a_to_i (char *s,int len)
-{
-       int n = 0, i= 0;
-       
-       while( i<len  )         
-               n=n*10+( s[i++] -'0');
-       
-       return n;
+       return 0;
 }
 
index df3b745..216deb6 100644 (file)
@@ -35,6 +35,7 @@
 #include "../../mem/mem.h"
 #include "../../dprint.h"
 #include "../../str.h"
+#include "../../parser/msg_parser.h"
 
 static inline int uandd_to_uri(str user,  str domain, str *out)
 {
@@ -72,6 +73,7 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
 int a_to_i (char *s,int len);
 
 void to64frombits(unsigned char *out, const unsigned char *in, int inlen);
+int reply_bad_event(struct sip_msg * msg);
 
 #endif