mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 21:24:28 -08:00
Refactor code into utils, mfapi and mfshell
- utils is the low level library used by the others - mfapi uses utils and implements the api and some wrappers - mfshell uses mfapi and utils to provide a shell
This commit is contained in:
126
mfapi/folder.c
Normal file
126
mfapi/folder.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "folder.h"
|
||||
|
||||
struct _folder_s
|
||||
{
|
||||
char folderkey[20];
|
||||
char name[41];
|
||||
char parent[20];
|
||||
uint64_t revision;
|
||||
uint32_t folder_count;
|
||||
uint32_t file_count;
|
||||
};
|
||||
|
||||
folder_t*
|
||||
folder_alloc(void)
|
||||
{
|
||||
folder_t *folder;
|
||||
|
||||
folder = (folder_t*)calloc(1,sizeof(folder_t));
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
void
|
||||
folder_free(folder_t *folder)
|
||||
{
|
||||
if(folder == NULL) return;
|
||||
|
||||
free(folder);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
folder_set_key(folder_t *folder,const char *key)
|
||||
{
|
||||
if(folder == NULL) return -1;
|
||||
if(key == NULL) return -1;
|
||||
|
||||
if(strlen(key) != 13) return -1;
|
||||
|
||||
memset(folder->folderkey,0,sizeof(folder->folderkey));
|
||||
strncpy(folder->folderkey,key,sizeof(folder->folderkey) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
folder_get_key(folder_t *folder)
|
||||
{
|
||||
if(folder == NULL) return NULL;
|
||||
|
||||
return folder->folderkey;
|
||||
}
|
||||
|
||||
int
|
||||
folder_set_parent(folder_t *folder,const char *parent_key)
|
||||
{
|
||||
if(folder == NULL) return -1;
|
||||
if(parent_key == NULL) return -1;
|
||||
|
||||
if(strlen(parent_key) != 13)
|
||||
{
|
||||
if(strcmp(parent_key,"myfiles") != 0) return -1;
|
||||
}
|
||||
|
||||
memset(folder->parent,0,sizeof(folder->parent));
|
||||
strncpy(folder->parent,parent_key,sizeof(folder->parent) -1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
folder_get_parent(folder_t *folder)
|
||||
{
|
||||
if(folder == NULL) return NULL;
|
||||
|
||||
return folder->parent;
|
||||
}
|
||||
|
||||
int
|
||||
folder_set_name(folder_t *folder,const char *name)
|
||||
{
|
||||
if(folder == NULL) return -1;
|
||||
if(name == NULL) return -1;
|
||||
|
||||
if(strlen(name) > 40) return -1;
|
||||
|
||||
memset(folder->name,0,sizeof(folder->name));
|
||||
strncpy(folder->name,name,sizeof(folder->name) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
folder_get_name(folder_t *folder)
|
||||
{
|
||||
if(folder == NULL) return NULL;
|
||||
|
||||
return folder->name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user