📄 plugin.c
字号:
/* The NOTIFY plugin is a GPL plugin for partysip. Copyright (C) 2002 2003 Aymeric MOIZARD - <jack@atosc.org> The NOTIFY plugin 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. The NOTIFY plugin 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 Foobar; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <partysip/partysip.h>#include "plugin.h"#include <osipparser2/osip_port.h>#include <osipparser2/osip_message.h>#include <ppl/ppl_md5.h>#include <sql_module.h>plugin_ctx_t *plugin_context = NULL;extern psp_plugin_t PPL_DECLARE_DATA mysqldb_notify_plugin;extern char name_config[50];intplugin_ctx_init (){ int i; plugin_context = (plugin_ctx_t *) malloc (sizeof (plugin_ctx_t)); if (plugin_context == NULL) return -1; /* my_thread_init(); */ /* do I need that? (only one thread access SQL elements. */ memset(plugin_context, '\0', sizeof(plugin_context)); i = module_notify_initialize(); if (i==0) return 0; plugin_ctx_free(); plugin_context = NULL; return -1;}voidplugin_ctx_free (){ /* my_thread_end(); */ if (plugin_context==NULL) return; if (plugin_context->connected==1) mysql_close(&(plugin_context->mysql_conn)); plugin_context->connected = 0; free (plugin_context); plugin_context = NULL;}intcb_plugin_catch_2xxanswer (psp_request_t * psp_req, osip_message_t * response) /* HOOK MIDDLE */{ osip_message_t *request; osip_header_t *event; osip_generic_param_t *tag_to; subscription_t sub; publication_t pub; int i; int auth=0; request = psp_request_get_request(psp_req); if (!MSG_IS_SUBSCRIBE (request) && !MSG_IS_PUBLISH (request) ) { /* bug?? */ psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } if (0 != psp_core_is_responsible_for_this_domain (request-> req_uri)) { /* this module only handle SUBSCRIBE to local users */ psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "%s plugin: build NOTIFY for SUBSCRIBE or PUBLISH!\n", PLUGIN_NAME)); osip_message_header_get_byname(response, "event", 0, &event); if (event==NULL || event->hvalue==NULL) { /* serach for compact form of Event header: "o" */ osip_message_header_get_byname(response, "o", 0, &event); } if (event==NULL || event->hvalue==NULL) osip_message_header_get_byname(request, "event", 0, &event); if (event==NULL || event->hvalue==NULL) osip_message_header_get_byname(request, "o", 0, &event); if (event==NULL || event->hvalue==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "%s plugin: missing event header in SUBSCRIBE or PUBLISH!\n", PLUGIN_NAME)); psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } memset(&pub, '\0', sizeof(publication_t)); snprintf(pub.username, 64, "%s", request->req_uri->username); snprintf(pub.domain, 128, "%s", request->req_uri->host); i = module_notify_get_publication(&pub, event->hvalue); if (i!=0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "%s plugin: no available publication for user!\n", PLUGIN_NAME)); } if (MSG_IS_SUBSCRIBE (request)) { osip_from_param_get_byname (response->to, "tag", &tag_to); if (tag_to==NULL || tag_to->gvalue==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "%s plugin: missing tag in to header of SUBSCRIBE!\n", PLUGIN_NAME)); psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } memset(&sub ,0 , sizeof(subscription_t)); i = module_notify_get_notify_template(tag_to->gvalue, event->hvalue, &sub); if (i!=0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "%s plugin: failed to get notify template!\n", PLUGIN_NAME)); psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "%s plugin: notify template: %s\n", PLUGIN_NAME, sub.notify_template)); /* TODO: look for user authorization */ /* */ auth=1; if (auth==0) { build_notify(&sub, NULL); } else { build_notify(&sub, &pub); } return 0; } else /* PUBLISH request */ { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "%s plugin: must send all NOTIFYs for all sub!\n", PLUGIN_NAME)); /* get nofify info from user/domain informations */ i = module_notify_send_all_notification(&pub, event->hvalue); if (i!=0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "%s plugin: no available publication for user!\n", PLUGIN_NAME)); psp_request_set_state (psp_req, PSP_CONTINUE); return 0; } } psp_request_set_state (psp_req, PSP_CONTINUE); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -