Compare commits
	
		
			5 Commits
		
	
	
		
			2ee2c8ce27
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5bc1c8de68 | |||
| 7efbd654b7 | |||
| db89e0e129 | |||
| b0cdcabe1a | |||
| a8ba784397 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | ||||
| /.idea/ | ||||
| /cmake-build-debug/ | ||||
| /doc/ | ||||
| @@ -1,6 +1,8 @@ | ||||
| cmake_minimum_required(VERSION 3.5) | ||||
| project(YaDisk) | ||||
|  | ||||
| set(CMAKE_C_STANDARD 99) | ||||
|  | ||||
| set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) | ||||
| find_package(CURL REQUIRED) | ||||
| find_package(JsonC REQUIRED) | ||||
| @@ -31,11 +33,10 @@ target_link_libraries(yadisk | ||||
| target_include_directories( | ||||
|         test-app PRIVATE | ||||
|         "${CMAKE_SOURCE_DIR}/src" | ||||
|         ${NEON_INCLUDE_DIR} | ||||
|         ${CURL_INCLUDE_DIR} | ||||
|         ${JSON_C_INCLUDE_DIR} | ||||
| ) | ||||
| target_link_libraries( | ||||
|         test-app | ||||
|         yadisk | ||||
| ) | ||||
| ) | ||||
|   | ||||
							
								
								
									
										22
									
								
								src/yadisk.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/yadisk.h
									
									
									
									
									
								
							| @@ -1,7 +1,21 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
