3
** Copyright (C) 2000-2005 SIA Zabbix
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7
int comms_create_request(char *host, char *key, char *data, char *lastlogsize, char *request,int maxlen)
24
/******************************************************************************
26
* Function: comms_create_request *
28
* Purpose: dinamical xml request generation *
30
* Return value: XML request *
32
* Author: Eugene Grigorjev *
34
* Comments: required free allocated string with function 'zbx_free' *
36
******************************************************************************/
37
char* comms_create_request(
42
unsigned long *timestamp,
44
unsigned short *severity
10
char host_b64[MAX_STRING_LEN];
11
char key_b64[MAX_STRING_LEN];
47
#define ADD_XML_DATA(tag_name, var) \
49
str_base64_encode(var, data_b64, (int)strlen(var)); \
50
request = zbx_strdcatf(request, "<" tag_name ">%s</" tag_name ">", data_b64)
12
52
char data_b64[ZBX_MAX_B64_LEN];
13
char lastlogsize_b64[MAX_STRING_LEN];
15
memset(request,0,maxlen);
16
memset(host_b64,0,sizeof(host_b64));
17
memset(key_b64,0,sizeof(key_b64));
60
/* zabbix_log(LOG_LEVEL_DEBUG, "comms_create_request host [%s] key [%s] data [%s]",host,key,data); */
18
62
memset(data_b64,0,sizeof(data_b64));
19
memset(lastlogsize_b64,0,sizeof(lastlogsize_b64));
21
str_base64_encode(host, host_b64, strlen(host));
22
str_base64_encode(key, key_b64, strlen(key));
23
str_base64_encode(data, data_b64, strlen(data));
26
str_base64_encode(lastlogsize, lastlogsize_b64, strlen(lastlogsize));
29
/* fprintf(stderr, "Data Base64 [%s]\n", data_b64);*/
33
snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data></req>",host_b64,key_b64,data_b64);
37
snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data><lastlogsize>%s</lastlogsize></req>",host_b64,key_b64,data_b64,lastlogsize_b64);
39
/* fprintf(stderr, "Max [%d] Result [%s][%d]\n", maxlen , request, strlen(request));*/
64
request = zbx_dsprintf(NULL,"%s", "<req>");
66
ADD_XML_DATA("host", host);
67
ADD_XML_DATA("key", key);
68
ADD_XML_DATA("data", data);
72
tmp_str = zbx_dsprintf(NULL, "%li", *lastlogsize);
73
ADD_XML_DATA("lastlogsize", tmp_str);
82
tmp_str = zbx_dsprintf(NULL, "%lu", *timestamp);
83
ADD_XML_DATA("timestamp", tmp_str);
86
ADD_XML_DATA("source", source);
88
tmp_str = zbx_dsprintf(NULL, "%u", *severity);
89
ADD_XML_DATA("severity", tmp_str);
93
return zbx_strdcat(request, "</req>");
43
96
int comms_parse_response(char *xml,char *host,char *key, char *data, char *lastlogsize, char *timestamp,
44
97
char *source, char *severity, int maxlen)
99
void *zbx_malloc(size_t size)
153
void *zbx_malloc2(char *filename, int line, void *old, size_t size)
101
155
register int max_attempts;
102
156
void *ptr = NULL;
104
for( max_attempts = 10, size = MAX(size, 1);
158
/* Old pointer must be NULL */
161
zabbix_log(LOG_LEVEL_CRIT,"[file:%s,line:%d] zbx_malloc: allocating already allocated memory. Please report this to ZABBIX developers.",
164
/* Exit if defined DEBUG. Ignore otherwise. */
168
/* zabbix_log(LOG_LEVEL_DEBUG,"In zbx_malloc(size:%d)", size); */
171
max_attempts = 10, size = MAX(size, 1);
105
172
max_attempts > 0 && !ptr;
106
173
ptr = malloc(size),
112
zabbix_log(LOG_LEVEL_CRIT,"out of memory. requested '%i' bytes.", size);
115
/* Program will never reach this point. */
179
zabbix_log(LOG_LEVEL_CRIT,"zbx_malloc: out of memory. requested '%lu' bytes.", size);
182
/* Program will never reach this point. */
186
void *zbx_realloc(void *src, size_t size)
188
register int max_attempts;
193
/* zabbix_log(LOG_LEVEL_DEBUG,"In zbx_realloc(size:%d)", size); */
196
max_attempts = 10, size = MAX(size, 1);
197
max_attempts > 0 && !ptr;
198
ptr = realloc(src, size),
204
zabbix_log(LOG_LEVEL_CRIT,"zbx_realloc: out of memory. requested '%lu' bytes.", size);
207
/* Program will never reach this point. */