Example #1
0
static int web_perform(DC_ITEM *item, AGENT_RESULT *result, const char *cmd, const char *params)
{
	struct web *opt = NULL;
	int i;

	opt = (struct web *) zbx_calloc(opt, 1, sizeof (struct web));

	if (web_set_key(item, opt, cmd))
		goto failed;

	if (web_set_params_count(result, opt, params))
		goto failed;

	/* web set & validate params */
	for (i = 0; i < opt->params_count; i++) {
		/* result can be set previously by web_set_ip (WEB_ERR_DNS) */
		if (opt->result)
			goto result;

		if (WEB_PARAM_OPT[opt->key_id][i].param_set != NULL)
			if (WEB_PARAM_OPT[opt->key_id][i].param_set(result, opt, params,
								    WEB_PARAM_OPT[opt->key_id][i].param_id))
				goto failed;
	}

	/* web set curl internal struct (WEB_ERR_CURL)*/
	if (web_curl_set(opt))
		goto result;

	/* web perform curl request (WEB_ERR_CURL)*/
	if (web_curl_perform(opt))
		goto result;

	/* web perform key specific check (WEB_ERR[CURL|CONTENT_TYPE|REGEXP])*/
	for (i = 0; i < WEB_KEY_CHECK_COUNT; i++) {
		if (WEB_KEY_CHECK_OPT[opt->key_id][i].key_check != NULL)
			if (WEB_KEY_CHECK_OPT[opt->key_id][i].key_check(opt))
				goto result;
	}

result:
	SET_UI64_RESULT(result, opt->result);
	web_free(opt);
	return SUCCEED;
failed:
	web_free(opt);
	return NOTSUPPORTED;
}
Example #2
0
static void
tr_multi_perform( tr_web * g, int fd, int curl_what )
{
    CURLMcode m;

    dbgmsg( "check_run_count: %d taskCount", g->taskCount );

    /* invoke libcurl's processing */
    do
        m = curl_multi_socket_action( g->multi, fd, curl_what, &g->taskCount );
    while( m == CURLM_CALL_MULTI_SOCKET );

    remove_finished_tasks( g );

    if( g->closing && !g->taskCount )
        web_free( g );
    else
        restart_timer( g );
}