libzrtp  1.2.0
ZRTP VoIP security
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
zrtp_string.h
1 /*
2  * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
3  * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
4  * Contact: http://philzimmermann.com
5  * For licensing and other legal details, see the file zrtp_legal.c.
6  *
7  * Viktor Krykun <v.krikun at zfoneproject.com>
8  */
9 
10 #ifndef __ZRTP_STRING_H__
11 #define __ZRTP_STRING_H__
12 
13 #include "zrtp_config.h"
14 
20 /*============================================================================*/
21 /* Libzrtp Strings */
22 /*============================================================================*/
23 
24 #define ZRTP_STRING8 12
25 #define ZRTP_STRING16 20
26 #define ZRTP_STRING32 36
27 #define ZRTP_STRING64 68
28 #define ZRTP_STRING128 132
29 #define ZRTP_STRING256 260
30 #define ZRTP_STRING1024 1028
31 
32 
33 #if ( ZRTP_PLATFORM != ZP_SYMBIAN )
34 #pragma pack(push, 1)
35 #endif
36 
37 typedef struct zrtp_stringn
38 {
39  uint16_t length;
40  uint16_t max_length;
41  char buffer[0];
43 
44 typedef struct zrtp_string8
45 {
46  uint16_t length;
47  uint16_t max_length;
48  char buffer[ZRTP_STRING8];
50 
51 
52 typedef struct zrtp_string16
53 {
54  uint16_t length;
55  uint16_t max_length;
56  char buffer[ZRTP_STRING16];
58 
59 typedef struct zrtp_string32
60 {
61  uint16_t length;
62  uint16_t max_length;
63  char buffer[ZRTP_STRING32];
65 
66 typedef struct zrtp_string64
67 {
68  uint16_t length;
69  uint16_t max_length;
70  char buffer[ZRTP_STRING64];
72 
73 typedef struct zrtp_string128
74 {
75  uint16_t length;
76  uint16_t max_length;
77  char buffer[ZRTP_STRING128];
79 
80 typedef struct zrtp_string256
81 {
82  uint16_t length;
83  uint16_t max_length;
84  char buffer[ZRTP_STRING256];
86 
87 typedef struct zrtp_string1024
88 {
89  uint16_t length;
90  uint16_t max_length;
91  char buffer[ZRTP_STRING1024];
93 
94 #if ( ZRTP_PLATFORM != ZP_SYMBIAN )
95 #pragma pack(pop)
96 #endif
97 
98 
133 #define ZSTR_GV(pstr) \
134 (zrtp_stringn_t*)((char*)pstr.buffer - sizeof(pstr.max_length) - sizeof(pstr.length))
135 
142 #define ZSTR_GVP(pstr) \
143 (zrtp_stringn_t*)((char*)pstr->buffer - sizeof(pstr->max_length) - sizeof(pstr->length))
144 
150 #define ZSTR_INIT_EMPTY(a) { 0, sizeof(a.buffer) - 1, { 0 }}
151 
156 #define ZSTR_INIT_WITH_CONST_CSTRING(s) {sizeof(s) - 1, 0, s}
157 
164 #define ZSTR_SET_EMPTY(a)\
165 { a.length = 0; a.max_length = sizeof(a.buffer) - 1; a.buffer[0] = 0; }
166 
167 
168 #if defined(__cplusplus)
169 extern "C"
170 {
171 #endif
172 
184 int zrtp_zstrcmp(const zrtp_stringn_t *left, const zrtp_stringn_t *right);
185 
193 void zrtp_zstrcpy(zrtp_stringn_t *dst, const zrtp_stringn_t *src);
194 
204 void zrtp_zstrncpy(zrtp_stringn_t *dst, const zrtp_stringn_t *src, uint16_t size);
205 
211 void zrtp_zstrcpyc(zrtp_stringn_t *dst, const char *src);
212 
213 
220 void zrtp_zstrncpyc(zrtp_stringn_t *dst, const char *src, uint16_t size);
221 
230 void zrtp_zstrcat(zrtp_stringn_t *dst, const zrtp_stringn_t *src);
231 
237 
250 int zrtp_memcmp(const void* s1, const void* s2, uint32_t n);
251 
263 const char* hex2str(const char* bin, int bin_size, char* buff, int buff_size);
264 
275 char *str2hex(const char* buff, int buff_size, char* bin, int bin_size);
276 
277 #if defined(__cplusplus)
278 }
279 #endif
280 
283 #endif /* __ZRTP_STRING_H__ */