[asterisk-commits] mmichelson: branch group/pimp_my_sip r378839 - in /team/group/pimp_my_sip: in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 9 16:36:41 CST 2013
Author: mmichelson
Date: Wed Jan 9 16:36:37 2013
New Revision: 378839
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378839
Log:
Start filling in information on ast_sip_send_request()
I had to modify the method by adding an endpoint because I realized
that for out-of-dialog requests, we did not specify where to send the
request.
The out-of-dialog request-sending method is a stub at the moment since
we haven't defined the ast_sip_endpoint method. Once it's defined, we
can fill in the details and send the request as desired.
Modified:
team/group/pimp_my_sip/include/asterisk/res_sip.h
team/group/pimp_my_sip/res/res_sip.c
Modified: team/group/pimp_my_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip.h?view=diff&rev=378839&r1=378838&r2=378839
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip.h Wed Jan 9 16:36:37 2013
@@ -247,14 +247,20 @@
* Its typical use would be to send one-off messages such as an out of dialog
* SIP MESSAGE.
*
+ * The request can either be sent in- or out-of-dialog. If sent in-dialog, the
+ * dlg parameter MUST be present. If sent out-of-dialog the endpoint parameter
+ * MUST be present. If both are present, then we will assume that the message
+ * is to be sent in-dialog.
+ *
* \param method The method of the SIP request to send
* \param body The message body for the SIP request
- * \dlg Optional. If specified, the dialog on which to send the message. Otherwise, the message
- * will be sent out of dialog.
- * \retval 0 Success
- * \retval -1 Failure
- */
-int ast_sip_send_request(const char *method, const char *body, struct pjsip_dialog *dlg);
+ * \dlg Optional. If specified, the dialog on which to send the message.
+ * \endpoint Optional. If specified, the request will be sent out-of-dialog to the endpoint.
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_send_request(const char *method, const char *body,
+ struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
/*!
* \brief Determine if an incoming request requires authentication
Modified: team/group/pimp_my_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.c?view=diff&rev=378839&r1=378838&r2=378839
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Wed Jan 9 16:36:37 2013
@@ -20,6 +20,8 @@
#undef bzero
#define bzero bzero
#include "pjsip.h"
+/* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */
+#include "pjsip_simple.h"
#include "pjlib.h"
#include "asterisk/res_sip.h"
@@ -192,10 +194,92 @@
return endpoint;
}
-int ast_sip_send_request(const char *method, const char *body, struct pjsip_dialog *dlg)
-{
- /* XXX Stub */
- return 0;
+/* PJSIP doesn't know about the INFO method, so we have to define it ourselves */
+const pjsip_method pjsip_info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} };
+
+static struct {
+ const char *method;
+ const pjsip_method *pmethod;
+} methods [] = {
+ { "INVITE", &pjsip_invite_method },
+ { "CANCEL", &pjsip_cancel_method },
+ { "ACK", &pjsip_ack_method },
+ { "BYE", &pjsip_bye_method },
+ { "REGISTER", &pjsip_register_method },
+ { "OPTIONS", &pjsip_options_method },
+ { "SUBSCRIBE", &pjsip_subscribe_method },
+ { "NOTIFY", &pjsip_notify_method },
+ { "PUBLISH", &pjsip_publish_method },
+ { "INFO", &pjsip_publish_method },
+};
+
+static const pjsip_method *get_pjsip_method(const char *method)
+{
+ int i;
+ for (i = 0; i < ARRAY_LEN(methods); ++i) {
+ if (!strcmp(method, methods[i].method)) {
+ return methods[i].pmethod;
+ }
+ }
+ return NULL;
+}
+
+static int send_in_dialog_request(const pjsip_method *method, const char *body, struct pjsip_dialog *dlg)
+{
+ pj_status_t status;
+ pjsip_tx_data *tdata;
+
+ status = pjsip_dlg_create_request(dlg, method, -1, &tdata);
+ if (status != PJ_SUCCESS) {
+ ast_log(LOG_WARNING, "Unable to create in-dialog request.\n");
+ return -1;
+ }
+
+ if (!ast_strlen_zero(body)) {
+ /* XXX This requires a bit more thought. We may need to change the body argument
+ * to a pjsip_msg_body or require a type/subtype argument
+ */
+ }
+
+ status = pjsip_dlg_send_request(dlg, tdata, -1, NULL);
+ if (status != PJ_SUCCESS) {
+ ast_log(LOG_WARNING, "Unable to send in-dialog request.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int send_out_of_dialog_request(const pjsip_method *method, const char *body, struct ast_sip_endpoint *endpoint)
+{
+ /*XXX Stub
+ *
+ * We need to get the destination from the endpoint and then call
+ * pjsip_endpt_create_request to create the request.
+ *
+ * We can then add the body as necessary and transmit with
+ * pjsip_endpt_send_request_stateless(). The end.
+ *
+ * It's hard to really get started though without an ast_sip_endpoint
+ * structure to work with
+ */
+ return 0;
+}
+
+int ast_sip_send_request(const char *method, const char *body, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
+{
+ const pjsip_method *pmethod = get_pjsip_method(method);
+
+ if (!pmethod) {
+ ast_log(LOG_WARNING, "Unknown method '%s'. Cannot send request\n", method);
+ return -1;
+ }
+
+ if (dlg) {
+ return send_in_dialog_request(pmethod, body, dlg);
+ } else {
+ return send_out_of_dialog_request(pmethod, body, endpoint);
+ }
}
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
More information about the asterisk-commits
mailing list