static char* get_param_value(char* params, const char* param_name)
{
char
*p = NULL,
*l = NULL,
*n = NULL,
*r = NULL,
*buf = NULL;
for(p = params; p && *p; p++)
{
r = NULL;
/* trim left spaces */
for(; *p == ' '; p++);
/* find '=' symbol */
for(n = p; *n && *n != '\n'; n++)
{
if(*n == '=')
{
/* trim right spaces */
for(l = n - 1; *l == ' '; l--);
l++;
/* compare parameter name */
if(l - p != strlen(param_name)) break;
if(strncmp(p, param_name, l - p)) break;
r = n+1;
break;
}
}
/* find EOL */
for(p = n; *p && *p != '\n'; p++);
/* allocate result */
if(r)
{
/* trim right EOL symbols */
while(*p == '\r' || *p == '\n' || *p == '\0') p--;
p++;
/* allocate result */
buf = zbx_malloc(buf, p - r + 1);
memmove(buf, r, p - r);
buf[p - r] = '\0';
break;
}
}
if(buf == NULL)
{
/* allocate result */
buf = zbx_malloc(buf, 1);
*buf = '\0';
}
return buf;
}
阅读(1299) | 评论(0) | 转发(0) |