>From 6afefa9aea84e0e2d1d4bc06b19bd77d7c3631e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= <misi@niif.hu>
Date: Thu, 29 Sep 2011 10:14:12 +0200
Subject: [PATCH] add basic ua-profile event support

---
 Makefile                                           |    4 +-
 modules/tls/Makefile                               |    1 +
 modules_k/presence/event_list.c                    |    2 +-
 modules_k/presence_profile/Makefile                |   11 ++
 modules_k/presence_profile/README                  |   77 +++++++++++++
 modules_k/presence_profile/add_events.c            |   66 +++++++++++
 modules_k/presence_profile/add_events.h            |   40 +++++++
 modules_k/presence_profile/doc/Makefile            |    4 +
 .../presence_profile/doc/presence_profile.xml      |   39 +++++++
 .../doc/presence_profile_admin.xml                 |   72 ++++++++++++
 modules_k/presence_profile/presence_profile.c      |  118 ++++++++++++++++++++
 modules_k/presence_profile/presence_profile.h      |   38 +++++++
 parser/parse_event.c                               |    1 +
 parser/parse_event.h                               |    1 +
 14 files changed, 471 insertions(+), 3 deletions(-)
 create mode 100644 modules_k/presence_profile/Makefile
 create mode 100644 modules_k/presence_profile/README
 create mode 100644 modules_k/presence_profile/add_events.c
 create mode 100644 modules_k/presence_profile/add_events.h
 create mode 100644 modules_k/presence_profile/doc/Makefile
 create mode 100644 modules_k/presence_profile/doc/presence_profile.xml
 create mode 100644 modules_k/presence_profile/doc/presence_profile_admin.xml
 create mode 100644 modules_k/presence_profile/presence_profile.c
 create mode 100644 modules_k/presence_profile/presence_profile.h

diff --git a/Makefile b/Makefile
index 0eb44e8..dc81f2c 100644
--- a/Makefile
+++ b/Makefile
@@ -174,7 +174,7 @@ module_group_radius=acc_radius auth_radius misc_radius avp_radius uri_radius \
 
 # For presence
 # kamailio modules
-module_group_presence=presence presence_dialoginfo presence_mwi presence_xml \
+module_group_presence=presence presence_dialoginfo presence_mwi presence_xml presence_profile\
 						pua pua_bla pua_dialoginfo pua_mi pua_usrloc pua_xmpp \
 						rls xcap_client xcap_server presence_conference \
 						presence_reginfo pua_reginfo
@@ -259,7 +259,7 @@ module_group_kmemcached=memcached
 module_group_ktls=tls
 
 # K presence modules
-module_group_kpresence=presence presence_dialoginfo presence_mwi presence_xml \
+module_group_kpresence=presence presence_dialoginfo presence_mwi presence_xml presence_profile\
 						pua pua_bla pua_dialoginfo pua_mi pua_usrloc pua_xmpp \
 						rls xcap_client xcap_server presence_conference \
 						presence_reginfo pua_reginfo
diff --git a/modules/tls/Makefile b/modules/tls/Makefile
index 6e00b70..dd446c7 100644
--- a/modules/tls/Makefile
+++ b/modules/tls/Makefile
@@ -10,6 +10,7 @@ auto_gen=
 NAME=tls.so
 
 DEFS+= -I$(LOCALBASE)/ssl/include
+EXTRA_DEFS="-DTLS_WR_DEBUG -DTLS_RD_DEBUG"
 LIBS+=	-L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib \
 		-L$(LOCALBASE)/lib64 -L$(LOCALBASE)/ssl/lib64 \
 		-lssl  -lcrypto \
