Browse code

-exported a MI command - mi cmd: refreshWatchers <pres_uri> <event_packege> that makes possible modifying watcher permissions in real time

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

Anca Vamanu authored on 15/05/2007 14:28:19
Showing 2 changed files
... ...
@@ -50,10 +50,13 @@
50 50
 #include "../tm/tm_load.h"
51 51
 #include "../sl/sl_api.h"
52 52
 #include "../../pt.h"
53
+#include "../../mi/mi.h"
53 54
 #include "publish.h"
54 55
 #include "subscribe.h"
55 56
 #include "event_list.h"
56 57
 #include "bind_presence.h"
58
+#include "notify.h"
59
+
57 60
 MODULE_VERSION
58 61
 
59 62
 #define S_TABLE_VERSION 1
... ...
@@ -92,7 +95,7 @@ int handle_publish(struct sip_msg*, char*, char*);
92 95
 int handle_subscribe(struct sip_msg*, char*, char*);
93 96
 int stored_pres_info(struct sip_msg* msg, char* pres_uri, char* s);
94 97
 static int fixup_presence(void** param, int param_no);
95
-//int handle_notify(struct sip_msg*, char*, char*);
98
+struct mi_root* refreshWatchers(struct mi_root* cmd, void* param);
96 99
 
97 100
 int counter =0;
98 101
 int pid = 0;
... ...
@@ -108,12 +111,12 @@ void destroy(void);
108 111
 
109 112
 static cmd_export_t cmds[]=
110 113
 {
111
-	{"handle_publish",		handle_publish,	        0,	   0,           REQUEST_ROUTE},
112
-	{"handle_publish",		handle_publish,	        1,  fixup_presence, REQUEST_ROUTE},
113
-	{"handle_subscribe",	handle_subscribe,	    0,	   0,           REQUEST_ROUTE},
114
-	{"bind_presence", (cmd_function)bind_presence,  1,     0,             0          },
115
-	{"add_event",         (cmd_function)add_event,  1,     0,             0          },
116
-	{0,						0,				        0,	   0,             0			 }	 
114
+	{"handle_publish",		handle_publish,	     0,	   0,        REQUEST_ROUTE},
115
+	{"handle_publish",		handle_publish,	     1,fixup_presence,REQUEST_ROUTE},
116
+	{"handle_subscribe",	handle_subscribe,	 0,	   0,         REQUEST_ROUTE},
117
+	{"bind_presence",(cmd_function)bind_presence,1,    0,            0         },
118
+	{"add_event",    (cmd_function)add_event,    1,    0,            0         },
119
+	{0,						0,				     0,	   0,            0	       }	 
117 120
 };
118 121
 
119 122
 static param_export_t params[]={
... ...
@@ -130,6 +133,11 @@ static param_export_t params[]={
130 133
 	{0,0,0}
131 134
 };
132 135
 
136
+static mi_export_t mi_cmds[] = {
137
+	{ "refershWatchers", refreshWatchers,    0,  0,  0},
138
+	{ 0, 0, 0, 0}
139
+};
140
+
133 141
 /** module exports */
134 142
 struct module_exports exports= {
135 143
 	"presence",					/* module name */
... ...
@@ -137,7 +145,7 @@ struct module_exports exports= {
137 145
 	cmds,						/* exported functions */
138 146
 	params,						/* exported parameters */
139 147
 	0,							/* exported statistics */
140
-	0  ,						/* exported MI functions */
148
+	mi_cmds,   					/* exported MI functions */
141 149
 	0,							/* exported pseudo-variables */
142 150
 	mod_init,					/* module initialization function */
143 151
 	(response_function) 0,      /* response handling function */
... ...
@@ -350,3 +358,70 @@ static int fixup_presence(void** param, int param_no)
350 358
  	LOG(L_ERR, "PRESENCE:fixup_presence: ERROR null format\n");
351 359
  	return E_UNSPEC;
352 360
 }
361
+/* 
362
+ *  mi cmd: refreshWatchers
363
+ *			<presentity_uri> 
364
+ *			<event>
365
+ * */
366
+
367
+struct mi_root* refreshWatchers(struct mi_root* cmd, void* param)
368
+{
369
+	struct mi_node* node= NULL;
370
+	str pres_uri, event;
371
+	ev_t* ev;
372
+	struct sip_uri uri;
373
+
374
+	DBG("PRESENCE:refreshWatchers: start\n");
375
+	
376
+	node = cmd->node.kids;
377
+	if(node == NULL)
378
+		return 0;
379
+
380
+	/* Get presentity URI */
381
+	pres_uri = node->value;
382
+	if(pres_uri.s == NULL || pres_uri.s== 0)
383
+	{
384
+		LOG(L_ERR, "PRESENCE:refreshWatchers: empty uri\n");
385
+		return init_mi_tree(404, "Empty presentity URI", 20);
386
+	}
387
+	if(parse_uri(pres_uri.s, pres_uri.len, &uri)<0 )
388
+	{
389
+		LOG(L_ERR, "PRESENCE:refreshWatchers: bad uri\n");
390
+		return init_mi_tree(404, "Bad presentity URI", 18);
391
+	}
392
+	DBG("PRESENCE:refreshWatchers: pres_uri '%.*s'\n",
393
+	    pres_uri.len, pres_uri.s);
394
+	
395
+	node = node->next;
396
+	if(node == NULL)
397
+		return 0;
398
+	event= node->value;
399
+	if(event.s== NULL || event.len== 0)
400
+	{
401
+		LOG(L_ERR, "PRESENCE:refreshWatchers: "
402
+		    "empty event parameter\n");
403
+		return init_mi_tree(400, "Empty event parameter", 21);
404
+	}
405
+	DBG("PRESENCE:refreshWatchers: event '%.*s'\n",
406
+	    event.len, event.s);
407
+	
408
+	if(node->next!= NULL)
409
+	{
410
+		LOG(L_ERR, "PRESENCE:refreshWatchers: Too many parameters\n");
411
+		return init_mi_tree(400, "Too many parameters", 19);
412
+	}
413
+
414
+	ev= contains_event(&event, NULL);
415
+	if(ev== NULL)
416
+	{
417
+		LOG(L_ERR, "PRESENCE:refreshWatchers: ERROR wrong event parameter\n");
418
+		return 0;
419
+	}	
420
+	if(query_db_notify(&uri.user, &uri.host, ev, NULL)< 0)
421
+	{
422
+		LOG(L_ERR, "PRESENCE:refreshWatchers: ERROR while sending notify");
423
+		return 0;
424
+	}	
425
+	
426
+	return init_mi_tree(200, "OK", 2);
427
+}	
... ...
@@ -277,8 +277,6 @@ error:
277 277
 	return;	
278 278
 }
279 279
 
280
-
281
-
282 280
 /**
283 281
  * PUBLISH request handling
284 282
  *