#include #include #include #include #include "utils.h" static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; MemoryStruct *mem = (MemoryStruct *)userp; char *ptr = realloc(mem->memory, mem->size + realsize + 1); if(!ptr) { /* out of memory! */ printf("not enough memory (realloc returned NULL)\n"); return 0; } mem->memory = ptr; memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; return realsize; } char* perform_http_post(const char *url, struct curl_slist *headers, const char *json_body) { CURL *curl; CURLcode res; MemoryStruct chunk; chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_body); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); free(chunk.memory); chunk.memory = NULL; } curl_easy_cleanup(curl); } curl_global_cleanup(); return chunk.memory; } // FIX APPLIED: Added 'const char *app_path' argument to match utils.h (Line 59) int get_git_repo_info(const char *app_path, char **owner, char **repo) { FILE *fp; char line[256]; char *url = NULL; char *full_repo = NULL; fp = fopen("../.git/config", "r"); if (fp == NULL) { return 0; } while (fgets(line, sizeof(line), fp)) { if (strstr(line, "[remote \"origin\"]")) { while (fgets(line, sizeof(line), fp)) { if (strstr(line, "url =")) { url = strdup(line + 7); // trim whitespace url[strcspn(url, " \t\r\n")] = 0; break; } } break; } } fclose(fp); if (url == NULL) { return 0; } // Find the last ':' or '/' char *last_colon = strrchr(url, ':'); char *last_slash = strrchr(url, '/'); char *start = last_colon > last_slash ? last_colon : last_slash; if (start == NULL) { free(url); return 0; } start++; full_repo = strdup(start); free(url); // remove .git from repo name char *dot_git = strstr(full_repo, ".git"); if (dot_git) { *dot_git = '\0'; } // split owner and repo char *slash = strchr(full_repo, '/'); if (slash == NULL) { free(full_repo); return 0; } *repo = strdup(slash + 1); *slash = '\0'; *owner = strdup(full_repo); free(full_repo); return 1; }