Skip to content
Snippets Groups Projects
Select Git revision
  • f604d32605c51ba7fa0d8575b384fe20d46731e0
  • devel default
  • master
  • fo
  • jirka/typing
  • fo-base
  • mj/submit-images
  • jk/issue-96
  • jk/issue-196
  • honza/add-contestant
  • honza/mr7
  • honza/mrf
  • honza/mrd
  • honza/mra
  • honza/mr6
  • honza/submit-images
  • honza/kolo-vs-soutez
  • jh-stress-test-wip
  • shorten-schools
19 results

org_score.py

Blame
  • client.c 8.38 KiB
    #define _GNU_SOURCE
    #include <stdio.h>
    #include <stdbool.h>
    #include <stdlib.h>
    #include <string.h>
    #include <curl/curl.h>
    #include <tidy/tidy.h>
    #include <tidy/tidybuffio.h>
    #include <time.h>
    #include "config.h"
    
    struct memory {
    	char *response;
    	size_t size;
    };
    
    struct submit_action {
    	int contest_id;
    	int task_id;
    	char *local_file;
    	char *reported_filename;
    };
    
    static size_t write_callback(void *data, size_t size, size_t nmemb, void *userp) {
    	size_t realsize = size *nmemb;
    	struct memory *mem = (struct memory *)userp;
    
    	char *ptr = realloc(mem->response, mem->size + realsize + 1);
    	if (ptr == NULL)
    		return 0;
    
    	mem->response = ptr;
    	memcpy(&(mem->response[mem->size]), data, realsize);
    	mem->size += realsize;
    	mem->response[mem->size] = 0;
    
    	return realsize;
    }
    
    static void debug_print_cookies(CURL *curl) {
    	CURLcode res;
    	struct curl_slist *cookies;
    	struct curl_slist *nc;
    	int i;
    
    	printf("Cookies, curl knows:\n");
    	res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
    	if (res != CURLE_OK) {
    		fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res));
    		return;
    	}
    	nc = cookies;
    	i = 0;
    	while (nc) {
    		printf("[%d]: %s\n", i, nc->data);
    		nc = nc->next;
    		i++;
    	}
    	if (i == 0) {
    		printf("(none)\n");
    	}
    	curl_slist_free_all(cookies);
    }
    
    
    void setup_curl(CURL *curl,  struct memory *chunk) {
    	chunk->response = NULL;
    	chunk->size = 0;
    	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
    	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // skip cert verification