فهرست منبع

websocket: added $ws_conid pseudo variable
- gives id of closed connection in websocket:closed event route

Juha Heinanen 9 سال پیش
والد
کامیت
00f108dfb3
4فایلهای تغییر یافته به همراه75 افزوده شده و 10 حذف شده
  1. 33 8
      modules/websocket/README
  2. 24 1
      modules/websocket/doc/websocket_admin.xml
  3. 2 0
      modules/websocket/ws_conn.c
  4. 16 1
      modules/websocket/ws_mod.c

+ 33 - 8
modules/websocket/README

@@ -4,7 +4,7 @@ Peter Dunkley
 
    Crocodile RCS Ltd
 
-   Copyright © 2012-2013 Crocodile RCS Ltd
+   Copyright © 2012-2013 Crocodile RCS Ltd
      __________________________________________________________________
 
    Table of Contents
@@ -51,6 +51,10 @@ Peter Dunkley
 
               7.1. websocket:closed
 
+        8. Exported Pseudo Variables
+
+              8.1. $ws_conid
+
    List of Examples
 
    1.1. event_route[xhttp:request]
@@ -65,6 +69,7 @@ Peter Dunkley
    1.10. ws_handle_handshake usage
    1.11. ws_close usage
    1.12. event_route[websocket:closed] usage
+   1.13. $ws_conid usage
 
 Chapter 1. Admin Guide
 
@@ -110,6 +115,10 @@ Chapter 1. Admin Guide
 
         7.1. websocket:closed
 
+   8. Exported Pseudo Variables
+
+        8.1. $ws_conid
+
 1. Overview
 
    This module implements a WebSocket (RFC 6455) server and provides
@@ -129,11 +138,11 @@ Chapter 1. Admin Guide
 2.1. Initiating a connection
 
    A WebSocket connection is initiated with an HTTP GET. The xhttp module
-   is used to handle this GET and call the Section 5.1, "
-   ws_handle_handshake() " exported function.
+   is used to handle this GET and call the Section 5.1, “
+   ws_handle_handshake() � exported function.
 
    event_route[xhttp:request] should perform some validation of the HTTP
-   headers before calling Section 5.1, " ws_handle_handshake() ". The
+   headers before calling Section 5.1, “ ws_handle_handshake() �. The
    event_route can also be used to make sure the HTTP GET has the correct
    URI, perform HTTP authentication on the WebSocket connection, and check
    the Origin header (RFC 6454) to ensure a browser-based SIP UA or MSRP
@@ -437,7 +446,7 @@ modparam("websocket", "cors_mode", 2)
    5.1. ws_handle_handshake()
    5.2. ws_close([status, reason[, connection_id]])
 
-5.1. ws_handle_handshake()
+5.1.  ws_handle_handshake()
 
    This function checks an HTTP GET request for the required headers and
    values, and (if successful) upgrades the connection from HTTP to
@@ -456,7 +465,7 @@ Note
 ws_handle_handshake();
 ...
 
-5.2. ws_close([status, reason[, connection_id]])
+5.2.  ws_close([status, reason[, connection_id]])
 
    This function closes a WebSocket connection.
 
@@ -497,7 +506,7 @@ ws_close(4000, "Because I say so");
    Name: ws.dump
 
    Parameters:
-     * order (optional) - "id_hash", "used_desc", or "used_asc".
+     * order (optional) - “id_hash�, “used_desc�, or “used_asc�.
 
 Note
 
@@ -582,7 +591,7 @@ Note
 
    7.1. websocket:closed
 
-7.1. websocket:closed
+7.1.  websocket:closed
 
    When defined, the module calls event_route[websocket:closed] when a
    connection closes. The connection may be identified using the the $si
@@ -594,3 +603,19 @@ event_route[websocket:closed] {
         xlog("L_INFO", "WebSocket connection from $si:$sp has closed\n");
 }
 ...
+
+8. Exported Pseudo Variables
+
+   8.1. $ws_conid
+
+8.1. $ws_conid
+
+   Connection id of closed websocket connection. Can only be used in
+   websocket:closed event route.
+
+   Example 1.13. $ws_conid usage
+...
+event_route[websocket:closed] {
+        xlog("L_INFO", "WebSocket connection with id $ws_conid has closed\n");
+}
+...

+ 24 - 1
modules/websocket/doc/websocket_admin.xml

@@ -632,6 +632,29 @@ event_route[websocket:closed] {
 		</example>
 	</section>
 
-	</section>	
+	</section>
+    
+	<section>
+		<title>Exported Pseudo Variables</title>
+		<section>
+			<title><function moreinfo="none">$ws_conid</function></title>
+			<para>
+			Connection id of closed websocket connection.  Can only be
+            used in websocket:closed event route.
+			</para>
+		<example>
+		<title>$ws_conid usage</title>
+		<programlisting format="linespecific">
+...
+event_route[websocket:closed] {
+        xlog("L_INFO", "WebSocket connection with id $ws_conid has closed\n");
+}
+...
+		</programlisting>
+		</example>
+	        </section>
+
+	</section>
+
 </chapter>
 

+ 2 - 0
modules/websocket/ws_conn.c

@@ -292,7 +292,9 @@ static void wsconn_run_route(ws_connection_t *wsc)
 		LM_ERR("faked_msg_init() failed\n");
 		return;
 	}
+	
 	fmsg = faked_msg_next();
+	wsc->rcv.proto_reserved1 = wsc->id;
 	fmsg->rcv = wsc->rcv;
 
 	backup_rt = get_route_type();

+ 16 - 1
modules/websocket/ws_mod.c

@@ -52,6 +52,7 @@ static int mod_init(void);
 static int child_init(int rank);
 static void destroy(void);
 static int ws_close_fixup(void** param, int param_no);
+static int pv_get_ws_conid_f(struct sip_msg *, pv_param_t *, pv_value_t *);
 
 sl_api_t ws_slb;
 
@@ -159,6 +160,12 @@ static mi_export_t mi_cmds[] =
 	{ 0, 0, 0, 0, 0 }
 };
 
+static pv_export_t mod_pvs[] = {
+    {{"ws_conid", (sizeof("ws_conid")-1)}, PVT_CONTEXT,
+     pv_get_ws_conid_f, 0, 0, 0, 0, 0},
+    {{0, 0}, 0, 0, 0, 0, 0, 0, 0}
+};
+
 struct module_exports exports= 
 {
 	"websocket",
@@ -167,7 +174,7 @@ struct module_exports exports=
 	params,			/* Exported parameters */
 	stats,			/* exported statistics */
 	mi_cmds,		/* exported MI functions */
-	0,			/* exported pseudo-variables */
+	mod_pvs,                /* exported pseudo-variables */
 	0,			/* extra processes */
 	mod_init,		/* module initialization function */
 	0,			/* response function */
@@ -341,3 +348,11 @@ static int ws_close_fixup(void** param, int param_no)
 		return 0;
 	}
 }
+
+static int pv_get_ws_conid_f(struct sip_msg *msg, pv_param_t *param,
+			     pv_value_t *res)
+{
+    if (msg == NULL) return -1;
+
+    return pv_get_sintval(msg, param, res, msg->rcv.proto_reserved1);
+}