src/modules/auth_identity/auth_dynstr.c
618649c1
 /*
598bac61
  * This file is part of Kamailio, a free SIP server.
618649c1
  *
598bac61
  * Kamailio is free software; you can redistribute it and/or modify
618649c1
  * 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
  *
598bac61
  * Kamailio is distributed in the hope that it will be useful,
618649c1
  * 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 this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
598bac61
  *
  * Copyright (c) 2007 iptelorg GmbH
  *
618649c1
  */
 
105d0ab0
 /*!
  * \file
1f16abf4
  * \brief Kamailio auth-identity :: Dynamic strings
105d0ab0
  * \ingroup auth-identity
  * Module: \ref auth-identity
  */
 
cd519eda
 #include <errno.h>
 
cf83221d
 #include "../../core/parser/parse_from.h"
 #include "../../core/parser/parse_cseq.h"
 #include "../../core/parser/parse_content.h"
 #include "../../core/parser/parse_uri.h"
 #include "../../core/parser/contact/parse_contact.h"
cd519eda
 
cf83221d
 #include "../../core/data_lump.h"
 #include "../../core/msg_translator.h"
cd519eda
 #include "auth_identity.h"
 
 /*
  * Dynamic string functions
  */
 
 int initdynstr(dynstr *sout, int isize)
 {
 	memset(sout,0,sizeof(*sout));
 	getstr_dynstr(sout).s=pkg_malloc(isize);
 	if (!getstr_dynstr(sout).s) {
 		LOG(L_WARN,
 			"AUTH_IDENTITY:initdynstr: Not enough memory error\n");
 		return -1;
 	}
 	sout->size=isize;
 
 	return 0;
 }
 
 int cpy2dynstr(dynstr *sout, str *s2app)
 {
 	char *stmp;
 	int isize = s2app->len;
 
 	if (isize > sout->size) {
 		stmp=pkg_realloc(sout->sd.s, isize);
 		if (!stmp) {
d534ffe2
 			LOG(L_ERR, "AUTH_IDENTITY:cpy2dynstr: Not enough memory error\n");
cd519eda
 			return -1;
 		}
 		sout->sd.s=stmp;
 		sout->size=isize;
 	}
 
 	memcpy(sout->sd.s,s2app->s,s2app->len);
 	sout->sd.len = isize;
 
 	return 0;
 }
 
 int app2dynchr(dynstr *sout, char capp)
 {
 	char *stmp;
 	int isize = sout->sd.len + 1;
 
 	if (isize > sout->size) {
 		stmp=pkg_realloc(sout->sd.s, isize);
 		if (!stmp) {
d534ffe2
 			LOG(L_ERR, "AUTH_IDENTITY:app2dynchr: Not enough memory error\n");
cd519eda
 			return -1;
 		}
 		sout->sd.s=stmp;
 		sout->size++;
 	}
 
 	sout->sd.s[sout->sd.len]=capp;
 	sout->sd.len++;
 
 	return 0;
 }
 
 int app2dynstr(dynstr *sout, str *s2app)
 {
 	char *stmp;
 	int isize = sout->sd.len + s2app->len;
 
 	if (isize > sout->size) {
 		stmp=pkg_realloc(sout->sd.s, isize);
 		if (!stmp) {
d534ffe2
 			LOG(L_ERR, "AUTH_IDENTITY:app2dynstr: Not enough memory error\n");
cd519eda
 			return -1;
 		}
 		sout->sd.s=stmp;
 		sout->size=isize;
 	}
 
 	memcpy(&sout->sd.s[sout->sd.len],s2app->s,s2app->len);
 	sout->sd.len = isize;
 
 	return 0;
 }