Browse Source

new exec examples introduced

Jiri Kuthan 22 years ago
parent
commit
5eb5c40da1
5 changed files with 233 additions and 0 deletions
  1. 23 0
      examples/exec_s2.cfg
  2. 27 0
      examples/exec_s3.cfg
  3. 39 0
      examples/exec_s4.cfg
  4. 65 0
      examples/exec_s5.cfg
  5. 79 0
      examples/exec_s5b.cfg

+ 23 - 0
examples/exec_s2.cfg

@@ -0,0 +1,23 @@
+#
+# $Id$
+#
+# send a notificiation if a request for user jiri arrives
+# ------------------ module loading ----------------------------------
+
+loadmodule "modules/exec/exec.so"
+loadmodule "modules/sl/sl.so"
+
+# -------------------------  request routing logic -------------------
+
+# main routing logic
+
+route{
+	# send email if a request for jiri arrives
+	if (uri=~"^sip:jiri@") {
+		exec_msg("(egrep -i '^(From|f):'; 
+			echo 'request received')|
+			mail -s 'request for you' jiri");
+	};
+
+}
+

+ 27 - 0
examples/exec_s3.cfg

@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+# email notification to email address from mysql database
+#
+
+# ------------------ module loading ----------------------------------
+
+loadmodule "modules/exec/exec.so"
+loadmodule "modules/sl/sl.so"
+
+# send email if a request arrives
+route[0] {
+     if (!exec_msg('
+	QUERY="select email_address from subscriber 
+		where user_id=\"$SIP_OUSER\"";
+	EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
+	if [ -z "$EMAIL" ] ; then exit 1; fi ;
+	echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
+	mail -s "request for you" $EMAIL ')) {
+		# exec returned error ... user does not exist
+		sl_send_reply("404", "User does not exist");
+	} else {
+		sl_send_reply("600", "No messages for this user");
+	};
+		
+}

+ 39 - 0
examples/exec_s4.cfg

@@ -0,0 +1,39 @@
+#
+# $Id$
+#
+# email notification to email address from mysql database
+#
+
+fork=no
+
+# ------------------ module loading ----------------------------------
+
+loadmodule "modules/exec/exec.so"
+loadmodule "modules/sl/sl.so"
+loadmodule "modules/tm/tm.so"
+
+# send email if a request arrives; process statefully
+# to avoid multiple execution on request retransmissions
+route[0] {
+	# stop script processing if transaction exists
+	if ( !t_newtran()) {
+		sl_reply_error();
+		break;
+	};
+
+     	if (!exec_msg('
+		QUERY="select email_address from subscriber 
+			where user_id=\"$SIP_OUSER\"";
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
+		mail -s "request for you" $EMAIL ')) 
+	{
+		# exec returned error ... user does not exist
+		# send a stateful reply
+		t_reply("404", "User does not exist");
+	} else {
+		t_reply("600", "No messages for this user");
+	};
+		
+}

+ 65 - 0
examples/exec_s5.cfg

@@ -0,0 +1,65 @@
+#
+# $Id$
+#
+# simple quick-start config script
+#
+fork=no
+log_stderror=yes
+# ----------- global configuration parameters ------------------------
+
+loadmodule "modules/sl/sl.so"
+loadmodule "modules/tm/tm.so"
+loadmodule "modules/usrloc/usrloc.so"
+loadmodule "modules/registrar/registrar.so"
+loadmodule "modules/exec/exec.so"
+
+# ----------------- setting module-specific parameters ---------------
+
+route{
+	# uri for my domain ?
+	if (uri==myself) {
+
+		if (method=="REGISTER") {
+			save("location");
+			break;
+		};
+
+		# native SIP destinations are handled using our USRLOC DB
+		if (!lookup("location")) {
+			# proceed to email notification
+			if (method=="INVITE") route(1)
+			else sl_send_reply("404", "Not Found");
+			break;
+		};
+	};
+	# user found, forward to his current uri now
+	if (!t_relay()) {
+		sl_reply_error();
+	};
+}
+
+/* handling of missed calls */
+route[1] {
+	# don't continue if it is a retransmission
+	if ( !t_newtran()) {
+		sl_reply_error();
+		break;
+	};
+	# external script: lookup user, if user exists, send 
+	# an email notification to him
+     	if (!exec_msg('
+		QUERY="select email_address from subscriber 
+			where user_id=\"$SIP_OUSER\"";
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
+		mail -s "request for you" $EMAIL ')) 
+	{
+		# exec returned error ... user does not exist
+		# send a stateful reply
+		t_reply("404", "User does not exist");
+	} else {
+		t_reply("600", "No messages for this user");
+	};
+	break;
+}

+ 79 - 0
examples/exec_s5b.cfg

@@ -0,0 +1,79 @@
+#
+# $Id$
+#
+# simple quick-start config script
+#
+fork=no
+log_stderror=yes
+# ----------- global configuration parameters ------------------------
+
+loadmodule "modules/sl/sl.so"
+loadmodule "modules/tm/tm.so"
+loadmodule "modules/usrloc/usrloc.so"
+loadmodule "modules/registrar/registrar.so"
+loadmodule "modules/exec/exec.so"
+
+# ----------------- setting module-specific parameters ---------------
+
+route{
+	# uri for my domain ?
+	if (uri==myself) {
+
+		if (method=="REGISTER") {
+			save("location");
+			break;
+		};
+
+		# native SIP destinations are handled using our USRLOC DB
+		if (!lookup("location")) {
+			# proceed to email notification
+			if (method=="INVITE") route(1)
+			else sl_send_reply("404", "Not Found");
+			break;
+		};
+	};
+	# user found, forward to his current uri now; if any 
+	# forwarding error occurs (e.g., busy or cancelled recevied
+	# from downstream), proceed to reply_route[1]
+	t_on_negative("1");
+	if (!t_relay()) {
+		sl_reply_error();
+	};
+}
+
+/* handling of missed calls */
+route[1] {
+	# don't continue if it is a retransmission
+	if ( !t_newtran()) {
+		sl_reply_error();
+		break;
+	};
+	# external script: lookup user, if user exists, send 
+	# an email notification to him
+     	if (!exec_msg('
+		QUERY="select email_address from subscriber 
+			where user_id=\"$SIP_OUSER\"";
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
+		mail -s "request for you" $EMAIL ')) 
+	{
+		# exec returned error ... user does not exist
+		# send a stateful reply
+		t_reply("404", "User does not exist");
+	} else {
+		t_reply("600", "No messages for this user");
+	};
+	break;
+}
+
+reply_route[1] {
+	# just call exec, that's it
+     	exec_msg('
+		QUERY="select email_address from subscriber 
+			where user_id=\"$SIP_OUSER\"";
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
+		mail -s "request for you" $EMAIL ') ;
+}