diff --git a/modules_k/presence/event_list.c b/modules_k/presence/event_list.c
index 0d628b6..eb83d6b 100644
--- a/modules_k/presence/event_list.c
+++ b/modules_k/presence/event_list.c
@@ -356,7 +356,7 @@ pres_ev_t* search_event(event_t* event)
 				strncasecmp(pres_ev->evp->name.s,event->name.s,
 					pres_ev->evp->name.len)== 0))
 		{
-			if(event->params.list== NULL && pres_ev->evp->params.list== NULL)
+			if((event->params.list== NULL && pres_ev->evp->params.list== NULL) || event->type==EVENT_UA_PROFILE)
 			{
 				return pres_ev;
 			}
diff --git a/modules_k/presence_profile/Makefile b/modules_k/presence_profile/Makefile
new file mode 100644
index 0000000..addf9e2
--- /dev/null
+++ b/modules_k/presence_profile/Makefile
@@ -0,0 +1,11 @@
+# 
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=presence_profile.so
+LIBS=
+
+DEFS+=-DOPENSER_MOD_INTERFACE
+
+include ../../Makefile.modules
diff --git a/modules_k/presence_profile/README b/modules_k/presence_profile/README
new file mode 100644
index 0000000..1d59539
--- /dev/null
+++ b/modules_k/presence_profile/README
@@ -0,0 +1,77 @@
+Presence_Profile Module
+
+Mih����ly M����sz����ros
+
+   <misi@niif.hu>
+
+Edited by
+
+M����sz����ros Mih����ly
+
+   <misi@niif.hu>
+
+   Copyright �� 2011 M����sz����ros Mih����ly
+     __________________________________________________________________
+
+   Table of Contents
+
+   1. Admin Guide
+
+        1. Overview
+        2. Dependencies
+
+              2.1. Kamailio Modules
+              2.2. External Libraries or Applications
+
+        3. Exported Parameters
+        4. Exported Functions
+
+Chapter 1. Admin Guide
+
+   Table of Contents
+
+   1. Overview
+   2. Dependencies
+
+        2.1. Kamailio Modules
+        2.2. External Libraries or Applications
+
+   3. Exported Parameters
+   4. Exported Functions
+
+1. Overview
+
+   The module does a very basic handling for ua-profile. You can subscribe
+   to ua-profile provisioning information if you add a provisioning
+   document to presentity table.
+
+   Warning: When you add provisioning config to presentity table, then you
+   must make sure that you set the presentity table expires field to a
+   time value in long future
+
+   If your user agent is subscribing to AoR and if the subscription event
+   is ua-profile, then it will receive provisioning data in the
+   notification body. Read more about sip user agent configuration
+   framework in RFC6080. http://tools.ietf.org/html/rfc6080
+
+2. Dependencies
+
+   2.1. Kamailio Modules
+   2.2. External Libraries or Applications
+
+2.1. Kamailio Modules
+
+   The following modules must be loaded before this module:
+     * presence.
+
+2.2. External Libraries or Applications
+
+   None.
+
+3. Exported Parameters
+
+   None.
+
+4. Exported Functions
+
+   None to be used in configuration file.
diff --git a/modules_k/presence_profile/add_events.c b/modules_k/presence_profile/add_events.c
new file mode 100644
index 0000000..d4ee90c
--- /dev/null
+++ b/modules_k/presence_profile/add_events.c
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright (C) 2011 M��sz��ros Mih��ly
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ *  2011-09-22  initial version (misi)
+ */
+
+/*!
+ * \file
+ * \brief SIP-router Presence :: ua-profile provisioning support
+ * \ingroup presence
+ * Module: \ref presence
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../../parser/parse_content.h"
+#include "../presence/event_list.h"
+#include "presence_profile.h"
+
+
+int profile_add_events(void)
+{
+    pres_ev_t event;
+	
+    /* constructing profile event */
+    memset(&event, 0, sizeof(pres_ev_t));
+    event.name.s = "ua-profile";
+    event.name.len = 10;
+
+
+    event.content_type.s = "text/xml";
+    event.content_type.len = 8;
+
+    event.default_expires= 3600;
+    event.type = PUBL_TYPE;
+    event.req_auth = 0;
+    event.evs_publ_handl = 0;
+    
+    if (pres_add_event(&event) < 0) {
+	LM_ERR("failed to add event \"ua-profile\"\n");
+	return -1;
+    }		
+	
+    return 0;
+}
diff --git a/modules_k/presence_profile/add_events.h b/modules_k/presence_profile/add_events.h
new file mode 100644
index 0000000..6d9498f
--- /dev/null
+++ b/modules_k/presence_profile/add_events.h
@@ -0,0 +1,40 @@
+/*
+ * presence_profile module - add_event header file
+ *
+ * Copyright (C) 2011 M��sz��ros Mih��ly
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ *  2011-11-22  initial version (misi)
+ */
+
+/*!
+ * \file
+ * \brief SIP-router Presence :: ua-profile provisioning support
+ * \ingroup presence
+ * Module: \ref presence
+ */
+
+
+#ifndef _PROFILE_ADD_EV_H_
+#define _PROFILE_ADD_EV_H_
+
+int profile_add_events(void);
+
+#endif
diff --git a/modules_k/presence_profile/doc/Makefile b/modules_k/presence_profile/doc/Makefile
new file mode 100644
index 0000000..3c6a162
--- /dev/null
+++ b/modules_k/presence_profile/doc/Makefile
@@ -0,0 +1,4 @@
+docs = presence_profile.xml
+
+docbook_dir = ../../../docbook
+include $(docbook_dir)/Makefile.module
diff --git a/modules_k/presence_profile/doc/presence_profile.xml b/modules_k/presence_profile/doc/presence_profile.xml
new file mode 100644
index 0000000..9478a57
--- /dev/null
+++ b/modules_k/presence_profile/doc/presence_profile.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
+%docentities;
+
+]>
+
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
+    <bookinfo>
+	<title>Presence_Profile Module</title>
+	<productname class="trade">&kamailioname;</productname>
+	<authorgroup>
+	    <author>
+		<firstname>Mih��ly</firstname>
+		<surname>M��sz��ros</surname>
+		<email>misi@niif.hu</email>
+	    </author>
+	    <editor>
+		<firstname>M��sz��ros</firstname>
+		<surname>Mih��ly</surname>
+  	        <email>misi@niif.hu</email>
+	    </editor>
+	</authorgroup>
+	<copyright>
+	    <year>2011</year>
+	    <holder>M��sz��ros Mih��ly</holder>
+	</copyright>
+  </bookinfo>
+    <toc></toc>
+    
+    <xi:include href="presence_profile_admin.xml"/>
+    
+    
+</book>
+
+
diff --git a/modules_k/presence_profile/doc/presence_profile_admin.xml b/modules_k/presence_profile/doc/presence_profile_admin.xml
new file mode 100644
index 0000000..e1c026f
--- /dev/null
+++ b/modules_k/presence_profile/doc/presence_profile_admin.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
+%docentities;
+
+]>
+<!-- Module User's Guide -->
+
+<chapter>
+	
+
+	<title>&adminguide;</title>
+	
+	<section>
+	  <title>Overview</title>
+	    <para> 
+	      The module does a very basic handling for ua-profile.
+	      You can subscribe to ua-profile provisioning information if you add a provisioning document to presentity table.
+	    </para>
+	    <para>
+	      Warning: When you add provisioning config to presentity table, then you must make sure 
+	      that you set the presentity table expires field to a time value in long future
+	    </para>
+	    <para>
+	      If your user agent is subscribing to AoR and if the subscription event is ua-profile, then it will receive provisioning data in the notification body.
+	      Read more about sip user agent configuration framework in RFC6080. http://tools.ietf.org/html/rfc6080
+	    </para>
+	</section>
+
+	<section>
+	  <title>Dependencies</title>
+	  <section>
+		<title>&kamailio; Modules</title>
+		<para>
+		The following modules must be loaded before this module:
+			<itemizedlist>
+			<listitem>
+			<para>
+				<emphasis>presence</emphasis>.
+			</para>
+			</listitem>
+			</itemizedlist>
+		</para>
+	  </section>
+
+	  <section>
+		<title>External Libraries or Applications</title>
+		<para>
+		None.
+		</para>
+	  </section>
+	</section>
+	
+	<section>
+	  <title>Exported Parameters</title>
+		<para>
+		  None.
+		</para>
+        </section>
+
+        <section>
+	  <title>Exported Functions</title>
+	      <para>
+	        None to be used in configuration file.
+	      </para>
+	</section>
+
+</chapter>
+
diff --git a/modules_k/presence_profile/presence_profile.c b/modules_k/presence_profile/presence_profile.c
new file mode 100644
index 0000000..686dbd5
--- /dev/null
+++ b/modules_k/presence_profile/presence_profile.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2011 M��sz��ros Mih��ly
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ *  2011-09-22  initial version (misi)
+ */
+
+
+/*!
+ * \defgroup presence_profile Presence_profile :: Presence Handling of ua-profile events
+ */
+
+/*!
+ * \file
+ * \brief SIP-router Presence :: ua-profile provisioning support
+ * \ingroup presence
+ * Module: \ref presence
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "../../sr_module.h"
+#include "../../dprint.h"
+#include "../../str.h"
+#include "../../parser/msg_parser.h"
+#include "../../mem/mem.h"
+#include "../presence/bind_presence.h"
+#include "add_events.h"
+#include "presence_profile.h"
+
+MODULE_VERSION
+
+/* module functions */
+static int mod_init(void);
+
+/* module variables */
+add_event_t pres_add_event;
+
+/* module exported commands */
+static cmd_export_t cmds[] =
+{
+    {0,	0, 0, 0, 0, 0}
+};
+
+/* module exported paramaters */
+static param_export_t params[] = {
+    {0, 0, 0}
+};
+
+/* module exports */
+struct module_exports exports= {
+    "presence_profile",				/* module name */
+    DEFAULT_DLFLAGS,            /* dlopen flags */
+    cmds,						/* exported functions */
+    params,						/* exported parameters */
+    0,							/* exported statistics */
+    0,							/* exported MI functions */
+    0,							/* exported pseudo-variables */
+	0,							/* extra processes */
+    mod_init,					/* module initialization function */
+    0,							/* response handling function */
+    0,							/* destroy function */
+    0							/* per-child init function */
+};
+	
+/*
+ * init module function
+ */
+static int mod_init(void)
+{
+	presence_api_t pres;
+    bind_presence_t bind_presence;
+
+    bind_presence= (bind_presence_t)find_export("bind_presence", 1,0);
+    if (!bind_presence) {
+	LM_ERR("can't bind presence\n");
+	return -1;
+    }
+    if (bind_presence(&pres) < 0) {
+	LM_ERR("can't bind pua\n");
+	return -1;
+    }
+
+    pres_add_event = pres.add_event;
+    if (add_event == NULL) {
+	LM_ERR("could not import add_event\n");
+	return -1;
+    }
+    if(profile_add_events() < 0) {
+	LM_ERR("failed to add profile events\n");
+	return -1;		
+    }	
+    
+    return 0;
+}
diff --git a/modules_k/presence_profile/presence_profile.h b/modules_k/presence_profile/presence_profile.h
new file mode 100644
index 0000000..2b17fea
--- /dev/null
+++ b/modules_k/presence_profile/presence_profile.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 M��sz��ros Mih��ly
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ *  2011-09-22  initial version (misi)
+ */
+
+/*!
+ * \file
+ * \brief SIP-router Presence :: ua-profile provisioning support
+ * \ingroup presence
+ * Module: \ref presence
+ */
+
+
+#ifndef _PRES_PROFILE_H_
+#define _PRES_PROFILE_H_
+
+extern add_event_t pres_add_event;
+
+#endif
diff --git a/parser/parse_event.c b/parser/parse_event.c
index 4211da2..87d1c51 100644
--- a/parser/parse_event.c
+++ b/parser/parse_event.c
@@ -54,6 +54,7 @@ static struct {
 	{STR_STATIC_INIT("presence.winfo"),  EVENT_PRESENCE_WINFO},
 	{STR_STATIC_INIT("xcap-change"),     EVENT_XCAP_CHANGE},
 	{STR_STATIC_INIT("sip-profile"),     EVENT_SIP_PROFILE},
+	{STR_STATIC_INIT("ua-profile"),      EVENT_UA_PROFILE},
 	{STR_STATIC_INIT("message-summary"), EVENT_MESSAGE_SUMMARY},
 	{STR_STATIC_INIT("dialog"),          EVENT_DIALOG},
 	/* The following must be the last element in the array */
diff --git a/parser/parse_event.h b/parser/parse_event.h
index ab51b79..62175f3 100644
--- a/parser/parse_event.h
+++ b/parser/parse_event.h
@@ -40,6 +40,7 @@ enum event_type {
 	EVENT_OTHER = 0,
 	EVENT_PRESENCE,
 	EVENT_PRESENCE_WINFO,
+	EVENT_UA_PROFILE,
 	EVENT_SIP_PROFILE,
 	EVENT_XCAP_CHANGE,
 	EVENT_DIALOG,
-- 
1.7.6.3


