1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*
* $Id$
*
* Copyright (c) 2007 iptelorg GmbH
*
* This file is part of sip-router, a free SIP server.
*
* sip-router 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
*
* sip-router 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*!
* \file
* \brief SIP-router auth-identity :: Dynamic strings
* \ingroup auth-identity
* Module: \ref auth-identity
*/
#include <errno.h>
#include "../../parser/parse_from.h"
#include "../../parser/parse_cseq.h"
#include "../../parser/parse_content.h"
#include "../../parser/parse_uri.h"
#include "../../parser/contact/parse_contact.h"
#include "../../data_lump.h"
#include "../../msg_translator.h"
#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) {
LOG(L_ERR, "AUTH_IDENTITY:cpy2dynstr: Not enough memory error\n");
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) {
LOG(L_ERR, "AUTH_IDENTITY:app2dynchr: Not enough memory error\n");
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) {
LOG(L_ERR, "AUTH_IDENTITY:app2dynstr: Not enough memory error\n");
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;
}
|