mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
mfapi/file.c mfapi/folder.c mfapi/patch.c: add error messages
This commit is contained in:
122
mfapi/file.c
122
mfapi/file.c
@@ -56,8 +56,10 @@ mffile *file_alloc(void)
|
||||
|
||||
void file_free(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file cannot be NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file->share_link != NULL)
|
||||
free(file->share_link);
|
||||
@@ -75,14 +77,20 @@ int file_set_key(mffile * file, const char *key)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file cannot be NULL\n");
|
||||
return -1;
|
||||
if (key == NULL)
|
||||
}
|
||||
if (key == NULL) {
|
||||
fprintf(stderr, "key cannot be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = strlen(key);
|
||||
if (len != 11 && len != 15)
|
||||
if (len != 11 && len != 15) {
|
||||
fprintf(stderr, "key must be 11 or 15 chars long\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(file->quickkey, 0, sizeof(file->quickkey));
|
||||
strncpy(file->quickkey, key, sizeof(file->quickkey));
|
||||
@@ -92,16 +100,20 @@ int file_set_key(mffile * file, const char *key)
|
||||
|
||||
const char *file_get_key(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->quickkey;
|
||||
}
|
||||
|
||||
int file_set_parent(mffile * file, const char *parent_key)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parent_key == NULL) {
|
||||
memset(file->parent, 0, sizeof(file->parent));
|
||||
@@ -115,8 +127,10 @@ int file_set_parent(mffile * file, const char *parent_key)
|
||||
|
||||
const char *file_get_parent(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (file->parent[0] == '\0') {
|
||||
return NULL;
|
||||
@@ -127,14 +141,19 @@ const char *file_get_parent(mffile * file)
|
||||
|
||||
int file_set_hash(mffile * file, const char *hash)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
if (hash == NULL)
|
||||
}
|
||||
if (hash == NULL) {
|
||||
fprintf(stderr, "hash cannot be NULL\n");
|
||||
return -1;
|
||||
|
||||
}
|
||||
// system supports SHA256 (current) and MD5 (legacy)
|
||||
if (strlen(hash) < 32)
|
||||
if (strlen(hash) < 32) {
|
||||
fprintf(stderr, "hash must not be shorter than 32\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(file->hash, 0, sizeof(file->hash));
|
||||
strncpy(file->hash, hash, sizeof(file->hash) - 1);
|
||||
@@ -144,21 +163,30 @@ int file_set_hash(mffile * file, const char *hash)
|
||||
|
||||
const char *file_get_hash(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->hash;
|
||||
}
|
||||
|
||||
int file_set_name(mffile * file, const char *name)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
if (name == NULL)
|
||||
}
|
||||
if (name == NULL) {
|
||||
fprintf(stderr, "name must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(name) > MFAPI_MAX_LEN_NAME)
|
||||
if (strlen(name) > MFAPI_MAX_LEN_NAME) {
|
||||
fprintf(stderr, "name must not be longer than %d\n",
|
||||
MFAPI_MAX_LEN_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(file->name, 0, sizeof(file->name));
|
||||
strncpy(file->name, name, sizeof(file->name));
|
||||
@@ -168,16 +196,20 @@ int file_set_name(mffile * file, const char *name)
|
||||
|
||||
const char *file_get_name(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->name;
|
||||
}
|
||||
|
||||
int file_set_size(mffile * file, uint64_t size)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->size = size;
|
||||
|
||||
@@ -186,16 +218,20 @@ int file_set_size(mffile * file, uint64_t size)
|
||||
|
||||
uint64_t file_get_size(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return file->size;
|
||||
}
|
||||
|
||||
int file_set_revision(mffile * file, uint64_t revision)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->revision = revision;
|
||||
|
||||
@@ -204,16 +240,20 @@ int file_set_revision(mffile * file, uint64_t revision)
|
||||
|
||||
uint64_t file_get_revision(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return file->revision;
|
||||
}
|
||||
|
||||
int file_set_created(mffile * file, time_t created)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->created = created;
|
||||
|
||||
@@ -222,18 +262,24 @@ int file_set_created(mffile * file, time_t created)
|
||||
|
||||
time_t file_get_created(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return file->created;
|
||||
}
|
||||
|
||||
int file_set_share_link(mffile * file, const char *share_link)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
if (share_link == NULL)
|
||||
}
|
||||
if (share_link == NULL) {
|
||||
fprintf(stderr, "share_link must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (file->share_link != NULL) {
|
||||
free(file->share_link);
|
||||
@@ -247,18 +293,24 @@ int file_set_share_link(mffile * file, const char *share_link)
|
||||
|
||||
const char *file_get_share_link(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->share_link;
|
||||
}
|
||||
|
||||
int file_set_direct_link(mffile * file, const char *direct_link)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
if (direct_link == NULL)
|
||||
}
|
||||
if (direct_link == NULL) {
|
||||
fprintf(stderr, "direct_link must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (file->direct_link != NULL) {
|
||||
free(file->direct_link);
|
||||
@@ -272,18 +324,24 @@ int file_set_direct_link(mffile * file, const char *direct_link)
|
||||
|
||||
const char *file_get_direct_link(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->direct_link;
|
||||
}
|
||||
|
||||
int file_set_onetime_link(mffile * file, const char *onetime_link)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return -1;
|
||||
if (onetime_link == NULL)
|
||||
}
|
||||
if (onetime_link == NULL) {
|
||||
fprintf(stderr, "onetime_link must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (file->onetime_link != NULL) {
|
||||
free(file->onetime_link);
|
||||
@@ -297,8 +355,10 @@ int file_set_onetime_link(mffile * file, const char *onetime_link)
|
||||
|
||||
const char *file_get_onetime_link(mffile * file)
|
||||
{
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "file must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file->onetime_link;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,10 @@ mffolder *folder_alloc(void)
|
||||
|
||||
void folder_free(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
free(folder);
|
||||
|
||||
@@ -53,14 +55,18 @@ void folder_free(mffolder * folder)
|
||||
|
||||
int folder_set_key(mffolder * folder, const char *key)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (key == NULL) {
|
||||
memset(folder->folderkey, 0, sizeof(folder->folderkey));
|
||||
} else {
|
||||
if (strlen(key) != 13)
|
||||
if (strlen(key) != 13) {
|
||||
fprintf(stderr, "key length must be 13\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(folder->folderkey, 0, sizeof(folder->folderkey));
|
||||
strncpy(folder->folderkey, key, sizeof(folder->folderkey));
|
||||
@@ -71,8 +77,10 @@ int folder_set_key(mffolder * folder, const char *key)
|
||||
|
||||
const char *folder_get_key(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (folder->folderkey[0] == '\0') {
|
||||
return NULL;
|
||||
@@ -83,8 +91,10 @@ const char *folder_get_key(mffolder * folder)
|
||||
|
||||
int folder_set_parent(mffolder * folder, const char *parent_key)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parent_key == NULL) {
|
||||
memset(folder->parent, 0, sizeof(folder->parent));
|
||||
@@ -98,8 +108,10 @@ int folder_set_parent(mffolder * folder, const char *parent_key)
|
||||
|
||||
const char *folder_get_parent(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (folder->parent[0] == '\0') {
|
||||
return NULL;
|
||||
@@ -110,13 +122,20 @@ const char *folder_get_parent(mffolder * folder)
|
||||
|
||||
int folder_set_name(mffolder * folder, const char *name)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
if (name == NULL)
|
||||
}
|
||||
if (name == NULL) {
|
||||
fprintf(stderr, "name must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(name) > MFAPI_MAX_LEN_NAME)
|
||||
if (strlen(name) > MFAPI_MAX_LEN_NAME) {
|
||||
fprintf(stderr, "name must not be longer than %d\n",
|
||||
MFAPI_MAX_LEN_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(folder->name, 0, sizeof(folder->name));
|
||||
strncpy(folder->name, name, sizeof(folder->name));
|
||||
@@ -126,16 +145,20 @@ int folder_set_name(mffolder * folder, const char *name)
|
||||
|
||||
const char *folder_get_name(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return folder->name;
|
||||
}
|
||||
|
||||
int folder_set_revision(mffolder * folder, uint64_t revision)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
folder->revision = revision;
|
||||
return 0;
|
||||
@@ -143,16 +166,20 @@ int folder_set_revision(mffolder * folder, uint64_t revision)
|
||||
|
||||
uint64_t folder_get_revision(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return folder->revision;
|
||||
}
|
||||
|
||||
int folder_set_created(mffolder * folder, time_t created)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
folder->created = created;
|
||||
return 0;
|
||||
@@ -160,8 +187,10 @@ int folder_set_created(mffolder * folder, time_t created)
|
||||
|
||||
time_t folder_get_created(mffolder * folder)
|
||||
{
|
||||
if (folder == NULL)
|
||||
if (folder == NULL) {
|
||||
fprintf(stderr, "folder must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return folder->created;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <openssl/sha.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "patch.h"
|
||||
|
||||
@@ -52,8 +53,10 @@ mfpatch *patch_alloc(void)
|
||||
|
||||
void patch_free(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (patch->link != NULL)
|
||||
free(patch->link);
|
||||
@@ -65,16 +68,20 @@ void patch_free(mfpatch * patch)
|
||||
|
||||
uint64_t patch_get_source_revision(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return patch->source_revision;
|
||||
}
|
||||
|
||||
int patch_set_source_revision(mfpatch * patch, uint64_t revision)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
patch->source_revision = revision;
|
||||
|
||||
@@ -83,16 +90,20 @@ int patch_set_source_revision(mfpatch * patch, uint64_t revision)
|
||||
|
||||
uint64_t patch_get_target_revision(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return patch->target_revision;
|
||||
}
|
||||
|
||||
int patch_set_target_revision(mfpatch * patch, uint64_t revision)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
patch->target_revision = revision;
|
||||
|
||||
@@ -101,21 +112,29 @@ int patch_set_target_revision(mfpatch * patch, uint64_t revision)
|
||||
|
||||
const char *patch_get_hash(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return patch->hash;
|
||||
}
|
||||
|
||||
int patch_set_hash(mfpatch * patch, const char *hash)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
if (hash == NULL)
|
||||
}
|
||||
if (hash == NULL) {
|
||||
fprintf(stderr, "hash must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(hash) < 32)
|
||||
if (strlen(hash) < 32) {
|
||||
fprintf(stderr, "hash must not be shorter than 32\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(patch->hash, 0, sizeof(patch->hash));
|
||||
strncpy(patch->hash, hash, sizeof(patch->hash) - 1);
|
||||
@@ -125,21 +144,29 @@ int patch_set_hash(mfpatch * patch, const char *hash)
|
||||
|
||||
const char *patch_get_source_hash(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return patch->source_hash;
|
||||
}
|
||||
|
||||
int patch_set_source_hash(mfpatch * patch, const char *hash)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
if (hash == NULL)
|
||||
}
|
||||
if (hash == NULL) {
|
||||
fprintf(stderr, "hash must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(hash) < 32)
|
||||
if (strlen(hash) < 32) {
|
||||
fprintf(stderr, "hash must not be shorter than 32\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(patch->source_hash, 0, sizeof(patch->source_hash));
|
||||
strncpy(patch->source_hash, hash, sizeof(patch->source_hash) - 1);
|
||||
@@ -149,21 +176,29 @@ int patch_set_source_hash(mfpatch * patch, const char *hash)
|
||||
|
||||
const char *patch_get_target_hash(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return patch->target_hash;
|
||||
}
|
||||
|
||||
int patch_set_target_hash(mfpatch * patch, const char *hash)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
if (hash == NULL)
|
||||
}
|
||||
if (hash == NULL) {
|
||||
fprintf(stderr, "hash must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(hash) < 32)
|
||||
if (strlen(hash) < 32) {
|
||||
fprintf(stderr, "hash must not be shorter than 32\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(patch->target_hash, 0, sizeof(patch->target_hash));
|
||||
strncpy(patch->target_hash, hash, sizeof(patch->target_hash) - 1);
|
||||
@@ -173,16 +208,20 @@ int patch_set_target_hash(mfpatch * patch, const char *hash)
|
||||
|
||||
uint64_t patch_get_target_size(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return patch->target_size;
|
||||
}
|
||||
|
||||
int patch_set_target_size(mfpatch * patch, uint64_t size)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
patch->target_size = size;
|
||||
|
||||
@@ -191,18 +230,24 @@ int patch_set_target_size(mfpatch * patch, uint64_t size)
|
||||
|
||||
const char *patch_get_link(mfpatch * patch)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return patch->link;
|
||||
}
|
||||
|
||||
int patch_set_link(mfpatch * patch, const char *link)
|
||||
{
|
||||
if (patch == NULL)
|
||||
if (patch == NULL) {
|
||||
fprintf(stderr, "patch must not be NULL\n");
|
||||
return -1;
|
||||
if (link == NULL)
|
||||
}
|
||||
if (link == NULL) {
|
||||
fprintf(stderr, "link must not be NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (patch->link != NULL) {
|
||||
free(patch->link);
|
||||
|
||||
Reference in New Issue
Block a user