diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-04-14 05:55:37 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-04-14 05:55:37 +0000 |
| commit | 5ac1783eabb170049375d6cebd909c10a6523a73 (patch) | |
| tree | 4b27eec49bce906d83911e64ff173171cc6bc979 /src/libs/zbxsysinfo/common/http.c | |
| parent | eb60de08877fe0e6f42e54949bb332e02caf86c1 (diff) | |
| download | zabbix-5ac1783eabb170049375d6cebd909c10a6523a73.tar.gz zabbix-5ac1783eabb170049375d6cebd909c10a6523a73.tar.xz zabbix-5ac1783eabb170049375d6cebd909c10a6523a73.zip | |
- new comms protocol for ZABBIX agents
git-svn-id: svn://svn.zabbix.com/trunk@4001 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo/common/http.c')
| -rw-r--r-- | src/libs/zbxsysinfo/common/http.c | 91 |
1 files changed, 33 insertions, 58 deletions
diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c index 19fae063..6fd170b7 100644 --- a/src/libs/zbxsysinfo/common/http.c +++ b/src/libs/zbxsysinfo/common/http.c @@ -21,92 +21,69 @@ #include "sysinfo.h" #include "log.h" -#include "zbxsock.h" +#include "comms.h" #include "cfg.h" #include "http.h" -static int get_http_page(char *hostname, char *param, unsigned short port, char *buffer, int max_buf_len) +#define ZABBIX_MAX_WEBPAGE_SIZE 1*1024*1024 + +static int get_http_page(char *host, char *param, unsigned short port, char *buffer, int max_buf_len) { - register int i = 0; - char request[MAX_STRING_LEN]; + char + *buf, + request[MAX_STRING_LEN]; - ZBX_SOCKET s; - ZBX_SOCKADDR servaddr_in; - int - n, - total, - ret = SYSINFO_RET_FAIL; - - struct hostent *hp; + zbx_sock_t s; - if(NULL == (hp = zbx_gethost(hostname)) ) - { - return SYSINFO_RET_FAIL; - } + int ret; - memset(&servaddr_in, 0, sizeof(ZBX_SOCKADDR)); + assert(buffer); - servaddr_in.sin_family = AF_INET; - servaddr_in.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; - servaddr_in.sin_port = htons(port); - - - if(INVALID_SOCKET == (s = (ZBX_SOCKET)socket(AF_INET,SOCK_STREAM,0))) + if( SUCCEED == (ret = zbx_tcp_connect(&s, host, port)) ) { - zabbix_log( LOG_LEVEL_DEBUG, "get_http_page - Error in socket() [%s:%u] [%s]", hostname, port, strerror_from_system(errno)); - return SYSINFO_RET_FAIL; - } + zbx_snprintf(request, sizeof(request), "GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, host); - if(SOCKET_ERROR == connect(s,(struct sockaddr *)&servaddr_in,sizeof(ZBX_SOCKADDR))) - { - zabbix_log( LOG_LEVEL_WARNING, "get_http_page - Error in connect() [%s:%u] [%s]",hostname, port, strerror_from_system(errno)); - zbx_sock_close(s); - return SYSINFO_RET_FAIL; - } + if( SUCCEED == (ret = zbx_tcp_send_raw(&s, request)) ) + { + if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) ) + { + zbx_rtrim(buf, "\n\r\0"); - zbx_snprintf(request, sizeof(request), "GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname); + zbx_snprintf(buffer, max_buf_len, buf); + } + } + } + zbx_tcp_close(&s); - if(SOCKET_ERROR == zbx_sock_write(s, (void *)request, (int)strlen(request))) + if( FAIL == ret ) { - zabbix_log( LOG_LEVEL_DEBUG, "get_http_page - Error during sending [%s:%u] [%s]",hostname, port, strerror_from_system(errno)); - zbx_sock_close(s); + zabbix_log(LOG_LEVEL_DEBUG, "HTTP get error: %s", zbx_tcp_strerror()); return SYSINFO_RET_FAIL; } - - memset(buffer, 0, max_buf_len); - - for(total=0; (n = zbx_sock_read(s, buffer+total, max_buf_len-1-total, CONFIG_TIMEOUT)) > 0; total+=n); - - for(i=(int)strlen(buffer); i>0 && (buffer[i] == '\n' || buffer[i] == '\r' || buffer[i] == '\0'); buffer[i--] = '\0'); - - ret = SYSINFO_RET_OK; - - zbx_sock_close(s); - return ret; + return SYSINFO_RET_OK; } int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { -#define ZABBIX_MAX_WEBPAGE_SIZE 100*1024 char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[MAX_STRING_LEN]; char *buffer; - assert(result); + assert(result); - init_result(result); - - if(num_param(param) > 3) - { - return SYSINFO_RET_FAIL; - } + init_result(result); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } if(get_param(param, 1, hostname, MAX_STRING_LEN) != 0) { - return SYSINFO_RET_FAIL; + return SYSINFO_RET_FAIL; } if(get_param(param, 2, path, MAX_STRING_LEN) != 0) @@ -140,7 +117,6 @@ int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESUL int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { -#define ZABBIX_MAX_WEBPAGE_SIZE 100*1024 char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[MAX_STRING_LEN]; @@ -196,7 +172,6 @@ int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESU int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { -#define ZABBIX_MAX_WEBPAGE_SIZE 100*1024 char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[MAX_STRING_LEN]; |
