src/modules/sca/sca_event.c
ce6a9ca2
 /*
  * Copyright (C) 2012 Andrew Mortensen
  *
313e77d3
  * This file is part of the sca module for Kamailio, a free SIP server.
ce6a9ca2
  *
  * The sca module 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 sca module is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1e0ba69
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce6a9ca2
  * 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
c1e0ba69
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA. 02110-1301 USA
ce6a9ca2
  */
d694ceba
 #include "sca_common.h"
 
 #include "sca_event.h"
 
c1e0ba69
 str SCA_EVENT_NAME_CALL_INFO = STR_STATIC_INIT("call-info");
 str SCA_EVENT_NAME_LINE_SEIZE = STR_STATIC_INIT("line-seize");
d694ceba
 
c1e0ba69
 int sca_event_from_str(str *event_str)
d694ceba
 {
c1e0ba69
 	int event = SCA_EVENT_TYPE_UNKNOWN;
d694ceba
 
cf3c0132
 	if(event_str == NULL || event_str->s == NULL) {
c1e0ba69
 		return (SCA_EVENT_TYPE_UNKNOWN);
 	}
d694ceba
 
cf3c0132
 	if(STR_EQ(*event_str, SCA_EVENT_NAME_CALL_INFO)) {
c1e0ba69
 		event = SCA_EVENT_TYPE_CALL_INFO;
cf3c0132
 	} else if(STR_EQ(*event_str, SCA_EVENT_NAME_LINE_SEIZE)) {
c1e0ba69
 		event = SCA_EVENT_TYPE_LINE_SEIZE;
 	}
d694ceba
 
c1e0ba69
 	return (event);
d694ceba
 }
 
c1e0ba69
 char *sca_event_name_from_type(int event_type)
d694ceba
 {
cf3c0132
 	switch(event_type) {
 		case SCA_EVENT_TYPE_CALL_INFO:
 			return (SCA_EVENT_NAME_CALL_INFO.s);
d694ceba
 
cf3c0132
 		case SCA_EVENT_TYPE_LINE_SEIZE:
 			return (SCA_EVENT_NAME_LINE_SEIZE.s);
d694ceba
 
cf3c0132
 		default:
 			break;
c1e0ba69
 	}
d694ceba
 
c1e0ba69
 	return ("unknown");
d694ceba
 }
 
c1e0ba69
 int sca_event_append_header_for_type(int event_type, char *hdrbuf, int maxlen)
d694ceba
 {
c1e0ba69
 	int len;
d694ceba
 
c1e0ba69
 	len = snprintf(hdrbuf, maxlen, "Event: %s%s",
 			sca_event_name_from_type(event_type), CRLF);
cf3c0132
 	if(len >= maxlen) {
c1e0ba69
 		LM_ERR("%s Event header too long\n",
 				sca_event_name_from_type(event_type));
 		return (-1);
 	}
d694ceba
 
c1e0ba69
 	return (len);
d694ceba
 }