1
/* $Id: print_util.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJSIP_PRINT_H__
21
#define __PJSIP_PRINT_H__
23
#define copy_advance_check(buf,str) \
25
if ((str).slen >= (endbuf-buf)) return -1; \
26
pj_memcpy(buf, (str).ptr, (str).slen); \
30
#define copy_advance_pair_check(buf,str1,len1,str2) \
33
printed = len1+str2.slen; \
34
if (printed >= (endbuf-buf)) return -1; \
35
pj_memcpy(buf,str1,len1); \
36
pj_memcpy(buf+len1, str2.ptr, str2.slen); \
41
#define copy_advance_pair_quote_check(buf,str1,len1,str2,quotebegin,quoteend) \
44
printed = len1+str2.slen+2; \
45
if (printed >= (endbuf-buf)) return -1; \
46
pj_memcpy(buf,str1,len1); \
47
*(buf+len1)=quotebegin; \
48
pj_memcpy(buf+len1+1, str2.ptr, str2.slen); \
49
*(buf+printed-1) = quoteend; \
54
#define copy_advance_pair_quote(buf,str1,len1,str2,quotebegin,quoteend) \
56
printed = len1+str2.slen+2; \
57
if (printed >= (endbuf-buf)) return -1; \
58
pj_memcpy(buf,str1,len1); \
59
*(buf+len1)=quotebegin; \
60
pj_memcpy(buf+len1+1, str2.ptr, str2.slen); \
61
*(buf+printed-1) = quoteend; \
65
#define copy_advance_pair_escape(buf,str1,len1,str2,unres) \
68
if (len1+str2.slen >= (endbuf-buf)) return -1; \
69
pj_memcpy(buf,str1,len1); \
70
printed=pj_strncpy2_escape(buf+len1,&str2,(endbuf-buf-len1),&unres);\
71
if (printed < 0) return -1; \
72
buf += (printed+len1); \
77
#define copy_advance_no_check(buf,str) \
79
pj_memcpy(buf, (str).ptr, (str).slen); \
83
#define copy_advance_escape(buf,str,unres) \
86
pj_strncpy2_escape(buf, &(str), (endbuf-buf), &(unres)); \
87
if (printed < 0) return -1; \
91
#define copy_advance_pair_no_check(buf,str1,len1,str2) \
93
pj_memcpy(buf,str1,len1); \
94
pj_memcpy(buf+len1, str2.ptr, str2.slen); \
95
buf += len1+str2.slen; \
98
#define copy_advance copy_advance_check
99
#define copy_advance_pair copy_advance_pair_check
101
#define copy_advance_pair_quote_cond(buf,str1,len1,str2,quotebegin,quoteend) \
103
if (str2.slen && *str2.ptr!=quotebegin) \
104
copy_advance_pair_quote(buf,str1,len1,str2,quotebegin,quoteend); \
106
copy_advance_pair(buf,str1,len1,str2); \
110
* Internal type declarations.
112
typedef void* (*pjsip_hdr_clone_fptr)(pj_pool_t *, const void*);
113
typedef int (*pjsip_hdr_print_fptr)(void *hdr, char *buf, pj_size_t len);
115
typedef struct pjsip_hdr_name_info_t
120
} pjsip_hdr_name_info_t;
122
extern const pjsip_hdr_name_info_t pjsip_hdr_names[];
124
PJ_INLINE(void) init_hdr(void *hptr, pjsip_hdr_e htype, void *vptr)
126
pjsip_hdr *hdr = (pjsip_hdr*) hptr;
128
hdr->name.ptr = pjsip_hdr_names[htype].name;
129
hdr->name.slen = pjsip_hdr_names[htype].name_len;
130
if (pjsip_hdr_names[htype].sname) {
131
hdr->sname.ptr = pjsip_hdr_names[htype].sname;
134
hdr->sname = hdr->name;
136
hdr->vptr = (pjsip_hdr_vptr*) vptr;
140
#endif /* __PJSIP_PRINT_H__ */