auth_dynstr.c

Go to the documentation of this file.
00001 /*
00002  * $Id$ 
00003  *
00004  * Copyright (c) 2007 iptelorg GmbH
00005  *
00006  * This file is part of sip-router, a free SIP server.
00007  *
00008  * sip-router is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * sip-router is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00030 #include <errno.h>
00031 
00032 #include "../../parser/parse_from.h"
00033 #include "../../parser/parse_cseq.h"
00034 #include "../../parser/parse_content.h"
00035 #include "../../parser/parse_uri.h"
00036 #include "../../parser/contact/parse_contact.h"
00037 
00038 #include "../../data_lump.h"
00039 #include "../../msg_translator.h"
00040 #include "auth_identity.h"
00041 
00042 /*
00043  * Dynamic string functions
00044  */
00045 
00046 int initdynstr(dynstr *sout, int isize)
00047 {
00048         memset(sout,0,sizeof(*sout));
00049         getstr_dynstr(sout).s=pkg_malloc(isize);
00050         if (!getstr_dynstr(sout).s) {
00051                 LOG(L_WARN,
00052                         "AUTH_IDENTITY:initdynstr: Not enough memory error\n");
00053                 return -1;
00054         }
00055         sout->size=isize;
00056 
00057         return 0;
00058 }
00059 
00060 int cpy2dynstr(dynstr *sout, str *s2app)
00061 {
00062         char *stmp;
00063         int isize = s2app->len;
00064 
00065         if (isize > sout->size) {
00066                 stmp=pkg_realloc(sout->sd.s, isize);
00067                 if (!stmp) {
00068                         LOG(L_ERR, "AUTH_IDENTITY:cpy2dynstr: Not enough memory error\n");
00069                         return -1;
00070                 }
00071                 sout->sd.s=stmp;
00072                 sout->size=isize;
00073         }
00074 
00075         memcpy(sout->sd.s,s2app->s,s2app->len);
00076         sout->sd.len = isize;
00077 
00078         return 0;
00079 }
00080 
00081 int app2dynchr(dynstr *sout, char capp)
00082 {
00083         char *stmp;
00084         int isize = sout->sd.len + 1;
00085 
00086         if (isize > sout->size) {
00087                 stmp=pkg_realloc(sout->sd.s, isize);
00088                 if (!stmp) {
00089                         LOG(L_ERR, "AUTH_IDENTITY:app2dynchr: Not enough memory error\n");
00090                         return -1;
00091                 }
00092                 sout->sd.s=stmp;
00093                 sout->size++;
00094         }
00095 
00096         sout->sd.s[sout->sd.len]=capp;
00097         sout->sd.len++;
00098 
00099         return 0;
00100 }
00101 
00102 int app2dynstr(dynstr *sout, str *s2app)
00103 {
00104         char *stmp;
00105         int isize = sout->sd.len + s2app->len;
00106 
00107         if (isize > sout->size) {
00108                 stmp=pkg_realloc(sout->sd.s, isize);
00109                 if (!stmp) {
00110                         LOG(L_ERR, "AUTH_IDENTITY:app2dynstr: Not enough memory error\n");
00111                         return -1;
00112                 }
00113                 sout->sd.s=stmp;
00114                 sout->size=isize;
00115         }
00116 
00117         memcpy(&sout->sd.s[sout->sd.len],s2app->s,s2app->len);
00118         sout->sd.len = isize;
00119 
00120         return 0;
00121 }