Пример #1
0
void run(void)
{
    memset(etag_last, 0, sizeof (etag_last));

    while (1) { 
        struct http_req * http;

        /* The first time coming if there's no etag is set. */
        if (0 == strcmp(etag_last, "")) {
            http = curl_perform(GIT_EVENT_API_URL, NULL);
        } else {
            /* Other times set the ETag header to check for 304 Notified in the response. */
            struct curl_slist * slist = NULL;
            char reqbuf[256];

            snprintf(reqbuf, 256, "If-None-Match: %s", etag_last);
            slist = curl_slist_append(slist, reqbuf); 
            http = curl_perform(GIT_EVENT_API_URL, slist);
        }

        if (http == NULL || http->body == NULL || http->header == NULL)
            goto SKIP;

        parse_etag(http->header);

        if (!strstr(http->header, "304 Not Modified")) {
            char message[510];
            struct channel_t ** iterator;

            message[0] = 0;

            parse_json_event(http->body, message);
            if (message[0] && plugin->irc->channels_v != NULL) {
                for (iterator = plugin->irc->channels_v; *iterator != NULL; iterator++) {
                    char * channel = (*iterator)->name;
                    char response[512];

                    sprintf(response, "PRIVMSG %s :%s\r\n", channel, message);
                    plugin->send_message(plugin->irc, response);
                }
            }
        } 

        if (http->header != NULL) free(http->header);
        if (http->body != NULL) free(http->body);
        if (http != NULL) free(http);

SKIP:
        debug("I'm polling every %d seconds as per github wants me to.\n", x_rate_limit);
        usleep(x_rate_limit *1000*1000);
    }
}
Пример #2
0
static void curl_thread(uv_work_t *w) {
	luv_curl_t *lc = (luv_curl_t *)w->data;

	if (lc->stat != ERROR)
		curl_perform(lc);

	if (lc->headers)
		curl_slist_free_all(lc->headers);

	if (lc->proxy)
		free(lc->proxy);

	debug("thread ends r=%d", lc->curl_ret);
}
Пример #3
0
static void proc_info_youtube(struct irc_t * irc, struct youtube_t * youtube)
{
    char        url_path[512];
    char        * content;
    char *t;

    t = strstr(irc->request, "v=");
    if (t) t +=2;
    t = strtok(t, " &\r\n\\");

    sprintf(url_path, "http://gdata.youtube.com/feeds/api/videos/%s?alt=json&ver=2", t);

    content = curl_perform(url_path);
    parse_json_youtube(content, youtube);
    free(content);
}
Пример #4
0
void mod_title(struct irc_t * irc, char * reply_msg)
{
    char * content = NULL;
    char * t;

    if (validate_http(irc->request) < 0 )
        return;

    content = curl_perform(irc->request);

    if (!content) return;

    if ( parse_title(reply_msg, content) > 0 ) {
        t = reply_msg;
        while (*t != '\0')
            if (*t++ == '\n')
                t[-1] = ' ';
    }

    free(content);
    return;
}
Пример #5
0
static void test_perform(void **UNUSED(foo)) {
    MANGUSTA_TEST_SETUP;
    MANGUSTA_TEST_START;

    assert_int_equal(mangusta_context_set_request_header_cb(ctx, on_headers_ready), APR_SUCCESS);
    assert_int_equal(mangusta_context_set_request_ready_cb(ctx, on_request_ready), APR_SUCCESS);

    curl_perform(ctx, URL_BASE URL1 "a", CURL_HTTP_VERSION_1_0, "POST");
    curl_perform(ctx, URL_BASE URL1 "b", CURL_HTTP_VERSION_1_1, "POST");
    curl_perform(ctx, URL_BASE URL2 "a", CURL_HTTP_VERSION_1_0, "POST");
    curl_perform(ctx, URL_BASE URL2 "b", CURL_HTTP_VERSION_1_1, "POST");
    /* curl_perform(ctx, URL_BASE URL3 "a", CURL_HTTP_VERSION_1_0, "PUT"); // Chunk upload not supported  */
    curl_perform(ctx, URL_BASE URL3 "b", CURL_HTTP_VERSION_1_1, "PUT");
    must_shutdown = 1;
    curl_perform(ctx, URL_BASE URL4, CURL_HTTP_VERSION_1_1, "DELETE");

    while (mangusta_context_running(ctx) == APR_SUCCESS) {
        apr_sleep(APR_USEC_PER_SEC / 20);
    }

    MANGUSTA_TEST_DISPOSE;

    return;
}