[asterisk-commits] mmichelson: branch group/pimp_my_sip r379040 - in /team/group/pimp_my_sip: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 14 10:31:12 CST 2013


Author: mmichelson
Date: Mon Jan 14 10:31:09 2013
New Revision: 379040

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379040
Log:
Add skeleton for res_sip_session.

This is the module that will be used for handling
SIP INVITE sessions. Isn't it exciting?!

Everything is just stubbed out for the moment. Stay
tuned for further updates.


Added:
    team/group/pimp_my_sip/include/asterisk/res_sip_session.h   (with props)
    team/group/pimp_my_sip/res/res_sip_session.c   (with props)

Added: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip_session.h?view=auto&rev=379040
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip_session.h (added)
+++ team/group/pimp_my_sip/include/asterisk/res_sip_session.h Mon Jan 14 10:31:09 2013
@@ -1,0 +1,242 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef _RES_SIP_SESSION_H
+#define _RES_SIP_SESSION_H
+
+/* Forward declarations */
+struct ast_sip_endpoint;
+struct pjsip_inv_session;
+struct ast_channel;
+struct ast_datastore;
+struct ast_datastore_info;
+struct ao2_container;
+struct pjsip_tx_data;
+struct pjsip_rx_data;
+struct ast_party_id;
+struct pjmedia_sdp_media;
+struct pjmedia_sdp_session;
+
+/*!
+ * \brief A structure describing a SIP session
+ */
+struct ast_sip_session {
+    /* The endpoint with which Asterisk is communicating */
+    struct ast_sip_endpoint *endpoint;
+    /* The PJSIP details of the session, which includes the dialog */
+    struct pjsip_inv_session *inv_session;
+    /* The Asterisk channel associated with the session */
+    struct ast_channel *channel;
+    /* Datastores added to the session by supplements to the session */
+	struct ao2_container *datastores;
+};
+
+/*!
+ * \brief A supplement to SIP message processing
+ *
+ * These can be registered by any module in order to add
+ * processing to incoming and outgoing SIP requests and responses
+ */
+struct ast_sip_session_supplement {
+    /*! Method on which to call the callbacks. If NULL, call on all methods */
+    const char *method;
+    /*! Notification that the session has begun */
+    void (*session_begin)(struct ast_sip_session *session);
+    /*! Notification that the session has ended */
+    void (*session_end)(struct ast_sip_session *session);
+    /*!
+     * \brief Called on incoming SIP request
+     * This method can indicate a failure in processing in its return. If there
+     * is a failure, it is required that this method sends a response to the request.
+     */
+    int (*incoming_request)(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
+    /*! Called on an incoming SIP response */
+    void (*incoming_response)(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
+    /*! Called on an outgoing SIP request */
+    void (*outgoing_request)(struct ast_sip_session *session, struct pjsip_tx_data *tdata);
+    /*! Called on an outgoing SIP response */
+    void (*outgoing_response)(struct ast_sip_session *session, struct pjsip_tx_data *tdata);
+};
+
+/*!
+ * \brief A handler for SDPs in SIP sessions
+ *
+ * An SDP handler is registered by a module that is interested in being the
+ * responsible party for specific types of SDP streams.
+ */
+struct ast_sip_session_sdp_handler {
+    /*!
+     * \brief Set session details based on a stream in an incoming SDP offer or answer
+     * \param session The session for which the media is being negotiated
+     * \param stream The stream on which to operate
+     * \retval 0 The stream was not handled by this handler. If there are other registered handlers for this stream type, they will be called.
+     * \retval <0 There was an error encountered. No further operation will take place and the current negotiation will be abandoned.
+     * \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
+     */
+    int (*handle_incoming_sdp_stream_offer)(struct ast_sip_session *session, struct pjmedia_sdp_media *stream);
+    /*!
+     * \brief Create an SDP media stream and add it to the outgoing SDP offer or answer
+     * \param session The session for which media is being added
+     * \param[out] stream The stream to be added to the SDP
+     * \retval 0 This handler has no stream to add. If there are other registered handlers for this stream type, they will be called.
+     * \retval <0 There was an error encountered. No further operation will take place and the current SDP negotiation will be abandoned.
+     * \retval >0 The handler has a stream to be added to the SDP. No further handler of this stream type will be called.
+     */
+    int (*create_outgoing_sdp_stream)(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
+};
+
+/*!
+ * \brief Register an SDP handler
+ *
+ * An SDP handler is responsible for parsing incoming SDPs and ensuring that
+ * Asterisk can cope with the contents. Similarly, the SDP handler will be
+ * responsible for constructing outgoing SDPs.
+ *
+ * Multiple handlers for the same stream type may be registered. They will be
+ * visited in the order they were registered. Handlers will be visited for each
+ * stream type until one claims to have handled the stream.
+ *
+ * \param handler The SDP handler to register
+ * \param stream_type The type of media stream for which to call the handler
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_session_register_sdp_handler(const struct ast_sip_session_sdp_handler *handler, const char *stream_type);
+
+/*!
+ * \brief Unregister an SDP handler
+ *
+ * \param handler The SDP handler to unregister
+ */
+void ast_sip_session_unregister_sdp_handler(const struct ast_sip_session_sdp_handler *handler);
+
+/*!
+ * \brief Register a supplement to SIP session processing
+ *
+ * This allows for someone to insert themselves in the processing of SIP
+ * requests and responses. This, for example could allow for a module to
+ * set channel data based on headers in an incoming message. Similarly,
+ * a module could reject an incoming request if desired.
+ *
+ * \param supplement The supplement to register
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
+
+/*!
+ * \brief Unregister a an supplement to SIP session processing
+ *
+ * \param supplement The supplement to unregister
+ */
+void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
+
+/*!
+ * \brief Wrapper for ast_datastore_alloc()
+ *
+ * There are two major differences between this and ast_datastore_alloc()
+ * 1) This allocates a refcounted object
+ * 2) This will fill in a uid if one is not provided
+ *
+ * \param info Callbacks for datastore
+ * \param uid Identifier for datastore
+ * \retval NULL Failed to allocate datastore
+ * \retval non-NULL Newly allocated datastore
+ */
+struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid);
+
+/*!
+ * \brief Add a datastore to a SIP session
+ *
+ * Note that SIP uses reference counted datastores. The datastore passed into this function
+ * must have been allocated using ao2_alloc() or there will be serious problems.
+ *
+ * \param session The session to add the datastore to
+ * \param cookie The datastore to be added to the session
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore);
+
+/*!
+ * \brief Retrieve a session datastore
+ *
+ * The datastore retrieved will have its reference count incremented. When the caller is done
+ * with the datastore, the reference counted needs to be decremented using ao2_ref().
+ *
+ * \param session The session from which to retrieve the datastore
+ * \param name The name of the datastore to retrieve
+ * \retval NULL Failed to find the specified cookie
+ * \retval non-NULL The specified cookie
+ */
+struct ast_datastore *ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name);
+
+/*!
+ * \brief Remove a session datastore from the session
+ *
+ * This operation may cause the datastore's free() callback to be called if the reference
+ * count reaches zero.
+ *
+ * \param session The session to remove the cookie from
+ * \param name The name of the cookie to remove
+ * \retval 0 Successfully removed the cookie
+ * \retval -1 Failed to remove the cookie
+ */
+int ast_sip_session_remove_datastore(struct ast_sip_session *session, const char *name);
+
+/*!
+ * \brief Retrieve identifying information from an incoming request
+ *
+ * This will retrieve identifying information and place it in the
+ * id parameter. The caller of the function can then apply this to
+ * caller ID, connected line, or whatever else may be proper.
+ *
+ * \param rdata The incoming request or response
+ * \param[out] id The collected identity information
+ * \retval 0 Successfully found identifying information
+ * \retval -1 Identifying information could not be found
+ */
+int ast_sip_session_get_identity(struct pjsip_rx_data *rdata, struct ast_party_id *id);
+
+/*!
+ * \brief Send a reinvite on a session
+ *
+ * This method will inspect the session in order to construct an appropriate
+ * reinvite. As with any outgoing request in res_sip_session, this will
+ * call into registered supplements in case they wish to add anything.
+ * 
+ * \param session The session on which the reinvite will be sent
+ * \param response_cb Optional callback that can be called when the reinvite response is received. The callback is identical in nature to the incoming_response() callback for session supplements.
+ * \retval 0 Successfully sent reinvite
+ * \retval -1 Failure to send reinvite
+ */
+int ast_sip_session_send_reinvite(struct ast_sip_session *session, int (*response_cb)(struct ast_sip_session *session, struct pjsip_rx_data *rdata));
+
+/*!
+ * \brief Send a SIP response
+ *
+ * This will send a SIP response to the request specified in rdata. This will
+ * call into any registered supplements' outgoing_response callback.
+ *
+ * \param session The session to which the current transaction belongs
+ * \param response_code The response code to send for this response
+ * \param rdata The response to which the response is being sent
+ */
+int ast_sip_session_send_response(struct ast_sip_session *session, int response_code, struct pjsip_rx_data *rdata);
+
+#endif /* _RES_SIP_SESSION_H */

Propchange: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=auto&rev=379040
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (added)
+++ team/group/pimp_my_sip/res/res_sip_session.c Mon Jan 14 10:31:09 2013
@@ -1,0 +1,106 @@
+/*
+* Asterisk -- An open source telephony toolkit.
+*
+* Copyright (C) 2013, Digium, Inc.
+*
+* Mark Michelson <mmichelson at digium.com>
+*
+* See http://www.asterisk.org for more information about
+* the Asterisk project. Please do not directly contact
+* any of the maintainers of this project for assistance;
+* the project provides a web site, mailing lists and IRC
+* channels for your use.
+*
+* This program is free software, distributed under the terms of
+* the GNU General Public License Version 2. See the LICENSE file
+* at the top of the source tree.
+*/
+
+#include "asterisk.h"
+
+#include "asterisk/res_sip_session.h"
+#include "asterisk/datastore.h"
+#include "asterisk/module.h"
+#include "asterisk/logger.h"
+
+int ast_sip_session_register_sdp_handler(const struct ast_sip_session_sdp_handler *handler, const char *stream_type)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+void ast_sip_session_unregister_sdp_handler(const struct ast_sip_session_sdp_handler *handler)
+{
+	/* XXX STUB */
+}
+
+int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
+{
+	/* XXX STUB */
+}
+
+struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
+{
+	/* XXX STUB */
+	return NULL;
+}
+
+int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+struct ast_datastore *ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
+{
+	/* XXX STUB */
+	return NULL;
+}
+
+int ast_sip_session_remove_datastore(struct ast_sip_session *session, const char *name)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+int ast_sip_session_get_identity(struct pjsip_rx_data *rdata, struct ast_party_id *id)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+int ast_sip_session_send_reinvite(struct ast_sip_session *session, int (*response_cb)(struct ast_sip_session *session, struct pjsip_rx_data *rdata))
+{
+	/* XXX STUB */
+	return 0;
+}
+
+int ast_sip_session_send_response(struct ast_sip_session *session, int response_code, struct pjsip_rx_data *rdata)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+static int load_module(void)
+{
+	/* XXX STUB */
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	/* XXX STUB */
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "SIP Session resource",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_APP_DEPEND,
+	       );

Propchange: team/group/pimp_my_sip/res/res_sip_session.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/pimp_my_sip/res/res_sip_session.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/pimp_my_sip/res/res_sip_session.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list