Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include "../../parser/parse_content.h"
00039 #include "../presence/event_list.h"
00040 #include "presence_mwi.h"
00041
00043 inline char *eat_sp_tab(char *at, char *over)
00044 {
00045 while((at < over) && ((*at == ' ') || (*at == '\t'))) at++;
00046 return at;
00047 }
00048
00050 inline char *eat_printable(char *at, char *over)
00051 {
00052 while ((at < over) && ((*at == '\t') || ((*at >= 32) && (*at <= 126))))
00053 at++;
00054 return at;
00055 }
00056
00060 int mwi_publ_handl(struct sip_msg* msg)
00061 {
00062 str body;
00063 char *at, *over;
00064
00065 if (get_content_length(msg) == 0)
00066 return 1;
00067
00068 body.s = get_body(msg);
00069 if (body.s == NULL) {
00070 LM_ERR("cannot extract body from msg\n");
00071 return -1;
00072 }
00073
00074
00075 body.len = get_content_length(msg);
00076 at = body.s;
00077 over = body.s + body.len;
00078
00079
00080 if (body.len <= 16) goto err;
00081 if (strncmp(body.s, "Messages-Waiting", 16) != 0) goto err;
00082 at = at + 16;
00083 at = eat_sp_tab(at, over);
00084 if ((at >= over) || (*at != ':')) goto err;
00085 at++;
00086 if ((at >= over) || ((*at != ' ') && (*at != '\t'))) goto err;
00087 at++;
00088 at = eat_sp_tab(at, over);
00089 if (at + 3 >= over) goto err;
00090 if (strncmp(at, "yes", 3) == 0) at = at + 3;
00091 else
00092 if (strncmp(at, "no", 2) == 0) at = at + 2;
00093 else
00094 goto err;
00095 if ((at + 1 >= over) || (*at != '\r') || (*(at + 1) != '\n')) goto err;
00096 at = at + 2;
00097
00098
00099
00100 while (at < over) {
00101 at = eat_printable(at, over);
00102 if ((at + 1 >= over) || (*at != '\r') || (*(at + 1) != '\n')) goto err;
00103 at = at + 2;
00104 }
00105
00106 return 1;
00107
00108 err:
00109 LM_ERR("check of body <%.*s> failed at character number %d\n",
00110 body.len, body.s, (int)(at - body.s + 1));
00111 return -1;
00112
00113 }
00114
00115 int mwi_add_events(void)
00116 {
00117 pres_ev_t event;
00118
00119
00120 memset(&event, 0, sizeof(pres_ev_t));
00121 event.name.s = "message-summary";
00122 event.name.len = 15;
00123
00124 event.content_type.s = "application/simple-message-summary";
00125 event.content_type.len = 34;
00126
00127 event.default_expires= 3600;
00128 event.type = PUBL_TYPE;
00129 event.req_auth = 0;
00130 event.evs_publ_handl = mwi_publ_handl;
00131
00132 if (pres_add_event(&event) < 0) {
00133 LM_ERR("failed to add event \"message-summary\"\n");
00134 return -1;
00135 }
00136
00137 return 0;
00138 }