|  | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
| #ifndef YADISK_YADISK_H | ||||
| #define YADISK_YADISK_H | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,23 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| @@ -97,6 +114,7 @@ int api_http_request( | ||||
|         } else { | ||||
|             snprintf(url, sizeof(url), "%s%s", YANDEX_DISK_API_HOST, path); | ||||
|         } | ||||
|         printf("%s\n", url); | ||||
|         curl_easy_setopt(curl, CURLOPT_URL, url); | ||||
|         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb); | ||||
|         curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk); | ||||
|   | ||||
| @@ -1,6 +1,23 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #ifndef YADISK_YADISK_API_INTERNAL_H | ||||
| #define YADISK_YADISK_API_INTERNAL_H | ||||
| @@ -24,12 +41,13 @@ int api_http_request(yadisk_api_client* client, | ||||
|         return YADISK_FAILED_PARSE_JSON; \ | ||||
|     } | ||||
|  | ||||
| #define __DANGER_GET_JSON_OBJECT(root, key)          \ | ||||
|     json_object* obj = NULL;                         \ | ||||
|     if (!json_object_object_get_ex(root, key, &obj)){\ | ||||
|         json_object_put(root);                       \ | ||||
|         THROW_PARSE_JSON_ERROR                       \ | ||||
|     }                                                \ | ||||
| #define __DANGER_GET_JSON_OBJECT(root, key)           \ | ||||
|     json_object* obj = NULL;                          \ | ||||
|     if (!json_object_object_get_ex(root, key, &obj)){ \ | ||||
|     } | ||||
|  | ||||
| // json_object_put(root); | ||||
| // THROW_PARSE_JSON_ERROR | ||||
|  | ||||
| #define GET_JSON_STRING(root, key, v) {              \ | ||||
|         __DANGER_GET_JSON_OBJECT(root, key)              \ | ||||
|   | ||||
| @@ -1,14 +1,44 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #include "yadisk_get_disk.h" | ||||
| #include "yadisk_api_internal.h" | ||||
|  | ||||
| yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info) | ||||
| yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_get_disk_params* params, yadisk_disk_info* info) | ||||
| { | ||||
|     query_param* qparams = NULL; | ||||
|     int num_params = 0; | ||||
|     const int max_params = 1; | ||||
|  | ||||
|     if (params != NULL) { | ||||
|         qparams = malloc(max_params * sizeof(query_param)); | ||||
|         if (params->fields != NULL) { | ||||
|             qparams[num_params].key = "fields"; | ||||
|             qparams[num_params].value = strdup(params->fields); | ||||
|             num_params++; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     char* output = NULL; | ||||
|     int error = api_http_request(client, "GET", "/v1/disk", NULL, 0, &output); | ||||
|     int error = api_http_request(client, "GET", "/v1/disk", qparams, num_params, &output); | ||||
|     if (error) { | ||||
|         return YADISK_FAILED_HTTP_REQUEST; | ||||
|     } | ||||
| @@ -22,6 +52,46 @@ yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info) | ||||
|     GET_JSON_STRING(root, "reg_time", &(info->reg_time)); | ||||
|     GET_JSON_BOOL(root, "is_paid", &(info->is_paid)); | ||||
|  | ||||
|     json_object *user_object; | ||||
|     if (!json_object_object_get_ex(root, "user", &user_object)) { | ||||
|         // THROW_PARSE_JSON_ERROR | ||||
|     } | ||||
|  | ||||
|     if (user_object) { | ||||
|         GET_JSON_STRING(user_object, "reg_time", &(info->user.reg_time)); | ||||
|         GET_JSON_STRING(user_object, "display_name", &(info->user.display_name)); | ||||
|         GET_JSON_STRING(user_object, "uid", &(info->user.uid)); | ||||
|         GET_JSON_STRING(user_object, "country", &(info->user.country)); | ||||
|         GET_JSON_BOOL(user_object, "is_child", &(info->user.is_child)); | ||||
|         GET_JSON_STRING(user_object, "login", &(info->user.login)); | ||||
|     } | ||||
|  | ||||
|     json_object *system_folders; | ||||
|     if (!json_object_object_get_ex(root, "system_folders", &system_folders)) { | ||||
|         // THROW_PARSE_JSON_ERROR | ||||
|     } | ||||
|  | ||||
|     if (system_folders) { | ||||
|         GET_JSON_STRING(system_folders, "odnoklassniki", &(info->system_folders.odnoklassniki)); | ||||
|         GET_JSON_STRING(system_folders, "google", &(info->system_folders.google)); | ||||
|         GET_JSON_STRING(system_folders, "instagram", &(info->system_folders.instagram)); | ||||
|         GET_JSON_STRING(system_folders, "vkontakte", &(info->system_folders.vkontakte)); | ||||
|         GET_JSON_STRING(system_folders, "attach", &(info->system_folders.attach)); | ||||
|         GET_JSON_STRING(system_folders, "mailru", &(info->system_folders.mailru)); | ||||
|         GET_JSON_STRING(system_folders, "downloads", &(info->system_folders.downloads)); | ||||
|         GET_JSON_STRING(system_folders, "applications", &(info->system_folders.applications)); | ||||
|         GET_JSON_STRING(system_folders, "facebook", &(info->system_folders.facebook)); | ||||
|         GET_JSON_STRING(system_folders, "social", &(info->system_folders.social)); | ||||
|         GET_JSON_STRING(system_folders, "messenger", &(info->system_folders.messenger)); | ||||
|         GET_JSON_STRING(system_folders, "calendar", &(info->system_folders.calendar)); | ||||
|         GET_JSON_STRING(system_folders, "photostream", &(info->system_folders.photostream)); | ||||
|         GET_JSON_STRING(system_folders, "screenshots", &(info->system_folders.screenshots)); | ||||
|         GET_JSON_STRING(system_folders, "scans", &(info->system_folders.scans)); | ||||
|     } | ||||
|  | ||||
|     GET_JSON_BOOL(root, "unlimited_autoupload_enabled", &(info->unlimited_autoupload_enabled)); | ||||
|     GET_JSON_UINT64(root, "revision", &(info->revision)); | ||||
|  | ||||
|     json_object_put(root); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,20 +1,152 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
|  | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
| /** | ||||
|  * @file | ||||
|  */ | ||||
| #ifndef YADISK_YADISK_GET_DISK_H | ||||
| #define YADISK_YADISK_GET_DISK_H | ||||
|  | ||||
| #include "yadisk_shared.h" | ||||
|  | ||||
| typedef struct yadisk_disk_info { | ||||
|     unsigned long total_space; | ||||
|     unsigned long trash_size; | ||||
|     unsigned long used_space; | ||||
|     int is_paid; | ||||
| /** | ||||
|  * @brief | ||||
|  * @en User info | ||||
|  * @ru Информация о пользователе | ||||
|  */ | ||||
| typedef struct { | ||||
|     const char* reg_time; | ||||
|     const char* display_name; | ||||
|     const char* uid; | ||||
|     const char* country; | ||||
|     int is_child; | ||||
|     const char* login; | ||||
| } yadisk_user_info; | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @en System folders paths | ||||
|  * @ru Пути системных папок | ||||
|  */ | ||||
| typedef struct { | ||||
|     const char* odnoklassniki; | ||||
|     const char* google; | ||||
|     const char* instagram; | ||||
|     const char* vkontakte; | ||||
|     const char* attach; | ||||
|     const char* mailru; | ||||
|     const char* downloads; | ||||
|     const char* applications; | ||||
|     const char* facebook; | ||||
|     const char* social; | ||||
|     const char* messenger; | ||||
|     const char* calendar; | ||||
|     const char* photostream; | ||||
|     const char* screenshots; | ||||
|     const char* scans; | ||||
| } yadisk_system_folders; | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @en Information about the disk | ||||
|  * @ru Информация о диске | ||||
|  */ | ||||
| typedef struct yadisk_disk_info { | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Total space | ||||
|      * @ru Общий объем | ||||
|      */ | ||||
|     unsigned long total_space; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Trash size | ||||
|      * @ru Объем корзины | ||||
|      */ | ||||
|     unsigned long trash_size; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Used space | ||||
|      * @ru Использованный объем | ||||
|      */ | ||||
|     unsigned long used_space; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Is paid tariff | ||||
|      * @ru Платный ли тариф | ||||
|      */ | ||||
|     int is_paid; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Registration date | ||||
|      * @ru Дата регистрации | ||||
|      */ | ||||
|     const char* reg_time; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en System folders paths | ||||
|      * @ru Пути системных папок | ||||
|      */ | ||||
|     yadisk_system_folders system_folders; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Info about user | ||||
|      * @ru Информация о пользователе | ||||
|      */ | ||||
|     yadisk_user_info user; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Unlimited autoupload | ||||
|      * @ru Безлимитная автозагрузка | ||||
|      */ | ||||
|     int unlimited_autoupload_enabled; | ||||
|     /** | ||||
|      * @brief | ||||
|      * @en Revision | ||||
|      * @ru Ревизия | ||||
|      */ | ||||
|     unsigned long revision; | ||||
| } yadisk_disk_info; | ||||
|  | ||||
| yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info); | ||||
| typedef struct { | ||||
|     /** | ||||
|      * @brief | ||||
|      * @ru Список возвращаемых атрибутов. | ||||
|      */ | ||||
|     const char* fields; | ||||
| } yadisk_get_disk_params; | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @ru Функция для получения метаинформации о диске пользователя. | ||||
|  * | ||||
|  * Реализует метод `GET /v1/disk` | ||||
|  * @param client | ||||
|  * @ru Клиент Яндекс.Диска | ||||
|  * @param params | ||||
|  * @ru Параметры запроса | ||||
|  * @param info | ||||
|  * @ru Информация о диске. Результат выполнения операции | ||||
|  * @return | ||||
|  * @ru Код возврата (YADISK_OK в случае успеха). | ||||
|  */ | ||||
| yadisk_code yadisk_get_disk(yadisk_api_client* client, yadisk_get_disk_params* params, yadisk_disk_info* info); | ||||
|  | ||||
| #endif //YADISK_YADISK_GET_DISK_H | ||||
|   | ||||
| @@ -1,12 +1,28 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #include "yadisk_get_disk_resources.h" | ||||
| #include "yadisk_api_internal.h" | ||||
|  | ||||
| yadisk_code | ||||
| yadisk_get_disk_resources( | ||||
|     yadisk_api_client* client, const char* path, yadisk_resource_info* info | ||||
|     yadisk_api_client* client, yadisk_get_disk_resources_params* path, yadisk_resource_info* info | ||||
| ) | ||||
| { | ||||
|     char* output = NULL; | ||||
| @@ -25,6 +41,9 @@ yadisk_get_disk_resources( | ||||
|     GET_JSON_STRING(root, "type", &(info->type)); | ||||
|     GET_JSON_STRING(root, "created", &(info->created)); | ||||
|     GET_JSON_STRING(root, "modified", &(info->modified)); | ||||
|     GET_JSON_STRING(root, "media_type", &(info->media_type)); | ||||
|     GET_JSON_STRING(root, "mime_type", &(info->mime_type)); | ||||
|     GET_JSON_UINT64(root, "size", &(info->size)); | ||||
|  | ||||
|     json_object_put(root); | ||||
|     return YADISK_OK; | ||||
|   | ||||
| @@ -1,6 +1,24 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #ifndef YADISK_GET_DISK_RESOURCES_H_INCLUDED | ||||
| #define YADISK_GET_DISK_RESOURCES_H_INCLUDED | ||||
|  | ||||
| @@ -12,16 +30,49 @@ | ||||
|     const char* resource_id; \ | ||||
|     const char* type; \ | ||||
|     const char* created; \ | ||||
|     const char* modified; | ||||
|     const char* modified; \ | ||||
|     const char* mime_type; \ | ||||
|     const char* media_type; \ | ||||
|     unsigned long size; \ | ||||
|     const char* md5; \ | ||||
|     const char* sha256; \ | ||||
|     const char* antivirus_status; \ | ||||
|     unsigned long long revision; \ | ||||
|     yadisk_comment_ids* comment_ids; \ | ||||
|     yadisk_sizes* sizes; \ | ||||
|     unsigned long sizes_count; | ||||
|  | ||||
| // Структура для комментариев | ||||
| typedef struct { | ||||
|     const char* private_resource; | ||||
|     const char* public_resource; | ||||
| } yadisk_comment_ids; | ||||
|  | ||||
| // Структура для размеров | ||||
| typedef struct { | ||||
|     const char* url; | ||||
|     const char* name; | ||||
| } yadisk_size; | ||||
|  | ||||
| // Массив размеров | ||||
| typedef struct { | ||||
|     yadisk_size* sizes; | ||||
|     unsigned long count; | ||||
| } yadisk_sizes; | ||||
|  | ||||
| struct yadisk_resource_item { | ||||
|     YADISK_RESOURCE_ITEM_PROPERTIES | ||||
| }; | ||||
|  | ||||
| typedef struct { | ||||
|     /** Массив элементов */ | ||||
|     struct yadisk_resource_item* items; // Массив элементов | ||||
|     unsigned long items_count;          // Количество элементов | ||||
|     unsigned long limit; | ||||
|     unsigned long offset; | ||||
|     unsigned long total; | ||||
|     const char* sort; | ||||
|     const char* path; | ||||
| } yadisk_resource_embedded; | ||||
|  | ||||
| typedef struct { | ||||
| @@ -29,6 +80,16 @@ typedef struct { | ||||
|     const yadisk_resource_embedded* _embedded; | ||||
| } yadisk_resource_info; | ||||
|  | ||||
| yadisk_code yadisk_get_disk_resources(yadisk_api_client* client, const char* path, yadisk_resource_info* resource); | ||||
| typedef struct { | ||||
|     const char* path; | ||||
|     const char* fields; | ||||
|     unsigned long limit; | ||||
|     unsigned long offset; | ||||
|     int preview_crop; | ||||
|     const char* preview_size; | ||||
|     const char* sort; | ||||
| } yadisk_get_disk_resources_params; | ||||
|  | ||||
| yadisk_code yadisk_get_disk_resources(yadisk_api_client* client, yadisk_get_disk_resources_params* params, yadisk_resource_info* resource); | ||||
|  | ||||
| #endif // YADISK_GET_DISK_RESOURCES_H_INCLUDED | ||||
|   | ||||
| @@ -1,6 +1,23 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
|  | ||||
| #include "yadisk_shared.h" | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,26 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
|  | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
| /** | ||||
|  * @file | ||||
|  */ | ||||
| #ifndef YADISK_YADISK_SHARED_H | ||||
| #define YADISK_YADISK_SHARED_H | ||||
|  | ||||
| @@ -9,17 +28,74 @@ | ||||
| #include <curl/curl.h> | ||||
| #include <json.h> | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @ru Определение кодов ошибок для взаимодействия с сервисом Яндекс.Диск. | ||||
|  * | ||||
|  * Это перечисление используется для представления различных состояний, которые могут возникнуть | ||||
|  * при взаимодействии с API Яндекс.Диска. Оно включает в себя как успешные, так и ошибочные | ||||
|  * результаты операций. | ||||
|  */ | ||||
| typedef enum { | ||||
|     /** | ||||
|      * @brief | ||||
|      * @ru Операция выполнена успешно, без ошибок. | ||||
|      */ | ||||
|     YADISK_OK = 0, | ||||
|     /** | ||||
|      * @brief | ||||
|      * @ru Ошибка при разборе JSON. | ||||
|      * | ||||
|      * Возникает, если полученный от Яндекс.Диска ответ не может быть | ||||
|      * корректно интерпретирован как валидный JSON. | ||||
|      */ | ||||
|     YADISK_FAILED_PARSE_JSON = 1, | ||||
|     /** | ||||
|      * @brief | ||||
|      * @ru Ошибка HTTP запроса. | ||||
|      * | ||||
|      * Этот код возвращается, когда происходит сбой в процессе | ||||
|      * отправки запроса или получения ответа от Яндекс.Диска, | ||||
|      * например, из-за проблем с сетевым соединением. | ||||
|      */ | ||||
|     YADISK_FAILED_HTTP_REQUEST = 2 | ||||
| } yadisk_code; | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @ru Структура для клиента API Яндекс.Диска. | ||||
|  * | ||||
|  * Эта структура используется для хранения данных, необходимых для взаимодействия с API Яндекс.Диска. | ||||
|  */ | ||||
| typedef struct { | ||||
|     /** | ||||
|      * @brief | ||||
|      * @ru OAuth токен для аутентификации в API Яндекс.Диска. | ||||
|      */ | ||||
|     char* token; | ||||
| } yadisk_api_client; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @ru Инициализирует клиента Яндекс.Диска. | ||||
|  * | ||||
|  * Вызывает необходимые процедуры для подготовки клиента к работе с API Яндекс.Диска. | ||||
|  * Эта функция должна быть вызвана перед началом работы с API. | ||||
|  * | ||||
|  * @return | ||||
|  * @ru Код ошибки (0 в случае успеха). | ||||
|  */ | ||||
| int yadisk_init(); | ||||
|  | ||||
| /** | ||||
|  * @brief | ||||
|  * @ru Освобождает ресурсы, связанные с клиентом Яндекс.Диска. | ||||
|  * | ||||
|  * Эта функция освобождает все ресурсы и выполняет необходимые действия по очистке | ||||
|  * после завершения работы с API Яндекс.Диска. Она должна быть вызвана после | ||||
|  * завершения всех операций с API. | ||||
|  */ | ||||
| void yadisk_cleanup(); | ||||
|  | ||||
| #endif //YADISK_YADISK_SHARED_H | ||||
|   | ||||
							
								
								
									
										86
									
								
								tests/app.c
									
									
									
									
									
								
							
							
						
						
									
										86
									
								
								tests/app.c
									
									
									
									
									
								
							| @@ -1,7 +1,23 @@ | ||||
| // | ||||
| // Created by maxim on 27.11.23. | ||||
| // | ||||
|  | ||||
| /* | ||||
|  * libyadisk - A C library for interacting with Yandex.Disk API | ||||
|  * | ||||
|  * This file is part of libyadisk. | ||||
|  * | ||||
|  * Copyright (C) 2023 Maxim Slipenko | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This library is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||
|  */ | ||||
| #include <yadisk.h> | ||||
| #include <stdio.h> | ||||
|  | ||||
| @@ -14,29 +30,69 @@ int main() | ||||
|  | ||||
|     yadisk_init(); | ||||
|  | ||||
|     yadisk_api_client* client = &(yadisk_api_client) { | ||||
|         .token = token | ||||
|     }; | ||||
|     yadisk_api_client* client = malloc(sizeof(yadisk_api_client)); | ||||
|     if (client != NULL) { | ||||
|         client->token = token; | ||||
|     } | ||||
|  | ||||
|     yadisk_disk_info yadisk_disk_info; | ||||
|     yadisk_get_disk(client, &yadisk_disk_info); | ||||
|     yadisk_disk_info info; | ||||
|     // yadisk_get_disk_params params1 = {.fields = "total_space"}; | ||||
|     yadisk_code result = yadisk_get_disk(client, NULL, &info); | ||||
|     if (result != YADISK_OK) { | ||||
|         printf("Erorr yadisk_get_disk\n"); | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
|     printf("Total disk size: %lu\n", yadisk_disk_info.total_space); | ||||
|     printf("Trash size: %lu\n", yadisk_disk_info.trash_size); | ||||
|     printf("Used space: %lu\n", yadisk_disk_info.used_space); | ||||
|     printf("Registration time: %s\n", yadisk_disk_info.reg_time); | ||||
|     printf("Is paid: %s\n", yadisk_disk_info.is_paid ? "Yes" : "No"); | ||||
|     printf("Total disk size: %lu\n", info.total_space); | ||||
|     printf("Trash size: %lu\n", info.trash_size); | ||||
|     printf("Used space: %lu\n", info.used_space); | ||||
|     printf("Registration time: %s\n", info.reg_time); | ||||
|     printf("Is paid: %s\n", info.is_paid ? "Yes" : "No"); | ||||
|  | ||||
|     printf("User Info:\n"); | ||||
|     printf("  Registration time: %s\n", info.user.reg_time); | ||||
|     printf("  Display Name: %s\n", info.user.display_name); | ||||
|     printf("  UID: %s\n", info.user.uid); | ||||
|     printf("  Country: %s\n", info.user.country); | ||||
|     printf("  Is Child: %s\n", info.user.is_child ? "Yes" : "No"); | ||||
|     printf("  Login: %s\n", info.user.login); | ||||
|  | ||||
|     printf("System Folders:\n"); | ||||
|     printf("  Odnoklassniki: %s\n", info.system_folders.odnoklassniki); | ||||
|     printf("  Google: %s\n", info.system_folders.google); | ||||
|     printf("  Instagram: %s\n", info.system_folders.instagram); | ||||
|     printf("  Vkontakte: %s\n", info.system_folders.vkontakte); | ||||
|     printf("  Attach: %s\n", info.system_folders.attach); | ||||
|     printf("  Mailru: %s\n", info.system_folders.mailru); | ||||
|     printf("  Downloads: %s\n", info.system_folders.downloads); | ||||
|     printf("  Applications: %s\n", info.system_folders.applications); | ||||
|     printf("  Facebook: %s\n", info.system_folders.facebook); | ||||
|     printf("  Social: %s\n", info.system_folders.social); | ||||
|     printf("  Messenger: %s\n", info.system_folders.messenger); | ||||
|     printf("  Calendar: %s\n", info.system_folders.calendar); | ||||
|     printf("  Photostream: %s\n", info.system_folders.photostream); | ||||
|     printf("  Screenshots: %s\n", info.system_folders.screenshots); | ||||
|     printf("  Scans: %s\n", info.system_folders.scans); | ||||
|  | ||||
|     printf("Unlimited Autoupload Enabled: %s\n", info.unlimited_autoupload_enabled ? "Yes" : "No"); | ||||
|     printf("Revision: %lu\n", info.revision); | ||||
|  | ||||
|     printf("=================\n"); | ||||
|  | ||||
|     yadisk_resource_info resource; | ||||
|     yadisk_get_disk_resources(client, "/", &resource); | ||||
|     yadisk_get_disk_resources_params params = { | ||||
|         .path = "/" | ||||
|     }; | ||||
|     yadisk_get_disk_resources(client, ¶ms, &resource); | ||||
|     printf("Path: %s\n", resource.path); | ||||
|     printf("Name: %s\n", resource.name); | ||||
|     printf("Type: %s\n", resource.type); | ||||
|     printf("Created: %s\n", resource.created); | ||||
|     printf("Modified: %s\n", resource.modified); | ||||
|     printf("ResourceID: %s\n", resource.resource_id); | ||||
|     printf("Media TYPE: %s\n", resource.media_type); | ||||
|     printf("Mime TYPE: %s\n", resource.mime_type); | ||||
|     printf("Size: %lu\n", resource.size); | ||||
|  | ||||
|     yadisk_cleanup(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user