--- ../asterisk-1.2.32-org/channels/chan_sip.c 2009-04-02 19:02:18.000000000 +0200
+++ channels/chan_sip.c 2009-07-01 09:21:30.000000000 +0200
@@ -13665,8 +13665,86 @@
return sip_reload(0, 0, NULL);
}
+/*! \brief sip_message: Send SIP notify to peer */
+static int sip_message (int fd, int argc, char *argv[])
+{
+ char *message_body = NULL;
+ int i;
+
+ if (argc < 2)
+ return RESULT_SHOWUSAGE;
+
+ struct sip_pvt *p;
+ struct sip_request req;
+
+ p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY);
+ if (!p)
+ {
+ ast_log(LOG_WARNING, "Unable to build sip pvt data for notify\n");
+ return RESULT_FAILURE;
+ }
+
+ if (create_addr(p, argv[2]))
+ {
+ /* Maybe they're not registered, etc. */
+ sip_destroy(p);
+ ast_cli(fd, "Could not create address for '%s'\n", argv[2]);
+ return RESULT_FAILURE;
+ }
+
+ initreqprep(&req, p, SIP_NOTIFY);
+
+ for (i = 3; i < argc ; ++i)
+ {
+ if (strcmp (argv[i], ".") == 0)
+ {
+ ast_log(LOG_DEBUG, "Body detected\n");
+
+ if (i + 1 < argc)
+ {
+ ast_log(LOG_DEBUG, "Body: %s\n", argv[i + 1]);
+ message_body = argv[i + 1];
+ break;
+ }
+ }
+
+ char *pos = strchr (argv[i], '=');
+ if (pos != NULL)
+ {
+ *pos = '\0';
+ ast_log(LOG_DEBUG, "Header: %s : %s\n", argv[i], pos+1);
+
+ add_header(&req, argv[i], pos+1);
+ }
+ }
+
+ if (message_body != NULL)
+ {
+ add_header_contentLength(&req, strlen(message_body) + 2);
+ add_line(&req, message_body);
+ add_line(&req, "\r\n");
+ }
+ else
+ {
+ add_blank_header(&req);
+ }
+
+ /* Recalculate our side, and recalculate Call ID */
+ if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
+ memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
+ build_via(p, p->via, sizeof(p->via));
+ build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+ ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[1], argv[2]);
+ transmit_sip_request(p, &req);
+ sip_scheddestroy(p, 15000);
+
+ return RESULT_SUCCESS;
+}
+
+
static struct ast_cli_entry my_clis[] = {
{ { "sip", "notify", NULL }, sip_notify, "Send a notify packet to a SIP peer", notify_usage, complete_sipnotify },
+ { { "sip", "message", NULL }, sip_message, "Send a message (notify) packet to a SIP peer", "peer header(s) . body"},
{ { "sip", "show", "objects", NULL }, sip_show_objects, "Show all SIP object allocations", show_objects_usage },
{ { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage },
{ { "sip", "show", "user", NULL }, sip_show_user, "Show details on specific SIP user", show_user_usage, complete_sip_show_user },