reformat all files

This commit is contained in:
Maxim Slipenko 2023-11-29 14:00:52 +03:00
parent f69b73187e
commit 54fa7bb7d0
4 changed files with 31 additions and 29 deletions

View File

@ -10,7 +10,7 @@
#include "yadisk_api_internal.h"
struct memory {
char *response;
char* response;
size_t size;
};
@ -19,13 +19,13 @@ struct data {
};
static size_t cb(void *data, size_t size, size_t nmemb, void *clientp)
static size_t cb(void* data, size_t size, size_t nmemb, void* clientp)
{
size_t realsize = size * nmemb;
struct memory *mem = (struct memory *)clientp;
struct memory* mem = (struct memory*)clientp;
char *ptr = realloc(mem->response, mem->size + realsize + 1);
if(ptr == NULL)
char* ptr = realloc(mem->response, mem->size + realsize + 1);
if (ptr == NULL)
return 0; /* out of memory! */
mem->response = ptr;
@ -36,18 +36,19 @@ static size_t cb(void *data, size_t size, size_t nmemb, void *clientp)
return realsize;
}
char* build_query_string(query_param *params, size_t num_params) {
CURL *curl = curl_easy_init();
char* build_query_string(query_param* params, size_t num_params)
{
CURL* curl = curl_easy_init();
if (!curl) {
return NULL;
}
char *query = NULL;
char* query = NULL;
size_t query_len = 0;
for (size_t i = 0; i < num_params; ++i) {
char *encoded_key = curl_easy_escape(curl, params[i].key, 0);
char *encoded_value = curl_easy_escape(curl, params[i].value, 0);
char* encoded_key = curl_easy_escape(curl, params[i].key, 0);
char* encoded_value = curl_easy_escape(curl, params[i].value, 0);
// Calculate additional space needed: key=value& (including null terminator)
size_t additional_len = strlen(encoded_key) + strlen(encoded_value) + 2;
@ -73,23 +74,24 @@ char* build_query_string(query_param *params, size_t num_params) {
// Function to make an HTTP request using libcurl
int api_http_request(
yadisk_api_client *client,
const char* method,
const char* path,
query_param *params,
size_t num_params,
char** output
) {
CURL *curl;
yadisk_api_client* client,
const char* method,
const char* path,
query_param* params,
size_t num_params,
char** output
)
{
CURL* curl;
CURLcode res;
struct memory chunk = {0};
curl = curl_easy_init();
if(curl) {
if (curl) {
char url[512];
if (num_params) {
char *query_string = build_query_string(params, num_params);
char* query_string = build_query_string(params, num_params);
snprintf(url, sizeof(url), "%s%s?%s", YANDEX_DISK_API_HOST, path, query_string);
free(query_string);
} else {
@ -97,7 +99,7 @@ int api_http_request(
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
// Set the HTTP method
if (strcmp(method, "GET") == 0) {
@ -113,13 +115,13 @@ int api_http_request(
// Set the authorization header
char auth_header[256];
snprintf(auth_header, sizeof(auth_header), "Authorization: OAuth %s", client->token);
struct curl_slist *headers = NULL;
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, auth_header);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// Perform the request
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
free(chunk.response);
curl_easy_cleanup(curl);

View File

@ -14,8 +14,7 @@
const char* created; \
const char* modified;
struct yadisk_resource_item
{
struct yadisk_resource_item {
YADISK_RESOURCE_ITEM_PROPERTIES
};

View File

@ -5,7 +5,8 @@
#include <yadisk.h>
#include <stdio.h>
int main() {
int main()
{
char token[1024];
printf("Enter OAuth token: ");
@ -13,8 +14,8 @@ int main() {
yadisk_init();
yadisk_api_client* client = &(yadisk_api_client){
.token = token
yadisk_api_client* client = &(yadisk_api_client) {
.token = token
};
yadisk_disk_info yadisk_disk_info;