mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
initial commit - import mediafire-shell sources
This commit is contained in:
16
CHANGELOG
Normal file
16
CHANGELOG
Normal file
@@ -0,0 +1,16 @@
|
||||
0.60
|
||||
|
||||
* [Bryan Christ] added the get command for single file download
|
||||
|
||||
0.51
|
||||
|
||||
* [Bryan Christ] added mkdir command to create new cloud folders
|
||||
* [Bryan Christ] removed some vestigial debug code
|
||||
|
||||
0.50
|
||||
|
||||
* [Bryan Christ] disabled SSL_LAX flag which was enabled for debugging
|
||||
|
||||
0.49
|
||||
|
||||
* [Bryan Christ] initial release
|
||||
30
Makefile
Normal file
30
Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
CFLAGS = --std=c99
|
||||
DEFS = -D_REENTRANT -D_GNU_SOURCE
|
||||
LIBS = -lcurl -lssl -lcrypto -ljansson
|
||||
PREFIX = /usr/local
|
||||
|
||||
HOSTARCH = $(shell arch)
|
||||
|
||||
ifeq ($(HOSTARCH),x86_64)
|
||||
LIB_ARCH = lib64
|
||||
else
|
||||
LIB_ARCH = lib
|
||||
endif
|
||||
|
||||
makefile: all
|
||||
|
||||
all: mfshell
|
||||
|
||||
mfshell:
|
||||
gcc $(CFLAGS) $(DEFS) -o mfshell *.c $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.so
|
||||
rm -f mfshell
|
||||
|
||||
install:
|
||||
cp -f mfshell ${PREFIX}/bin
|
||||
chmod 755 ${PREFIX}/bin/mfshell
|
||||
|
||||
|
||||
110
account.c
Normal file
110
account.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
|
||||
static int
|
||||
_decode_user_get_info(mfshell_t *mfshell,cfile_t *cfile);
|
||||
|
||||
int
|
||||
_user_get_info(mfshell_t *mfshell)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
// char *rx_buffer;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"user/get_info.php",
|
||||
"?session_token=%s"
|
||||
"&response_format=json",
|
||||
mfshell->session_token);
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
// print an error code if something went wrong
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
retval = _decode_user_get_info(mfshell,cfile);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_user_get_info(mfshell_t *mfshell,cfile_t *cfile)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *email;
|
||||
json_t *first_name;
|
||||
json_t *last_name;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response/user_info");
|
||||
|
||||
email = json_object_get(node,"email");
|
||||
if(email != NULL)
|
||||
printf("Email: %s\n\r",(char*)json_string_value(email));
|
||||
|
||||
first_name = json_object_get(node,"first_name");
|
||||
if(first_name != NULL)
|
||||
printf("Name: %s ",(char*)json_string_value(first_name));
|
||||
|
||||
last_name = json_object_get(node,"last_name");
|
||||
if(node != NULL)
|
||||
printf("%s",(char*)json_string_value(last_name));
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sample user callback
|
||||
/*
|
||||
static void
|
||||
_mycallback(char *data,size_t sz,cfile_t *cfile)
|
||||
{
|
||||
double bytes_read;
|
||||
double bytes_total;
|
||||
|
||||
bytes_read = cfile_get_rx_count(cfile);
|
||||
bytes_total = cfile_get_rx_length(cfile);
|
||||
|
||||
printf("bytes read: %.0f\n\r",bytes_read);
|
||||
|
||||
if(bytes_read == bytes_total)
|
||||
{
|
||||
printf("transfer complete!\n\r");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
9
account.h
Normal file
9
account.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _MFSHELL_ACCOUNT_H_
|
||||
#define _MFSHELL_ACCOUNT_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _user_get_info(_mfshell_t *mfshell);
|
||||
|
||||
#endif
|
||||
|
||||
3910
cacert.pem
Normal file
3910
cacert.pem
Normal file
File diff suppressed because it is too large
Load Diff
601
cfile.c
Normal file
601
cfile.c
Normal file
@@ -0,0 +1,601 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
|
||||
struct _cfile_s
|
||||
{
|
||||
CURL *curl_handle;
|
||||
char *url;
|
||||
|
||||
int mode;
|
||||
uint32_t opts;
|
||||
|
||||
char *get_args;
|
||||
char *post_args;
|
||||
|
||||
size_t (*curl_rx_io) (char *,size_t,size_t,void *);
|
||||
size_t (*curl_tx_io) (char *,size_t,size_t,void *);
|
||||
|
||||
void (*user_io) (cfile_t *);
|
||||
void *userptr;
|
||||
|
||||
void (*progress) (cfile_t *);
|
||||
|
||||
char *rx_buffer;
|
||||
ssize_t rx_buffer_sz;
|
||||
|
||||
char *tx_buffer;
|
||||
ssize_t tx_buffer_sz;
|
||||
|
||||
double rx_length;
|
||||
double rx_count;
|
||||
double tx_length;
|
||||
double tx_count;
|
||||
};
|
||||
|
||||
/*
|
||||
according to libcurl doc the payload of these two callbacks (data)
|
||||
is size * nmemb which is logistically similar to calloc().
|
||||
*/
|
||||
|
||||
/*
|
||||
static size_t
|
||||
curl_send_callback(char *data,size_t size,size_t nmemb,void *user_ptr);
|
||||
*/
|
||||
|
||||
static size_t
|
||||
_cfile_rx_callback(char *data,size_t size,size_t nmemb,void *user_ptr);
|
||||
|
||||
static size_t
|
||||
_cfile_tx_callback(char *data,size_t size,size_t nmemb,void *user_ptr);
|
||||
|
||||
static int
|
||||
_cfile_progress_callback(void *user_ptr,double dltotal,double dlnow,
|
||||
double ultotal,double ulnow);
|
||||
|
||||
|
||||
cfile_t*
|
||||
cfile_create(void)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
CURL *curl_handle;
|
||||
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
if(curl_handle == NULL) return NULL;
|
||||
|
||||
cfile = (cfile_t*)calloc(1,sizeof(cfile_t));
|
||||
|
||||
cfile->curl_handle = curl_handle;
|
||||
|
||||
cfile->curl_tx_io = &_cfile_tx_callback;
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_READFUNCTION,cfile->curl_tx_io);
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_READDATA,(void*)cfile);
|
||||
|
||||
cfile->curl_rx_io = &_cfile_rx_callback;
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_WRITEFUNCTION,cfile->curl_rx_io);
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_WRITEDATA,(void*)cfile);
|
||||
|
||||
// enable progress reporting
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_NOPROGRESS,0);
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_PROGRESSFUNCTION,_cfile_progress_callback);
|
||||
curl_easy_setopt(cfile->curl_handle,
|
||||
CURLOPT_PROGRESSDATA,(void*)cfile);
|
||||
|
||||
return cfile;
|
||||
}
|
||||
|
||||
int
|
||||
cfile_exec(cfile_t *cfile)
|
||||
{
|
||||
char *url = NULL;
|
||||
size_t len;
|
||||
int retval;
|
||||
|
||||
if(cfile == NULL) return -1;
|
||||
if(cfile->curl_handle == NULL) return -1;
|
||||
|
||||
// use an appended URL if GET arguments are supplied
|
||||
if(cfile->get_args != NULL)
|
||||
{
|
||||
len = strlen(cfile->get_args) + strlen(cfile->url) + 1;
|
||||
|
||||
url = (char*)calloc(1,len);
|
||||
|
||||
strcpy(url,cfile->url);
|
||||
strcat(url,cfile->get_args);
|
||||
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_URL,url);
|
||||
}
|
||||
|
||||
// has the user supplied POST arguments?
|
||||
if(cfile->post_args != NULL)
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_POSTFIELDS,
|
||||
cfile->post_args);
|
||||
}
|
||||
|
||||
retval = curl_easy_perform(cfile->curl_handle);
|
||||
|
||||
// restore the URL to the cURL handle if it was modified
|
||||
if(url != NULL)
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_URL,cfile->url);
|
||||
free(url);
|
||||
|
||||
url = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
if the user specified CFILE_MODE_TEXT, ensure that the buffer is
|
||||
NULL terminated.
|
||||
*/
|
||||
if(cfile->mode == CFILE_MODE_TEXT)
|
||||
{
|
||||
if(cfile->rx_buffer[cfile->rx_buffer_sz - 1] != '\0')
|
||||
{
|
||||
cfile->rx_buffer = (char*)realloc(cfile->rx_buffer,
|
||||
cfile->rx_buffer_sz + 1);
|
||||
|
||||
cfile->rx_buffer_sz++;
|
||||
|
||||
cfile->rx_buffer[cfile->rx_buffer_sz - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_destroy(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
if(cfile->url != NULL) free(cfile->url);
|
||||
if(cfile->get_args != NULL) free(cfile->get_args);
|
||||
if(cfile->post_args != NULL) free(cfile->post_args);
|
||||
if(cfile->rx_buffer != NULL) free(cfile->rx_buffer);
|
||||
if(cfile->tx_buffer != NULL) free(cfile->tx_buffer);
|
||||
|
||||
if(cfile->curl_handle != NULL)
|
||||
{
|
||||
curl_easy_cleanup(cfile->curl_handle);
|
||||
}
|
||||
|
||||
free(cfile);
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_mode(cfile_t *cfile,int mode)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
if(mode <= 0) return;
|
||||
|
||||
/*
|
||||
CFILE_MODE_TEXT ensure that the final buffer contents is NULL
|
||||
terminated.
|
||||
|
||||
CFILE_MODE_BINARY does not modify the contents of the final
|
||||
buffer at all.
|
||||
*/
|
||||
|
||||
cfile->mode = mode;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_defaults(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
cfile->mode = CFILE_MODE_TEXT;
|
||||
|
||||
// if the protocol supports following redirects, do so
|
||||
cfile_set_opts(cfile,CFILE_OPT_FOLLOW_REDIRECTS);
|
||||
|
||||
// enable SSL engine
|
||||
cfile_set_opts(cfile,CFILE_OPT_ENABLE_SSL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_url(cfile_t *cfile,const char *url)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
if(url == NULL) return;
|
||||
|
||||
// make sure curl handle was successfully instantiated
|
||||
if(cfile->curl_handle == NULL) return;
|
||||
|
||||
// reject the request if a source already exists
|
||||
if(cfile->url != NULL) return;
|
||||
|
||||
// escape the url
|
||||
// cfile->url = curl_easy_escape(cfile->url,url,0);
|
||||
|
||||
cfile->url = strdup(url);
|
||||
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_URL,cfile->url);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
cfile_get_url(cfile_t *cfile,char *buf,size_t buf_sz)
|
||||
{
|
||||
if(cfile == NULL) return -1;
|
||||
if(cfile->url == NULL) return -1;
|
||||
if(buf == NULL) return -1;
|
||||
if(buf_sz <=1 ) return -1;
|
||||
|
||||
strncpy(buf,cfile->url,buf_sz-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_args(cfile_t *cfile,int type,const char *args)
|
||||
{
|
||||
int len;
|
||||
|
||||
if(cfile == NULL) return;
|
||||
if(args == NULL) return;
|
||||
if(cfile->curl_handle == NULL) return;
|
||||
|
||||
len = strlen(args);
|
||||
if(len == 0) return;
|
||||
|
||||
if(type == CFILE_ARGS_POST)
|
||||
{
|
||||
cfile->post_args = (char*)realloc(cfile->post_args,len + 1);
|
||||
strcpy(cfile->post_args,args);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == CFILE_ARGS_GET)
|
||||
{
|
||||
cfile->get_args = (char*)realloc(cfile->get_args,len + 1);
|
||||
strcpy(cfile->get_args,args);
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: handle custome headers
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_add_args(cfile_t *cfile,int type,const char *args)
|
||||
{
|
||||
char *new_args;
|
||||
|
||||
if(cfile == NULL) return;
|
||||
|
||||
if(type == CFILE_ARGS_POST)
|
||||
{
|
||||
if(cfile->post_args == NULL)
|
||||
{
|
||||
cfile_set_args(cfile,CFILE_ARGS_POST,args);
|
||||
return;
|
||||
}
|
||||
|
||||
new_args = strdup_printf("%s%s",cfile->post_args,(char*)args);
|
||||
free(cfile->post_args);
|
||||
cfile->post_args = new_args;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == CFILE_ARGS_GET)
|
||||
{
|
||||
if(cfile->get_args == NULL)
|
||||
{
|
||||
cfile_set_args(cfile,CFILE_ARGS_GET,args);
|
||||
return;
|
||||
}
|
||||
|
||||
new_args = strdup_printf("%s%s",cfile->get_args,(char*)args);
|
||||
free(cfile->get_args);
|
||||
cfile->get_args = new_args;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
cfile_set_opts(cfile_t *cfile,uint32_t opts)
|
||||
{
|
||||
if(cfile == NULL) return -1;
|
||||
if(cfile->curl_handle == NULL) return -1;
|
||||
|
||||
cfile->opts = opts;
|
||||
|
||||
if(cfile->opts & CFILE_OPT_FOLLOW_REDIRECTS)
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_FOLLOWLOCATION,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_FOLLOWLOCATION,0);
|
||||
}
|
||||
|
||||
if(cfile->opts & CFILE_OPT_ENABLE_SSL)
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_SSLENGINE,NULL);
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_SSLENGINE_DEFAULT,1L);
|
||||
|
||||
// libcurl will use built-in CA certificate if none specified
|
||||
|
||||
//curl_easy_setopt(cfile->curl_handle,CURLOPT_SSLCERTTYPE,"PEM");
|
||||
//curl_easy_setopt(cfile->curl_handle,CURLOPT_CAINFO,"cacert.pem");
|
||||
}
|
||||
|
||||
if(cfile->opts & CFILE_OPT_ENABLE_SSL_LAX)
|
||||
{
|
||||
curl_easy_setopt(cfile->curl_handle,CURLOPT_SSL_VERIFYPEER,0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_io_func(cfile_t *cfile,CFileFunc user_io)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
cfile->user_io = user_io;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_progress_func(cfile_t *cfile,CFileFunc progress)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
cfile->progress = progress;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const char*
|
||||
cfile_get_rx_buffer(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return NULL;
|
||||
if(cfile->curl_handle == NULL) return NULL;
|
||||
|
||||
return cfile->rx_buffer;
|
||||
}
|
||||
|
||||
size_t
|
||||
cfile_get_rx_buffer_size(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
|
||||
return cfile->rx_buffer_sz;
|
||||
}
|
||||
|
||||
const char*
|
||||
cfile_get_tx_buffer(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return NULL;
|
||||
if(cfile->curl_handle == NULL) return NULL;
|
||||
|
||||
return cfile->tx_buffer;
|
||||
}
|
||||
|
||||
size_t
|
||||
cfile_get_tx_buffer_size(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
|
||||
return cfile->tx_buffer_sz;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_reset_rx_buffer(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
if(cfile->rx_buffer != NULL)
|
||||
{
|
||||
free(cfile->rx_buffer);
|
||||
cfile->rx_buffer = NULL;
|
||||
}
|
||||
|
||||
cfile->rx_buffer_sz = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_reset_tx_buffer(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
if(cfile->tx_buffer != NULL)
|
||||
{
|
||||
free(cfile->tx_buffer);
|
||||
cfile->tx_buffer = NULL;
|
||||
}
|
||||
|
||||
cfile->tx_buffer_sz = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
double
|
||||
cfile_get_rx_count(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
if(cfile->curl_handle == NULL) return 0;
|
||||
|
||||
return cfile->rx_count;
|
||||
}
|
||||
|
||||
double
|
||||
cfile_get_rx_length(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
if(cfile->curl_handle == NULL) return 0;
|
||||
|
||||
return cfile->rx_length;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
cfile_get_tx_count(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
if(cfile->curl_handle == NULL) return 0;
|
||||
|
||||
return cfile->tx_count;
|
||||
}
|
||||
|
||||
double
|
||||
cfile_get_tx_length(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return 0;
|
||||
if(cfile->curl_handle == NULL) return 0;
|
||||
|
||||
return cfile->tx_length;
|
||||
}
|
||||
|
||||
void
|
||||
cfile_set_userptr(cfile_t *cfile,void *anything)
|
||||
{
|
||||
if(cfile == NULL) return;
|
||||
|
||||
cfile->userptr = anything;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void*
|
||||
cfile_get_userptr(cfile_t *cfile)
|
||||
{
|
||||
if(cfile == NULL) return NULL;
|
||||
|
||||
return cfile->userptr;
|
||||
}
|
||||
|
||||
static size_t
|
||||
_cfile_tx_callback(char *data,size_t size,size_t nmemb,void *user_ptr)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
size_t data_sz = 0;
|
||||
char *buffer_tail;
|
||||
|
||||
/*
|
||||
Your function must return the actual number of bytes that you stored
|
||||
in that memory area. Returning 0 will signal end-of-file to the
|
||||
library and cause it to stop the current transfer.
|
||||
*/
|
||||
if(user_ptr == NULL) return 0;
|
||||
|
||||
cfile = (cfile_t*)user_ptr;
|
||||
data_sz = size * nmemb;
|
||||
|
||||
if(data_sz > 0)
|
||||
{
|
||||
cfile->tx_buffer = (char*)realloc(cfile->tx_buffer,
|
||||
cfile->tx_buffer_sz);
|
||||
|
||||
buffer_tail = cfile->tx_buffer + cfile->tx_buffer_sz;
|
||||
|
||||
memcpy(buffer_tail,data,data_sz);
|
||||
|
||||
cfile->tx_buffer_sz += data_sz;
|
||||
}
|
||||
|
||||
if(cfile->user_io != NULL)
|
||||
{
|
||||
cfile->user_io(cfile);
|
||||
}
|
||||
|
||||
if(cfile->progress != NULL)
|
||||
{
|
||||
cfile->progress(cfile);
|
||||
}
|
||||
|
||||
return data_sz;
|
||||
}
|
||||
|
||||
static size_t
|
||||
_cfile_rx_callback(char *data,size_t size,size_t nmemb,void *user_ptr)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
size_t data_sz = 0;
|
||||
char *buffer_tail = NULL;
|
||||
|
||||
/*
|
||||
Your function must return the actual number of bytes that you stored
|
||||
in that memory area. Returning 0 will signal end-of-file to the
|
||||
library and cause it to stop the current transfer.
|
||||
*/
|
||||
if(user_ptr == NULL) return 0;
|
||||
|
||||
cfile = (cfile_t*)user_ptr;
|
||||
data_sz = size * nmemb;
|
||||
|
||||
if(data_sz > 0)
|
||||
{
|
||||
cfile->rx_buffer = (char*)realloc(cfile->rx_buffer,
|
||||
cfile->rx_buffer_sz + data_sz);
|
||||
|
||||
buffer_tail = cfile->rx_buffer + cfile->rx_buffer_sz;
|
||||
|
||||
memcpy(buffer_tail,data,data_sz);
|
||||
|
||||
cfile->rx_buffer_sz += data_sz;
|
||||
}
|
||||
|
||||
if(cfile->user_io != NULL)
|
||||
{
|
||||
cfile->user_io(cfile);
|
||||
}
|
||||
|
||||
if(cfile->progress != NULL)
|
||||
{
|
||||
cfile->progress(cfile);
|
||||
}
|
||||
|
||||
return data_sz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_cfile_progress_callback(void *user_ptr,double dltotal,double dlnow,
|
||||
double ultotal,double ulnow)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
|
||||
if(user_ptr == NULL) return 0;
|
||||
|
||||
cfile = (cfile_t*)user_ptr;
|
||||
|
||||
cfile->tx_length = ultotal;
|
||||
cfile->tx_count = ulnow;
|
||||
|
||||
cfile->rx_length = dltotal;
|
||||
cfile->rx_count = dlnow;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
77
cfile.h
Normal file
77
cfile.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef _CFILE_H_
|
||||
#define _CFILE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct _cfile_s cfile_t;
|
||||
|
||||
typedef void (*CFileFunc) (cfile_t *cfile);
|
||||
|
||||
#define CFILE_MODE_TEXT 1
|
||||
#define CFILE_MODE_BINARY 2
|
||||
|
||||
#define CFILE_OPT_FOLLOW_REDIRECTS (1 << 0)
|
||||
#define CFILE_OPT_ENABLE_SSL (1 << 1)
|
||||
#define CFILE_OPT_ENABLE_SSL_LAX (1 << 2)
|
||||
|
||||
enum
|
||||
{
|
||||
CFILE_ARGS_POST,
|
||||
CFILE_ARGS_GET,
|
||||
CFILE_ARGS_HEADER,
|
||||
};
|
||||
|
||||
cfile_t* cfile_create(void);
|
||||
|
||||
int cfile_exec(cfile_t *cfile);
|
||||
|
||||
void cfile_destroy(cfile_t *cfile);
|
||||
|
||||
void cfile_set_mode(cfile_t *cfile,int mode);
|
||||
|
||||
void cfile_set_defaults(cfile_t *cfile);
|
||||
|
||||
void cfile_set_url(cfile_t *cfile,const char *url);
|
||||
|
||||
int cfile_get_url(cfile_t *cfile,char *buf,size_t buf_sz);
|
||||
|
||||
void cfile_set_args(cfile_t *cfile,int type,const char *args);
|
||||
|
||||
void cfile_add_args(cfile_t *cfile,int type,const char *args);
|
||||
|
||||
int cfile_set_opts(cfile_t *cfile,uint32_t opts);
|
||||
|
||||
uint32_t cfile_get_opts(cfile_t *cfile);
|
||||
|
||||
void cfile_set_io_func(cfile_t *cfile,CFileFunc io_func);
|
||||
|
||||
void cfile_set_progress_func(cfile_t *cfile,CFileFunc progress);
|
||||
|
||||
const char* cfile_get_rx_buffer(cfile_t *cfile);
|
||||
|
||||
size_t cfile_get_rx_buffer_size(cfile_t *cfile);
|
||||
|
||||
void cfile_reset_rx_buffer(cfile_t *cfile);
|
||||
|
||||
const char* cfile_get_tx_buffer(cfile_t *cfile);
|
||||
|
||||
size_t cfile_get_tx_buffer_size(cfile_t *cfile);
|
||||
|
||||
void cfile_reset_tx_buffer(cfile_t *cfile);
|
||||
|
||||
void cfile_copy_buffer(cfile_t *cfile,char *buffer,size_t sz);
|
||||
|
||||
double cfile_get_tx_length(cfile_t *cfile);
|
||||
|
||||
double cfile_get_rx_length(cfile_t *cfile);
|
||||
|
||||
double cfile_get_rx_count(cfile_t *cfile);
|
||||
|
||||
double cfile_get_tx_count(cfile_t *cfile);
|
||||
|
||||
void cfile_set_userptr(cfile_t *cfile,void *anything);
|
||||
|
||||
void* cfile_get_userptr(cfile_t *cfile);
|
||||
|
||||
#endif
|
||||
|
||||
9
chdir.h
Normal file
9
chdir.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _MFSHELL_CHDIR_H_
|
||||
#define _MFSHELL_CHDIR_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int
|
||||
_folder_chdir(mfshell_t *mfshell,char *folder_key);
|
||||
|
||||
#endif
|
||||
107
cmd_auth.c
Normal file
107
cmd_auth.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
#include "console.h"
|
||||
|
||||
static char*
|
||||
_get_login_from_user(void);
|
||||
|
||||
static char*
|
||||
_get_passwd_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_auth(mfshell_t *mfshell)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->server == NULL) return -1;
|
||||
|
||||
// free and invalidate existing user name
|
||||
if(mfshell->user != NULL)
|
||||
{
|
||||
free(mfshell->user);
|
||||
mfshell->user = NULL;
|
||||
}
|
||||
|
||||
// free and invalidate existing passwd
|
||||
if(mfshell->passwd != NULL)
|
||||
{
|
||||
free(mfshell->passwd);
|
||||
mfshell->passwd = NULL;
|
||||
}
|
||||
|
||||
mfshell->user = _get_login_from_user();
|
||||
mfshell->passwd = _get_passwd_from_user();
|
||||
|
||||
if(mfshell->user == NULL || mfshell->passwd == NULL) return -1;
|
||||
|
||||
retval = mfshell->get_session_token(mfshell);
|
||||
|
||||
if(retval == 0)
|
||||
printf("\n\rAuthentication SUCCESS\n\r");
|
||||
else
|
||||
printf("\n\rAuthentication FAILURE\n\r");
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_login_from_user(void)
|
||||
{
|
||||
char *login = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
|
||||
printf("login: ");
|
||||
bytes_read = getline(&login,&len,stdin);
|
||||
string_chomp(login);
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(login != NULL)
|
||||
{
|
||||
free(login);
|
||||
login = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return login;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_passwd_from_user(void)
|
||||
{
|
||||
char *passwd = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
|
||||
printf("passwd: ");
|
||||
|
||||
// disable screen echo
|
||||
console_save_state();
|
||||
console_echo_off();
|
||||
|
||||
bytes_read = getline(&passwd,&len,stdin);
|
||||
string_chomp(passwd);
|
||||
|
||||
// re-enable screen echo
|
||||
console_restore_state();
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(passwd != NULL)
|
||||
{
|
||||
free(passwd);
|
||||
passwd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return passwd;
|
||||
}
|
||||
|
||||
82
cmd_chdir.c
Normal file
82
cmd_chdir.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_chdir(mfshell_t *mfshell,const char *folderkey)
|
||||
{
|
||||
folder_t *folder_new;
|
||||
const char *folder_curr;
|
||||
const char *folder_parent;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(folderkey == NULL) return -1;
|
||||
|
||||
// change to root
|
||||
if(strcmp(folderkey,"/") == 0) folderkey = "myfiles";
|
||||
|
||||
// user wants to navigate up a level
|
||||
if(strcmp(folderkey,"..") == 0)
|
||||
{
|
||||
// do several sanity checks to see if we're already at the root
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
if(folder_curr == NULL) return 0;
|
||||
if(strcmp(folder_curr,"myfiles") == 0) return 0;
|
||||
|
||||
folder_parent = folder_get_parent(mfshell->folder_curr);
|
||||
|
||||
if(folder_parent == NULL) return 0;
|
||||
|
||||
// it's pretty sure that we're not at the root
|
||||
folderkey = folder_parent;
|
||||
}
|
||||
|
||||
// check the lenght of the key
|
||||
if(strlen(folderkey) != 13)
|
||||
{
|
||||
// as a folder moniker, "myfiles" is an exception
|
||||
if(strcmp(folderkey,"myfiles") != 0) return -1;
|
||||
}
|
||||
|
||||
// create a new folder object to store the results
|
||||
folder_new = folder_alloc();
|
||||
|
||||
// navigate to root is a special case
|
||||
if(strcmp(folderkey,"myfiles") == 0)
|
||||
{
|
||||
folder_set_key(folder_new,"myfiles");
|
||||
retval = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = mfshell->folder_get_info(mfshell,
|
||||
folder_new,(char*)folderkey);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
}
|
||||
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->folder_curr != NULL)
|
||||
{
|
||||
folder_free(mfshell->folder_curr);
|
||||
mfshell->folder_curr = NULL;
|
||||
}
|
||||
|
||||
mfshell->folder_curr = folder_new;
|
||||
}
|
||||
else
|
||||
{
|
||||
folder_free(folder_new);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
41
cmd_debug.c
Normal file
41
cmd_debug.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_debug(mfshell_t *mfshell)
|
||||
{
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"server:",
|
||||
mfshell->server);
|
||||
|
||||
if(mfshell->session_token != NULL && mfshell->secret_time != NULL)
|
||||
{
|
||||
printf(" %-15.15s %u\n\r",
|
||||
"secret key:",
|
||||
mfshell->secret_key);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"secret time:",
|
||||
mfshell->secret_time);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Authenticated");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Not authenticated");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
50
cmd_file.c
Normal file
50
cmd_file.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_file(mfshell_t *mfshell,const char *quickkey)
|
||||
{
|
||||
extern int term_width;
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfshell->file_get_info(mfshell,file,(char*)quickkey);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
if(file->name[0] != '\0')
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"filename:",
|
||||
term_width - 22,term_width -22,
|
||||
file->name);
|
||||
|
||||
if(file->quickkey[0] != '\0')
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"quickkey:",
|
||||
term_width - 22,term_width - 22,
|
||||
file->quickkey);
|
||||
|
||||
if(file->hash[0] != '\0')
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"hash:",
|
||||
term_width - 22,term_width - 22,
|
||||
file->hash);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
68
cmd_get.c
Normal file
68
cmd_get.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "download.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_get(mfshell_t *mfshell,const char *quickkey)
|
||||
{
|
||||
extern int term_width;
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
ssize_t bytes_read;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
// get file name
|
||||
retval = mfshell->file_get_info(mfshell,file,(char*)quickkey);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
file_free(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// request a direct download (streaming) link
|
||||
retval = mfshell->file_get_links(mfshell,file,(char*)quickkey);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
file_free(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// make sure we have a valid working directory to download to
|
||||
if(mfshell->local_working_dir == NULL)
|
||||
{
|
||||
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
|
||||
getcwd(mfshell->local_working_dir,PATH_MAX);
|
||||
}
|
||||
|
||||
retval = download_direct(file,mfshell->local_working_dir);
|
||||
|
||||
if(retval != -1)
|
||||
printf("\r Downloaded %zd bytes OK!\n\r",bytes_read);
|
||||
else
|
||||
printf("\r\n Download FAILED!\n\r");
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
42
cmd_help.c
Normal file
42
cmd_help.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
void
|
||||
mfshell_cmd_help(void)
|
||||
{
|
||||
printf(
|
||||
" arguments:\n\r"
|
||||
" <optional>\n\r"
|
||||
" [required]\n\r");
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
printf(
|
||||
" help show this help\n\r"
|
||||
" debug show debug information\n\r"
|
||||
|
||||
" host <server> change target server\n\r"
|
||||
" auth authenticate with active server\n\r"
|
||||
" whoami show basic user info\n\r"
|
||||
|
||||
" ls show contents of active folder\n\r"
|
||||
" cd [folderkey] change active folder\n\r"
|
||||
" pwd show the active folder\n\r"
|
||||
" lpwd show the local working directory\n\r"
|
||||
" lcd [dir] change the local working directory\n\r"
|
||||
" mkdir [folder name] create a new folder\n\r"
|
||||
|
||||
" file [quickkey] show file information\n\r"
|
||||
" links [quickkey] show access urls for the file\n\r"
|
||||
" get [quickkey] download a file\n\r");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
82
cmd_host.c
Normal file
82
cmd_host.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "command.h"
|
||||
#include "private.h"
|
||||
#include "strings.h"
|
||||
|
||||
static char*
|
||||
_get_host_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_host(mfshell_t *mfshell,const char *host)
|
||||
{
|
||||
char *alt_host = NULL;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if(host == NULL)
|
||||
{
|
||||
alt_host = _get_host_from_user();
|
||||
host = alt_host;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
// do nothing if the server is exactly the same
|
||||
if(strcmp(mfshell->server,host) == 0)
|
||||
{
|
||||
if(alt_host != NULL) free(alt_host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
free(mfshell->server);
|
||||
mfshell->server = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mfshell->server = strdup(host);
|
||||
|
||||
// invalidate server auth credentials
|
||||
if(mfshell->session_token != NULL)
|
||||
{
|
||||
free(mfshell->session_token);
|
||||
mfshell->session_token = NULL;
|
||||
}
|
||||
|
||||
if(mfshell->secret_time != NULL)
|
||||
{
|
||||
free(mfshell->secret_time);
|
||||
mfshell->secret_time = NULL;
|
||||
}
|
||||
|
||||
if(alt_host != NULL) free(alt_host);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_host_from_user(void)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *host = NULL;
|
||||
|
||||
printf("host: [www.mediafire.com] ");
|
||||
getline(&host,&len,stdin);
|
||||
string_chomp(host);
|
||||
|
||||
if(host == NULL)
|
||||
return strdup("www.mediafire.com");
|
||||
|
||||
if(strlen(host) < 2)
|
||||
{
|
||||
free(host);
|
||||
return strdup("www.mediafire.com");
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
34
cmd_lcd.c
Normal file
34
cmd_lcd.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "private.h"
|
||||
#include "mfshell.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_lcd(mfshell_t *mfshell,const char *dir)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(dir == NULL) return -1;
|
||||
|
||||
if(strlen(dir) < 1) return -1;
|
||||
|
||||
retval = chdir(dir);
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->local_working_dir != NULL)
|
||||
{
|
||||
free(mfshell->local_working_dir);
|
||||
mfshell->local_working_dir = NULL;
|
||||
}
|
||||
|
||||
mfshell->local_working_dir = strdup(dir);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
50
cmd_links.c
Normal file
50
cmd_links.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_links(mfshell_t *mfshell,const char *quickkey)
|
||||
{
|
||||
extern int term_width;
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfshell->file_get_links(mfshell,file,(char*)quickkey);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
if(file->share_link != NULL)
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"sharing url:",
|
||||
term_width - 22,term_width -22,
|
||||
file->share_link);
|
||||
|
||||
if(file->direct_link != NULL)
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"direct url:",
|
||||
term_width - 22,term_width -22,
|
||||
file->direct_link);
|
||||
|
||||
if(file->onetime_link != NULL)
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
"1-time url:",
|
||||
term_width - 22,term_width -22,
|
||||
file->onetime_link);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
39
cmd_list.c
Normal file
39
cmd_list.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_list(mfshell_t *mfshell)
|
||||
{
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
// safety check... this should never happen
|
||||
if(folder_curr == NULL)
|
||||
folder_set_key(mfshell->folder_curr,"myfiles");
|
||||
|
||||
// safety check... this should never happen
|
||||
if(folder_curr[0] == '\0')
|
||||
folder_set_key(mfshell->folder_curr,"myfiles");
|
||||
|
||||
// first folders
|
||||
retval = mfshell->folder_get_content(mfshell,0);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
// then files
|
||||
retval = mfshell->folder_get_content(mfshell,1);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
32
cmd_lpwd.c
Normal file
32
cmd_lpwd.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_lpwd(mfshell_t *mfshell)
|
||||
{
|
||||
extern int term_width;
|
||||
int trim_size;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if(mfshell->local_working_dir == NULL)
|
||||
{
|
||||
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
|
||||
getcwd(mfshell->local_working_dir,PATH_MAX);
|
||||
}
|
||||
|
||||
trim_size = term_width - 1;
|
||||
|
||||
printf("%-*.*s\n\r",
|
||||
trim_size,trim_size,
|
||||
mfshell->local_working_dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
36
cmd_mkdir.c
Normal file
36
cmd_mkdir.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_mkdir(mfshell_t *mfshell,const char *name)
|
||||
{
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
// safety check... this should never happen
|
||||
if(folder_curr == NULL)
|
||||
folder_set_key(mfshell->folder_curr,"myfiles");
|
||||
|
||||
// safety check... this should never happen
|
||||
if(folder_curr[0] == '\0')
|
||||
folder_set_key(mfshell->folder_curr,"myfiles");
|
||||
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
retval = mfshell->folder_create(mfshell,(char*)folder_curr,(char*)name);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
32
cmd_pwd.c
Normal file
32
cmd_pwd.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_pwd(mfshell_t *mfshell)
|
||||
{
|
||||
const char *folder_name;
|
||||
char *folder_name_tmp = NULL;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->folder_curr == NULL) return -1;
|
||||
|
||||
folder_name = folder_get_name(mfshell->folder_curr);
|
||||
if(folder_name[0] == '\0') return -1;
|
||||
|
||||
folder_name_tmp = strdup_printf("< %s >",folder_name);
|
||||
|
||||
printf("%-15.13s %-50.50s\n\r",
|
||||
folder_get_key(mfshell->folder_curr),
|
||||
folder_name_tmp);
|
||||
|
||||
free(folder_name_tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
21
cmd_whoami.c
Normal file
21
cmd_whoami.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "command.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_whoami(mfshell_t *mfshell)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = mfshell->user_get_info(mfshell);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
34
command.h
Normal file
34
command.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _MFSHELL_COMMAND_H_
|
||||
#define _MFSHELL_COMMAND_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
void mfshell_cmd_help(void);
|
||||
|
||||
int mfshell_cmd_debug(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_host(mfshell_t *mfshell,const char *host);
|
||||
|
||||
int mfshell_cmd_auth(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_whomai(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_list(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_chdir(mfshell_t *mfshell,const char *folderkey);
|
||||
|
||||
int mfshell_cmd_pwd(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_lpwd(mfshell_t *mfshell);
|
||||
|
||||
int mfshell_cmd_lcd(mfshell_t *mfshell,const char *dir);
|
||||
|
||||
int mfshell_cmd_file(mfshell_t *mfshell,const char *quickkey);
|
||||
|
||||
int mfshell_cmd_links(mfshell_t *mfshell,const char *quickkey);
|
||||
|
||||
int mfshell_cmd_mkdir(mfshell_t *mfshell,const char *name);
|
||||
|
||||
int mfshell_cmd_get(mfshell_t *mfshell,const char *quickkey);
|
||||
|
||||
#endif
|
||||
208
console.c
Normal file
208
console.c
Normal file
@@ -0,0 +1,208 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "console.h"
|
||||
#include "private.h"
|
||||
#include "stringv.h"
|
||||
|
||||
int
|
||||
console_control_mode(int mode)
|
||||
{
|
||||
static struct termios saved_state;
|
||||
struct termios new_state;
|
||||
int retval = 0;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case CONSOLE_STATE_SAVE:
|
||||
{
|
||||
retval = tcgetattr(STDIN_FILENO,&saved_state);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONSOLE_STATE_RESTORE:
|
||||
{
|
||||
retval = tcsetattr(STDIN_FILENO,TCSANOW,&saved_state);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONSOLE_ECHO_OFF:
|
||||
{
|
||||
tcgetattr(STDIN_FILENO,&new_state);
|
||||
new_state.c_lflag &= (~ECHO);
|
||||
// new_state.c_cc[VERASE] = '\b';
|
||||
// new_state.c_lflag &= (~ECHOE);
|
||||
tcsetattr(STDIN_FILENO,TCSANOW,&new_state);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONSOLE_ECHO_ON:
|
||||
{
|
||||
tcgetattr(STDIN_FILENO,&new_state);
|
||||
new_state.c_lflag |= ECHO;
|
||||
tcsetattr(STDIN_FILENO,TCSANOW,&new_state);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
retval = -1;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
console_get_metrics(int *height,int *width)
|
||||
{
|
||||
struct winsize metrics;
|
||||
|
||||
if(height == NULL || width == NULL) return -1;
|
||||
|
||||
ioctl(0,TIOCGWINSZ,&metrics);
|
||||
|
||||
*height = metrics.ws_row;
|
||||
*width = metrics.ws_col;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
_execute_shell_command(mfshell_t *mfshell,char *command)
|
||||
{
|
||||
extern int term_resized;
|
||||
extern int term_height;
|
||||
extern int term_width;
|
||||
|
||||
char **argv = NULL;
|
||||
int argc = 0;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(command == NULL) return -1;
|
||||
|
||||
// check to see if the terminal has been resized
|
||||
if(term_resized == 1)
|
||||
{
|
||||
if(console_get_metrics(&term_height,&term_width) == 0)
|
||||
{
|
||||
term_resized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(term_width < 30)
|
||||
{
|
||||
printf("[EE] terminal size to small\n\r");
|
||||
return -1;
|
||||
}
|
||||
|
||||
argv = stringv_split(command," ",5);
|
||||
if(argv == NULL) return -1;
|
||||
|
||||
argc = stringv_len(argv);
|
||||
|
||||
if(strcmp(argv[0],"whoami") == 0)
|
||||
{
|
||||
retval = mfshell->user_get_info(mfshell);
|
||||
mfshell->update_secret_key(mfshell);
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"help") == 0)
|
||||
{
|
||||
mfshell->help();
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"host") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->host(mfshell,argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = mfshell->host(mfshell,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"debug") == 0)
|
||||
{
|
||||
retval = mfshell->debug(mfshell);
|
||||
}
|
||||
|
||||
if((strcmp(argv[0],"ls") == 0) || strcmp(argv[0],"list") == 0)
|
||||
{
|
||||
retval = mfshell->list(mfshell);
|
||||
}
|
||||
|
||||
if((strcmp(argv[0],"cd") == 0) || strcmp(argv[0],"chdir") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->chdir(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"pwd") == 0)
|
||||
{
|
||||
retval = mfshell->pwd(mfshell);
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"lpwd") == 0)
|
||||
{
|
||||
retval = mfshell->lpwd(mfshell);
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"lcd") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->lcd(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"file") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->file(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"links") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->links(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"get") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->get(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"auth") == 0)
|
||||
{
|
||||
retval = mfshell->auth(mfshell);
|
||||
}
|
||||
|
||||
if(strcmp(argv[0],"mkdir") == 0)
|
||||
{
|
||||
if(argc > 1 && argv[1] != '\0')
|
||||
{
|
||||
retval = mfshell->mkdir(mfshell,argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
stringv_free(argv,STRINGV_FREE_ALL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
28
console.h
Normal file
28
console.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _MFSHELL_CONSOLE_H_
|
||||
#define _MFSHELL_CONSOLE_H_
|
||||
|
||||
enum
|
||||
{
|
||||
CONSOLE_STATE_SAVE = 0x01,
|
||||
CONSOLE_STATE_RESTORE,
|
||||
CONSOLE_ECHO_OFF,
|
||||
CONSOLE_ECHO_ON
|
||||
};
|
||||
|
||||
int console_control_mode(int mode);
|
||||
|
||||
#define console_save_state() \
|
||||
console_control_mode(CONSOLE_STATE_SAVE)
|
||||
|
||||
#define console_restore_state() \
|
||||
console_control_mode(CONSOLE_STATE_RESTORE)
|
||||
|
||||
#define console_echo_off() \
|
||||
console_control_mode(CONSOLE_ECHO_OFF)
|
||||
|
||||
#define console_echo_on() \
|
||||
console_control_mode(CONSOLE_ECHO_ON)
|
||||
|
||||
int console_get_metrics(int *height,int *width);
|
||||
|
||||
#endif
|
||||
134
download.c
Normal file
134
download.c
Normal file
@@ -0,0 +1,134 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "download.h"
|
||||
|
||||
void
|
||||
_download_direct_cbio(cfile_t *cfile);
|
||||
|
||||
void
|
||||
_download_direct_cbprogress(cfile_t *cfile);
|
||||
|
||||
ssize_t
|
||||
download_direct(file_t *file,char *local_dir)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
const char *url;
|
||||
const char *file_name;
|
||||
char *file_path;
|
||||
struct stat file_info;
|
||||
ssize_t bytes_read = 0;
|
||||
int retval;
|
||||
|
||||
if(file == NULL) return -1;
|
||||
if(local_dir == NULL) return -1;
|
||||
|
||||
url = file_get_direct_link(file);
|
||||
if(url == NULL) return -1;
|
||||
|
||||
file_name = file_get_name(file);
|
||||
if(file_name == NULL) return -1;
|
||||
if(strlen(file_name) < 1) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the defaults but switch to binary mode
|
||||
cfile_set_defaults(cfile);
|
||||
cfile_set_mode(cfile,CFILE_MODE_BINARY);
|
||||
|
||||
cfile_set_url(cfile,url);
|
||||
cfile_set_io_func(cfile,_download_direct_cbio);
|
||||
cfile_set_progress_func(cfile,_download_direct_cbprogress);
|
||||
|
||||
if(local_dir[strlen(local_dir) - 1] == '/')
|
||||
file_path = strdup_printf("%s%s",local_dir,file_name);
|
||||
else
|
||||
file_path = strdup_printf("%s/%s",local_dir,file_name);
|
||||
|
||||
cfile_set_userptr(cfile,(void*)file_path);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
cfile_destroy(cfile);
|
||||
|
||||
if(retval != CURLE_OK)
|
||||
{
|
||||
free(file_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
it is preferable to have the vfs tell us how many bytes the
|
||||
transfer actually is. it's really all that matters.
|
||||
*/
|
||||
memset(&file_info,0,sizeof(file_info));
|
||||
retval = stat(file_path,&file_info);
|
||||
|
||||
free(file_path);
|
||||
|
||||
if(retval != 0) return -1;
|
||||
|
||||
bytes_read = file_info.st_size;
|
||||
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
void
|
||||
_download_direct_cbio(cfile_t *cfile)
|
||||
{
|
||||
FILE *file;
|
||||
char *file_path;
|
||||
size_t bytes_ready = 0;
|
||||
const char *rx_buffer;
|
||||
|
||||
if(cfile == NULL) return;
|
||||
|
||||
file_path = (char*)cfile_get_userptr(cfile);
|
||||
if(file_path == NULL) return;
|
||||
|
||||
bytes_ready = cfile_get_rx_buffer_size(cfile);
|
||||
if(bytes_ready == 0) return;
|
||||
|
||||
file = fopen(file_path,"a+");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
rx_buffer = cfile_get_rx_buffer(cfile);
|
||||
fwrite((const void*)rx_buffer,sizeof(char),bytes_ready,file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
cfile_reset_rx_buffer(cfile);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_download_direct_cbprogress(cfile_t *cfile)
|
||||
{
|
||||
double total;
|
||||
double recv;
|
||||
|
||||
if(cfile == NULL) return;
|
||||
|
||||
total = cfile_get_rx_length(cfile);
|
||||
recv = cfile_get_rx_count(cfile);
|
||||
|
||||
printf("\r %.0f / %.0f",recv,total);
|
||||
|
||||
return;
|
||||
}
|
||||
6
download.h
Normal file
6
download.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _MFSHELL_DOWNLOAD_H_
|
||||
#define _MFSHELL_DOWNLOAD_H_
|
||||
|
||||
ssize_t download_direct(file_t *file,char *local_dir);
|
||||
|
||||
#endif
|
||||
179
file.c
Normal file
179
file.c
Normal file
@@ -0,0 +1,179 @@
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "private.h"
|
||||
|
||||
#ifndef file_t
|
||||
#define file_t _file_t
|
||||
#endif
|
||||
|
||||
file_t*
|
||||
file_alloc(void)
|
||||
{
|
||||
file_t *file;
|
||||
|
||||
file = (file_t*)calloc(1,sizeof(file_t));
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void
|
||||
file_free(file_t *file)
|
||||
{
|
||||
if(file == NULL) return;
|
||||
|
||||
if(file->share_link != NULL) free(file->share_link);
|
||||
if(file->direct_link != NULL) free(file->direct_link);
|
||||
if(file->onetime_link != NULL) free(file->onetime_link);
|
||||
|
||||
free(file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_key(file_t *file,const char *key)
|
||||
{
|
||||
int len;
|
||||
|
||||
if(file == NULL) return -1;
|
||||
if(key == NULL) return -1;
|
||||
|
||||
len = strlen(key);
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
memset(file->quickkey,0,sizeof(file->quickkey));
|
||||
strncpy(file->quickkey,key,sizeof(file->quickkey) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_key(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->quickkey;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_hash(file_t *file,const char *hash)
|
||||
{
|
||||
if(file == NULL) return -1;
|
||||
if(hash == NULL) return -1;
|
||||
|
||||
// system supports SHA256 (current) and MD5 (legacy)
|
||||
if(strlen(hash) < 32) return -1;
|
||||
|
||||
memset(file->hash,0,sizeof(file->hash));
|
||||
strncpy(file->hash,hash,sizeof(file->hash) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_hash(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->hash;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_name(file_t *file,const char *name)
|
||||
{
|
||||
if(file == NULL) return -1;
|
||||
if(name == NULL) return -1;
|
||||
|
||||
if(strlen(name) > 255) return -1;
|
||||
|
||||
memset(file->name,0,sizeof(file->name));
|
||||
strncpy(file->name,name,sizeof(file->name) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_name(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->name;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_share_link(file_t *file,const char *share_link)
|
||||
{
|
||||
if(file == NULL) return -1;
|
||||
if(share_link == NULL) return -1;
|
||||
|
||||
if(file->share_link != NULL)
|
||||
{
|
||||
free(file->share_link);
|
||||
file->share_link = NULL;
|
||||
}
|
||||
|
||||
file->share_link = strdup(share_link);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_share_link(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->share_link;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_direct_link(file_t *file,const char *direct_link)
|
||||
{
|
||||
if(file == NULL) return -1;
|
||||
if(direct_link == NULL) return -1;
|
||||
|
||||
if(file->direct_link != NULL)
|
||||
{
|
||||
free(file->direct_link);
|
||||
file->direct_link = NULL;
|
||||
}
|
||||
|
||||
file->direct_link = strdup(direct_link);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_direct_link(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->direct_link;
|
||||
}
|
||||
|
||||
int
|
||||
file_set_onetime_link(file_t *file,const char *onetime_link)
|
||||
{
|
||||
if(file == NULL) return -1;
|
||||
if(onetime_link == NULL) return -1;
|
||||
|
||||
if(file->onetime_link != NULL)
|
||||
{
|
||||
free(file->onetime_link);
|
||||
file->onetime_link = NULL;
|
||||
}
|
||||
|
||||
file->onetime_link = strdup(onetime_link);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_onetime_link(file_t *file)
|
||||
{
|
||||
if(file == NULL) return NULL;
|
||||
|
||||
return file->onetime_link;
|
||||
}
|
||||
|
||||
104
file_info.c
Normal file
104
file_info.c
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
|
||||
static int
|
||||
_decode_file_get_info(mfshell_t *mfshell,cfile_t *cfile,file_t *file);
|
||||
|
||||
int
|
||||
_file_get_info(mfshell_t *mfshell,file_t *file,char *quickkey)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
int len;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
if(mfshell->session_token == NULL) return -1;
|
||||
|
||||
if(file == NULL) return -1;
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
// key must either be 11 or 15 chars
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
// cfile_set_opts(cfile,CFILE_OPT_ENABLE_SSL_LAX);
|
||||
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"file/get_info.php",
|
||||
"?quick_key=%s"
|
||||
"&session_token=%s"
|
||||
"&response_format=json",
|
||||
quickkey,mfshell->session_token);
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
retval = _decode_file_get_info(mfshell,cfile,file);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_file_get_info(mfshell_t *mfshell,cfile_t *cfile,file_t *file)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *quickkey;
|
||||
json_t *file_hash;
|
||||
json_t *file_name;
|
||||
json_t *file_folder;
|
||||
int retval = 0;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response/file_info");
|
||||
|
||||
quickkey = json_object_get(node,"quickkey");
|
||||
if(quickkey != NULL)
|
||||
file_set_key(file,(char*)json_string_value(quickkey));
|
||||
|
||||
file_name = json_object_get(node,"filename");
|
||||
if(file_name != NULL)
|
||||
file_set_name(file,(char*)json_string_value(file_name));
|
||||
|
||||
file_hash = json_object_get(node,"hash");
|
||||
if(file_hash != NULL)
|
||||
{
|
||||
file_set_hash(file,(char*)json_string_value(file_hash));
|
||||
}
|
||||
|
||||
if(quickkey == NULL) retval = -1;
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
8
file_info.h
Normal file
8
file_info.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MFSHELL_FILE_INFO_H_
|
||||
#define _MFSHELL_FILE_INFO_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _file_get_info(mfshell_t *mfshell,file_t *file,char *quickkey);
|
||||
|
||||
#endif
|
||||
122
file_links.c
Normal file
122
file_links.c
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
|
||||
static int
|
||||
_decode_file_get_links(mfshell_t *mfshell,cfile_t *cfile,file_t *file);
|
||||
|
||||
int
|
||||
_file_get_links(mfshell_t *mfshell,file_t *file,char *quickkey)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
int len;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
if(mfshell->session_token == NULL) return -1;
|
||||
|
||||
if(file == NULL) return -1;
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
// key must either be 11 or 15 chars
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
// cfile_set_opts(cfile,CFILE_OPT_ENABLE_SSL_LAX);
|
||||
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"file/get_links.php",
|
||||
"?quick_key=%s"
|
||||
"&session_token=%s"
|
||||
"&response_format=json",
|
||||
quickkey,mfshell->session_token);
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
retval = _decode_file_get_links(mfshell,cfile,file);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_file_get_links(mfshell_t *mfshell,cfile_t *cfile,file_t *file)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *quickkey;
|
||||
json_t *share_link;
|
||||
json_t *direct_link;
|
||||
json_t *onetime_link;
|
||||
json_t *links_array;
|
||||
int retval = 0;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response");
|
||||
|
||||
links_array = json_object_get(node,"links");
|
||||
if(!json_is_array(links_array))
|
||||
{
|
||||
json_decref(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// just get the first one. maybe later support multi-quickkey
|
||||
node = json_array_get(links_array,0);
|
||||
|
||||
quickkey = json_object_get(node,"quickkey");
|
||||
if(quickkey != NULL)
|
||||
file_set_key(file,(char*)json_string_value(quickkey));
|
||||
|
||||
share_link = json_object_get(node,"normal_download");
|
||||
if(share_link != NULL)
|
||||
file_set_share_link(file,(char*)json_string_value(share_link));
|
||||
|
||||
direct_link = json_object_get(node,"direct_download");
|
||||
if(direct_link != NULL)
|
||||
{
|
||||
file_set_direct_link(file,(char*)json_string_value(direct_link));
|
||||
}
|
||||
|
||||
onetime_link = json_object_get(node,"one_time_download");
|
||||
if(onetime_link != NULL)
|
||||
{
|
||||
file_set_onetime_link(file,(char*)json_string_value(onetime_link));
|
||||
}
|
||||
|
||||
// if this is false something went horribly wrong
|
||||
if(share_link == NULL) retval = -1;
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
8
file_links.h
Normal file
8
file_links.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MFSHELL_FILE_LINKS_H_
|
||||
#define _MFSHELL_FILE_LINKS_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _file_get_links(mfshell_t *mfshell,file_t *file,char *quickkey);
|
||||
|
||||
#endif
|
||||
100
folder.c
Normal file
100
folder.c
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "private.h"
|
||||
|
||||
#ifndef folder_t
|
||||
#define folder_t _folder_t
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
71
folder_create.c
Normal file
71
folder_create.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
|
||||
int
|
||||
_folder_create(mfshell_t *mfshell,char *parent,char *name)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
if(mfshell->session_token == NULL) return -1;
|
||||
|
||||
if(name == NULL) return -1;
|
||||
if(strlen(name) < 1) return -1;
|
||||
|
||||
// key must either be 11 chars or "myfiles"
|
||||
if(parent != NULL)
|
||||
{
|
||||
if(strlen(parent) != 13)
|
||||
{
|
||||
// if it is myfiles, set paret to NULL
|
||||
if(strcmp(parent,"myfiles") == 0) parent = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
if(parent != NULL)
|
||||
{
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"folder/create.php",
|
||||
"?parent_key=%s"
|
||||
"&foldername=%s"
|
||||
"&session_token=%s"
|
||||
"&response_format=json",
|
||||
parent,name,mfshell->session_token);
|
||||
}
|
||||
else
|
||||
{
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"folder/create.php",
|
||||
"?foldername=%s",
|
||||
"&session_token=%s"
|
||||
"&response_format=json",
|
||||
name,mfshell->session_token);
|
||||
}
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
8
folder_create.h
Normal file
8
folder_create.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MFSHELL_FOLDER_CREATE_H_
|
||||
#define _MFSHELL_FOLDER_CREATE_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _folder_create(mfshell_t *mfshell,char *parent,char *name);
|
||||
|
||||
#endif
|
||||
126
folder_info.c
Normal file
126
folder_info.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "account.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
|
||||
static int
|
||||
_decode_folder_get_info(mfshell_t *mfshell,cfile_t *cfile,folder_t *folder);
|
||||
|
||||
int
|
||||
_folder_get_info(mfshell_t *mfshell,folder_t *folder,char *folderkey)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
if(mfshell->session_token == NULL) return -1;
|
||||
|
||||
if(folder == NULL) return -1;
|
||||
if(folderkey == NULL) return -1;
|
||||
|
||||
// key must either be 11 chars or "myfiles"
|
||||
if(strlen(folderkey) != 13)
|
||||
{
|
||||
if(strcmp(folderkey,"myfiles") == 0) return -1;
|
||||
}
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"folder/get_info.php",
|
||||
"?folder_key=%s"
|
||||
"&session_token=%s"
|
||||
"&response_format=json",
|
||||
folderkey,mfshell->session_token);
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
retval = _decode_folder_get_info(mfshell,cfile,folder);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_folder_get_info(mfshell_t *mfshell,cfile_t *cfile,folder_t *folder)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *folderkey;
|
||||
json_t *folder_name;
|
||||
json_t *parent_folder;
|
||||
int retval = 0;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response/folder_info");
|
||||
|
||||
folderkey = json_object_get(node,"folderkey");
|
||||
if(folderkey != NULL)
|
||||
folder_set_key(folder,(char*)json_string_value(folderkey));
|
||||
|
||||
folder_name = json_object_get(node,"name");
|
||||
if(folder_name != NULL)
|
||||
folder_set_name(folder,(char*)json_string_value(folder_name));
|
||||
|
||||
parent_folder = json_object_get(node,"parent_folderkey");
|
||||
if(parent_folder != NULL)
|
||||
{
|
||||
folder_set_parent(folder,(char*)json_string_value(parent_folder));
|
||||
}
|
||||
|
||||
// infer that the parent folder must be "myfiles" root
|
||||
if(parent_folder == NULL && folderkey != NULL)
|
||||
folder_set_parent(folder,"myfiles");
|
||||
|
||||
if(folderkey == NULL) retval = -1;
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// sample user callback
|
||||
/*
|
||||
static void
|
||||
_mycallback(char *data,size_t sz,cfile_t *cfile)
|
||||
{
|
||||
double bytes_read;
|
||||
double bytes_total;
|
||||
|
||||
bytes_read = cfile_get_rx_count(cfile);
|
||||
bytes_total = cfile_get_rx_length(cfile);
|
||||
|
||||
printf("bytes read: %.0f\n\r",bytes_read);
|
||||
|
||||
if(bytes_read == bytes_total)
|
||||
{
|
||||
printf("transfer complete!\n\r");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
8
folder_info.h
Normal file
8
folder_info.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MFSHELL_FOLDER_INFO_H_
|
||||
#define _MFSHELL_FOLDER_INFO_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _folder_get_info(mfshell_t *mfshell,folder_t *folder,char *folderkey);
|
||||
|
||||
#endif
|
||||
87
json.c
Normal file
87
json.c
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json.h"
|
||||
#include "stringv.h"
|
||||
|
||||
json_t*
|
||||
json_object_by_path(json_t *start,const char *path)
|
||||
{
|
||||
char **path_nodes;
|
||||
char **curr;
|
||||
json_t *node = NULL;
|
||||
json_t *data = NULL;
|
||||
|
||||
if(start == NULL) return NULL;
|
||||
if(path == NULL) return NULL;
|
||||
|
||||
path_nodes = stringv_split((char*)path,"/",10);
|
||||
|
||||
if(path_nodes == NULL) return NULL;
|
||||
curr = path_nodes;
|
||||
node = start;
|
||||
|
||||
while(curr != NULL)
|
||||
{
|
||||
if(*curr == NULL) break;
|
||||
|
||||
node = json_object_get(node,*curr);
|
||||
if(node == NULL) break;
|
||||
|
||||
if(!json_is_object(node))
|
||||
{
|
||||
stringv_free(path_nodes,STRINGV_FREE_ALL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
curr++;
|
||||
data = node;
|
||||
}
|
||||
|
||||
stringv_free(path_nodes,STRINGV_FREE_ALL);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// fix a path with leading slashes
|
||||
/*
|
||||
while(strlen(path) > 0)
|
||||
{
|
||||
if(*path[0] == '\')
|
||||
{
|
||||
path++;
|
||||
continue;
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
buffer = (char*)calloc(len + 1,sizeof(char));
|
||||
strncpy(buffer,path,len);
|
||||
}
|
||||
|
||||
// something went horribly wrong
|
||||
if(buffer == NULL) return NULL;
|
||||
|
||||
pos = buffer[strlen(buffer) - 1];
|
||||
|
||||
// fix a path with trailing slashes
|
||||
while(pos != buffer)
|
||||
{
|
||||
if(pos[0] == '/')
|
||||
{
|
||||
pos[0] = '\0';
|
||||
pos--;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// something else went horribly wrong
|
||||
if(pos == buffer)
|
||||
{
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
10
json.h
Normal file
10
json.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _MFSHELL_JSON_H_
|
||||
#define _MFSHELL_JSON_H_
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
json_t* json_object_by_path(json_t *start,const char *path);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
21
keys.c
Normal file
21
keys.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
|
||||
void
|
||||
_update_secret_key(mfshell_t *mfshell)
|
||||
{
|
||||
uint64_t new_val;
|
||||
|
||||
if(mfshell == NULL) return;
|
||||
|
||||
new_val = ((uint64_t)mfshell->secret_key) * 16807;
|
||||
new_val %= 0x7FFFFFFF;
|
||||
|
||||
mfshell->secret_key = new_val;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
195
list.c
Normal file
195
list.c
Normal file
@@ -0,0 +1,195 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
#include "list.h"
|
||||
|
||||
static int
|
||||
_decode_folder_get_content_folders(mfshell_t *mfshell,cfile_t *cfile);
|
||||
|
||||
static int
|
||||
_decode_folder_get_content_files(mfshell_t *mfshell,cfile_t *cfile);
|
||||
|
||||
long
|
||||
_folder_get_content(mfshell_t *mfshell,int mode)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *api_call;
|
||||
int retval;
|
||||
char *rx_buffer;
|
||||
char *content_type;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->user_signature == NULL) return -1;
|
||||
if(mfshell->session_token == NULL) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
// take the traditional defaults
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
// cfile_set_opts(cfile,CFILE_OPT_ENABLE_SSL_LAX);
|
||||
|
||||
if(mode == 0)
|
||||
content_type = "folders";
|
||||
else
|
||||
content_type = "files";
|
||||
|
||||
api_call = mfshell->create_signed_get(mfshell,0,"folder/get_content.php",
|
||||
"?session_token=%s"
|
||||
"&folder_key=%s"
|
||||
"&content_type=%s"
|
||||
"&response_format=json",
|
||||
mfshell->session_token,
|
||||
folder_get_key(mfshell->folder_curr),
|
||||
content_type);
|
||||
|
||||
cfile_set_url(cfile,api_call);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
// print an error code if something went wrong
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
// rx_buffer = cfile_get_rx_buffer(cfile);
|
||||
// printf("\n\r%s\n\r",rx_buffer);
|
||||
|
||||
if(mode == 0)
|
||||
retval = _decode_folder_get_content_folders(mfshell,cfile);
|
||||
else
|
||||
retval = _decode_folder_get_content_files(mfshell,cfile);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_folder_get_content_folders(mfshell_t *mfshell,cfile_t *cfile)
|
||||
{
|
||||
extern int term_width;
|
||||
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *data;
|
||||
|
||||
json_t *folders_array;
|
||||
json_t *folderkey;
|
||||
json_t *folder_name;
|
||||
char *folder_name_tmp;
|
||||
|
||||
int array_sz;
|
||||
int i = 0;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response/folder_content");
|
||||
|
||||
folders_array = json_object_get(node,"folders");
|
||||
if(!json_is_array(folders_array))
|
||||
{
|
||||
json_decref(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
array_sz = json_array_size(folders_array);
|
||||
for(i = 0;i < array_sz;i++)
|
||||
{
|
||||
data = json_array_get(folders_array,i);
|
||||
|
||||
if(json_is_object(data))
|
||||
{
|
||||
folderkey = json_object_get(data,"folderkey");
|
||||
|
||||
folder_name = json_object_get(data,"name");
|
||||
|
||||
if(folderkey != NULL && folder_name != NULL)
|
||||
{
|
||||
folder_name_tmp = strdup_printf("< %s >",
|
||||
json_string_value(folder_name));
|
||||
|
||||
printf(" %-15.13s %-*.*s\n\r",
|
||||
json_string_value(folderkey),
|
||||
term_width - 22,term_width - 22,
|
||||
folder_name_tmp);
|
||||
|
||||
free(folder_name_tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_folder_get_content_files(mfshell_t *mfshell,cfile_t *cfile)
|
||||
{
|
||||
extern int term_width;
|
||||
|
||||
json_error_t error;
|
||||
json_t *root;
|
||||
json_t *node;
|
||||
json_t *data;
|
||||
|
||||
json_t *files_array;
|
||||
json_t *quickkey;
|
||||
json_t *file_name;
|
||||
int array_sz;
|
||||
int i = 0;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
node = json_object_by_path(root,"response/folder_content");
|
||||
|
||||
files_array = json_object_get(node,"files");
|
||||
if(!json_is_array(files_array))
|
||||
{
|
||||
json_decref(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
array_sz = json_array_size(files_array);
|
||||
for(i = 0;i < array_sz;i++)
|
||||
{
|
||||
data = json_array_get(files_array,i);
|
||||
|
||||
if(json_is_object(data))
|
||||
{
|
||||
quickkey = json_object_get(data,"quickkey");
|
||||
|
||||
file_name = json_object_get(data,"filename");
|
||||
|
||||
if(quickkey != NULL && file_name != NULL)
|
||||
{
|
||||
printf(" %-15.15s %-*.*s\n\r",
|
||||
json_string_value(quickkey),
|
||||
term_width - 22,term_width - 22,
|
||||
json_string_value(file_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
list.h
Normal file
9
list.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _MFSHELL_LIST_H_
|
||||
#define _MFSHELL_LIST_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
long
|
||||
_folder_get_content(mfshell_t *mfshell,int mode);
|
||||
|
||||
#endif
|
||||
34
macros.h
Normal file
34
macros.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _MACROS_H_
|
||||
#define _MACROS_H_
|
||||
|
||||
// calculate the absolute value on a 2s-complement system
|
||||
#define ABSINT(x) ((x^(x>>((sizeof(x)*8)-1)))-(x>>((sizeof(x)*8)-1)))
|
||||
|
||||
// count the number of elements in the first axis of an array
|
||||
#define DIM(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
// portable implementation of getpagesize(). see NOTE 1 below.
|
||||
#if (!defined getpagesize) && (defined _SC_PAGESIZE)
|
||||
#define getpagesize(x) (sysconf(_SC_PAGESIZE))
|
||||
#endif
|
||||
#if (!defined getpagesize) && (defined _SC_PAGE_SIZE)
|
||||
#define getpagesize(x) (sysconf(_SC_PAGE_SIZE))
|
||||
#endif
|
||||
|
||||
/*
|
||||
Note 1: Regarding getpagesize()
|
||||
|
||||
In SUSv2 the getpagesize() call is labeled LEGACY, and in POSIX.1-2001
|
||||
it has been dropped; HP-UX does not have this call.
|
||||
|
||||
I suspect on most systems that do have getpagesize() it is a macro so
|
||||
we'll assume it to be. If not, we'll define it ourselves.
|
||||
|
||||
Note: That on some systems both _SC_PAGESIZE and _SC_PAGE_SIZE are
|
||||
interchangeable so we'll try both.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
96
main.c
Normal file
96
main.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "console.h"
|
||||
#include "private.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "signals.h"
|
||||
|
||||
static void
|
||||
mfshell_run(mfshell_t *mfshell);
|
||||
|
||||
int term_resized = 0;
|
||||
int term_height = 0;
|
||||
int term_width = 0;
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
extern int term_height;
|
||||
extern int term_width;
|
||||
mfshell_t *mfshell;
|
||||
char *server = "www.mediafire.com";
|
||||
size_t len;
|
||||
int retval;
|
||||
|
||||
SSL_library_init();
|
||||
|
||||
retval = console_get_metrics(&term_height,&term_width);
|
||||
if(retval != 0)
|
||||
{
|
||||
// maybe the system doesn't support it. we'll guess at it.
|
||||
term_height = 25;
|
||||
term_width = 80;
|
||||
}
|
||||
|
||||
sig_install_SIGWINCH();
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
if(argv[1] != NULL) server = argv[1];
|
||||
}
|
||||
|
||||
mfshell = mfshell_create(35860,
|
||||
"2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",server);
|
||||
|
||||
printf("\n\r");
|
||||
mfshell->auth(mfshell);
|
||||
|
||||
// begin shell mode
|
||||
mfshell_run(mfshell);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mfshell_run(mfshell_t *mfshell)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
size_t len;
|
||||
int abort = 0;
|
||||
int retval;
|
||||
|
||||
do
|
||||
{
|
||||
printf("\n\rmfshell > ");
|
||||
|
||||
getline(&cmd,&len,stdin);
|
||||
string_chomp(cmd);
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
if(strcmp(cmd,"exit") == 0)
|
||||
{
|
||||
abort = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strcmp(cmd,"quit") == 0)
|
||||
{
|
||||
abort = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
retval = mfshell->exec(mfshell,cmd);
|
||||
free(cmd);
|
||||
cmd = NULL;
|
||||
}
|
||||
while(abort == 0);
|
||||
|
||||
return;
|
||||
}
|
||||
96
mfshell.c
Normal file
96
mfshell.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "user_session.h"
|
||||
#include "command.h"
|
||||
#include "account.h"
|
||||
#include "list.h"
|
||||
#include "folder_info.h"
|
||||
#include "file_info.h"
|
||||
#include "file_links.h"
|
||||
#include "folder_create.h"
|
||||
|
||||
|
||||
mfshell_t*
|
||||
mfshell_create(int app_id,char *app_key,char *server)
|
||||
{
|
||||
mfshell_t *mfshell;
|
||||
|
||||
if(app_id <= 0) return NULL;
|
||||
if(app_key == NULL) return NULL;
|
||||
if(server == NULL) return NULL;
|
||||
|
||||
/*
|
||||
check to see if the server contains a forward-slash. if so,
|
||||
the caller did not understand the API and passed in the wrong
|
||||
type of server resource.
|
||||
*/
|
||||
if(strchr(server,'/') != NULL) return NULL;
|
||||
|
||||
mfshell = (mfshell_t*)calloc(1,sizeof(mfshell_t));
|
||||
|
||||
mfshell->app_id = app_id;
|
||||
mfshell->app_key = strdup(app_key);
|
||||
mfshell->server = strdup(server);
|
||||
|
||||
mfshell->update_secret_key = _update_secret_key;
|
||||
|
||||
mfshell->create_user_signature = _create_user_signature;
|
||||
mfshell->create_call_signature = _create_call_signature;
|
||||
mfshell->create_signed_get = _create_signed_get;
|
||||
|
||||
mfshell->exec = _execute_shell_command;
|
||||
|
||||
// console commands
|
||||
mfshell->debug = mfshell_cmd_debug;
|
||||
mfshell->list = mfshell_cmd_list;
|
||||
mfshell->chdir = mfshell_cmd_chdir;
|
||||
mfshell->pwd = mfshell_cmd_pwd;
|
||||
mfshell->help = mfshell_cmd_help;
|
||||
mfshell->file = mfshell_cmd_file;
|
||||
mfshell->links = mfshell_cmd_links;
|
||||
mfshell->host = mfshell_cmd_host;
|
||||
mfshell->auth = mfshell_cmd_auth;
|
||||
mfshell->lpwd = mfshell_cmd_lpwd;
|
||||
mfshell->lcd = mfshell_cmd_lcd;
|
||||
mfshell->mkdir = mfshell_cmd_mkdir;
|
||||
mfshell->get = mfshell_cmd_get;
|
||||
|
||||
// configure REST API callbacks
|
||||
mfshell->get_session_token = _get_session_token;
|
||||
mfshell->user_get_info = _user_get_info;
|
||||
mfshell->folder_get_content = _folder_get_content;
|
||||
mfshell->folder_get_info = _folder_get_info;
|
||||
mfshell->folder_create = _folder_create;
|
||||
|
||||
mfshell->file_get_info = _file_get_info;
|
||||
mfshell->file_get_links = _file_get_links;
|
||||
|
||||
// object to track folder location
|
||||
mfshell->folder_curr = folder_alloc();
|
||||
folder_set_key(mfshell->folder_curr,"myfiles");
|
||||
|
||||
return mfshell;
|
||||
}
|
||||
|
||||
int
|
||||
mfshell_set_login(mfshell_t *mfshell,char *user,char *passwd)
|
||||
{
|
||||
if(mfshell == NULL) return -1;
|
||||
if(user == NULL) return -1;
|
||||
if(passwd == NULL) return -1;
|
||||
|
||||
mfshell->user = strdup(user);
|
||||
mfshell->passwd = strdup(passwd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
62
mfshell.h
Normal file
62
mfshell.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _MFSHELL_H_
|
||||
#define _MFSHELL_H_
|
||||
|
||||
typedef struct _mfshell_s mfshell_t;
|
||||
typedef struct _folder_s folder_t;
|
||||
typedef struct _file_s file_t;
|
||||
|
||||
mfshell_t* mfshell_create(int app_id,char *app_key,char *server);
|
||||
|
||||
int mfshell_set_login(mfshell_t *mfshell,char *user,char *passwd);
|
||||
|
||||
int mfshell_authenticate_user(mfshell_t *mfshell);
|
||||
|
||||
|
||||
folder_t* folder_alloc(void);
|
||||
|
||||
void folder_free(folder_t *folder);
|
||||
|
||||
int folder_set_key(folder_t *folder,const char *folderkey);
|
||||
|
||||
const char* folder_get_key(folder_t *folder);
|
||||
|
||||
int folder_set_parent(folder_t *folder,const char *folderkey);
|
||||
|
||||
const char* folder_get_parent(folder_t *folder);
|
||||
|
||||
int folder_set_name(folder_t *folder,const char *name);
|
||||
|
||||
const char* folder_get_name(folder_t *folder);
|
||||
|
||||
|
||||
file_t* file_alloc(void);
|
||||
|
||||
void file_free(file_t *file);
|
||||
|
||||
int file_set_key(file_t *file,const char *quickkey);
|
||||
|
||||
const char* file_get_key(file_t *file);
|
||||
|
||||
int file_set_hash(file_t *file,const char *hash);
|
||||
|
||||
const char* file_get_hash(file_t *file);
|
||||
|
||||
int file_set_name(file_t *file,const char *name);
|
||||
|
||||
const char* file_get_name(file_t *file);
|
||||
|
||||
int file_set_share_link(file_t *file,const char *share_link);
|
||||
|
||||
const char* file_get_share_link(file_t *file);
|
||||
|
||||
int file_set_direct_link(file_t *file,const char *direct_link);
|
||||
|
||||
const char* file_get_direct_link(file_t *file);
|
||||
|
||||
int file_set_onetime_link(file_t *file,const char *onetime_link);
|
||||
|
||||
const char* file_get_onetime_link(file_t *file);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
111
private.h
Normal file
111
private.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef _MFSHELL_PRIVATE_H_
|
||||
#define _MFSHELL_PRIVATE_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef struct _mfshell_s _mfshell_t;
|
||||
typedef struct _folder_s _folder_t;
|
||||
typedef struct _file_s _file_t;
|
||||
|
||||
struct _folder_s
|
||||
{
|
||||
char folderkey[20];
|
||||
char name[41];
|
||||
char parent[20];
|
||||
uint64_t revision;
|
||||
uint32_t folder_count;
|
||||
uint32_t file_count;
|
||||
};
|
||||
|
||||
struct _file_s
|
||||
{
|
||||
char quickkey[18];
|
||||
char hash[65];
|
||||
char name[256];
|
||||
char mtime[16];
|
||||
uint64_t revision;
|
||||
|
||||
char *share_link;
|
||||
char *direct_link;
|
||||
char *onetime_link;
|
||||
};
|
||||
|
||||
struct _mfshell_s
|
||||
{
|
||||
int app_id;
|
||||
char *app_key;
|
||||
char *server;
|
||||
char *user;
|
||||
char *passwd;
|
||||
|
||||
char *user_signature;
|
||||
|
||||
char *session_token;
|
||||
char *secret_time;
|
||||
uint32_t secret_key;
|
||||
|
||||
void (*update_secret_key) (_mfshell_t *);
|
||||
|
||||
//char* (*set_sever) (_mfshell_t *,const char*);
|
||||
char* (*set_login) (_mfshell_t*,const char*);
|
||||
char* (*set_passwd) (_mfshell_t*,const char*);
|
||||
|
||||
char* (*create_user_signature) (_mfshell_t*);
|
||||
char* (*create_call_signature) (_mfshell_t*,char*,char*);
|
||||
char* (*create_signed_get) (_mfshell_t*,int,char*,char*,...);
|
||||
char* (*create_signed_post) (_mfshell_t*,int,char*,char*,...);
|
||||
|
||||
int (*exec) (_mfshell_t*,char*);
|
||||
|
||||
/* console commands */
|
||||
void (*help) (void);
|
||||
int (*debug) (_mfshell_t*);
|
||||
int (*whoami) (_mfshell_t*);
|
||||
int (*list) (_mfshell_t*);
|
||||
int (*chdir) (_mfshell_t*,const char*);
|
||||
int (*pwd) (_mfshell_t*);
|
||||
int (*file) (_mfshell_t*,const char*);
|
||||
int (*links) (_mfshell_t*,const char*);
|
||||
int (*host) (_mfshell_t*,const char*);
|
||||
int (*auth) (_mfshell_t*);
|
||||
int (*get) (_mfshell_t*,const char*);
|
||||
int (*lpwd) (_mfshell_t*);
|
||||
int (*lcd) (_mfshell_t*,const char*);
|
||||
int (*mkdir) (_mfshell_t*,const char*);
|
||||
|
||||
/* REST API calls */
|
||||
int (*get_session_token) (_mfshell_t*);
|
||||
|
||||
int (*user_get_info) (_mfshell_t*);
|
||||
|
||||
long (*folder_get_content) (_mfshell_t*,int);
|
||||
int (*folder_get_info) (_mfshell_t*,_folder_t*,char*);
|
||||
int (*folder_create) (_mfshell_t*,char*,char*);
|
||||
|
||||
int (*file_get_info) (_mfshell_t*,_file_t*,char*);
|
||||
int (*file_get_links) (_mfshell_t*,_file_t*,char*);
|
||||
|
||||
/* REST API tracking */
|
||||
_folder_t *folder_curr;
|
||||
|
||||
/* Local tracking */
|
||||
char *local_working_dir;
|
||||
|
||||
};
|
||||
|
||||
void
|
||||
_update_secret_key(_mfshell_t *mfshell);
|
||||
|
||||
char*
|
||||
_create_user_signature(_mfshell_t *mfshell);
|
||||
|
||||
char*
|
||||
_create_call_signature(_mfshell_t *mfshell,char *url,char *args);
|
||||
|
||||
char*
|
||||
_create_signed_get(_mfshell_t *mfshell,int ssl,char *api,char *fmt,...);
|
||||
|
||||
int
|
||||
_execute_shell_command(_mfshell_t *mfshell,char *command);
|
||||
|
||||
#endif
|
||||
54
signals.c
Normal file
54
signals.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "signals.h"
|
||||
|
||||
void
|
||||
sig_install_SIGWINCH(void)
|
||||
{
|
||||
signal(SIGWINCH,sig_handler_SIGWINCH);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
sig_handler_SIGWINCH(int signum)
|
||||
{
|
||||
extern int term_resized;
|
||||
|
||||
term_resized = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void
|
||||
sig_hanlder_SIGWINCH(int signum,siginfo_t *info,void *context)
|
||||
{
|
||||
extern int term_resized;
|
||||
|
||||
term_resized = 1;
|
||||
|
||||
return;
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
void
|
||||
sig_install_SIGWINCH(void)
|
||||
{
|
||||
static struct sigaction handler;
|
||||
|
||||
memset(&handler,0,sizeof(handler));
|
||||
|
||||
handler.sa_sigaction = sig_hanlder_SIGWINCH;
|
||||
sigfillset(&handler.sa_mask);
|
||||
handler.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGWINCH,&handler,NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
12
signals.h
Normal file
12
signals.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _MFSHELL_SIGNALS_H_
|
||||
#define _MFSHELL_SINGALS_H_
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
// int sig_handler_SIGWINCH(int signum,siginfo_t *info,void *context);
|
||||
|
||||
void sig_handler_SIGWINCH(int signum);
|
||||
|
||||
void sig_install_SIGWINCH(void);
|
||||
|
||||
#endif
|
||||
148
signature.c
Normal file
148
signature.c
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "private.h"
|
||||
|
||||
#ifndef mfshell_t
|
||||
#define mfshell_t _mfshell_t
|
||||
#endif
|
||||
|
||||
char*
|
||||
_create_user_signature(mfshell_t *mfshell)
|
||||
{
|
||||
char *signature_raw;
|
||||
unsigned char signature_enc[20]; // sha1 is 160 bits
|
||||
unsigned char signature_hex[41];
|
||||
int i;
|
||||
|
||||
if(mfshell == NULL) return NULL;
|
||||
|
||||
if(mfshell->app_id <= 0) return NULL;
|
||||
if(mfshell->app_key == NULL) return NULL;
|
||||
if(mfshell->user == NULL) return NULL;
|
||||
if(mfshell->passwd == NULL) return NULL;
|
||||
|
||||
signature_raw = strdup_printf("%s%s%d%s",
|
||||
mfshell->user,mfshell->passwd,mfshell->app_id,mfshell->app_key);
|
||||
|
||||
SHA1((const unsigned char *)signature_raw,
|
||||
strlen(signature_raw),signature_enc);
|
||||
|
||||
free(signature_raw);
|
||||
|
||||
for(i = 0;i < 20;i++)
|
||||
{
|
||||
sprintf(&signature_hex[i*2],"%02x",signature_enc[i]);
|
||||
}
|
||||
signature_hex[40] = '\0';
|
||||
|
||||
return strdup((const char *)signature_hex);
|
||||
}
|
||||
|
||||
char*
|
||||
_create_call_signature(mfshell_t *mfshell,char *url,char *args)
|
||||
{
|
||||
char *signature_raw;
|
||||
unsigned char signature_enc[16]; // md5 is 128 bits
|
||||
unsigned char signature_hex[33];
|
||||
char *api;
|
||||
int i;
|
||||
|
||||
if(mfshell == NULL) return NULL;
|
||||
if(url == NULL) return NULL;
|
||||
if(args == NULL) return NULL;
|
||||
|
||||
// printf("url: %s\n\rargs: %s\n\r",url,args);
|
||||
|
||||
api = strstr(url,"/api/");
|
||||
|
||||
if(api == NULL) return NULL;
|
||||
|
||||
signature_raw = strdup_printf("%d%s%s%s",
|
||||
(mfshell->secret_key % 256),
|
||||
mfshell->secret_time,
|
||||
api,args);
|
||||
|
||||
MD5((const unsigned char *)signature_raw,
|
||||
strlen(signature_raw),signature_enc);
|
||||
|
||||
free(signature_raw);
|
||||
|
||||
for(i = 0;i < 16;i++)
|
||||
{
|
||||
sprintf(&signature_hex[i*2],"%02x",signature_enc[i]);
|
||||
}
|
||||
signature_hex[32] = '\0';
|
||||
|
||||
return strdup((const char *)signature_hex);
|
||||
}
|
||||
|
||||
char*
|
||||
_create_signed_get(mfshell_t *mfshell,int ssl,char *api,char *fmt,...)
|
||||
{
|
||||
char *api_request = NULL;
|
||||
char *api_args = NULL;
|
||||
char *signature;
|
||||
char *call_hash;
|
||||
int bytes_to_alloc;
|
||||
int api_request_len;
|
||||
int api_args_len;
|
||||
int api_len;
|
||||
va_list ap;
|
||||
|
||||
if(mfshell == NULL) return NULL;
|
||||
if(mfshell->server == NULL) return NULL;
|
||||
if(mfshell->secret_time == NULL) return NULL;
|
||||
if(mfshell->session_token == NULL) return NULL;
|
||||
|
||||
// make sure the api (ex: user/get_info.php) is sane
|
||||
if(api == NULL) return NULL;
|
||||
api_len = strlen(api);
|
||||
if(api_len < 3) return NULL;
|
||||
|
||||
// calculate how big of a buffer we need
|
||||
va_start(ap, fmt);
|
||||
api_args_len = (vsnprintf(NULL, 0, fmt, ap) + 1); // + 1 for NULL
|
||||
va_end(ap);
|
||||
|
||||
// create the correctly sized buffer and process the args
|
||||
api_args = (char*)calloc(api_args_len,sizeof(char));
|
||||
|
||||
// printf("\n\r%d\n\r",api_args_len);
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(api_args, api_args_len, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// correct user error of trailing slash
|
||||
if(api[api_len - 1] == '/') api[api_len - 1] = '\0';
|
||||
|
||||
api_request = strdup_printf("%s//%s/api/%s",
|
||||
(ssl ? "https:" : "http:"), mfshell->server,api);
|
||||
|
||||
call_hash = mfshell->create_call_signature(mfshell,api_request,api_args);
|
||||
signature = strdup_printf("&signature=%s",call_hash);
|
||||
free(call_hash);
|
||||
|
||||
// compute the amount of space requred to realloc() the request
|
||||
bytes_to_alloc = api_args_len;
|
||||
bytes_to_alloc += strlen(api_request);
|
||||
bytes_to_alloc += strlen(signature);
|
||||
bytes_to_alloc += 1; // null termination
|
||||
|
||||
// append api GET args to api request
|
||||
api_request = (char*)realloc(api_request,bytes_to_alloc);
|
||||
strncat(api_request,api_args,api_args_len);
|
||||
strcat(api_request,signature);
|
||||
|
||||
free(signature);
|
||||
free(api_args);
|
||||
|
||||
return api_request;
|
||||
}
|
||||
241
strings.c
Normal file
241
strings.c
Normal file
@@ -0,0 +1,241 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "strings.h"
|
||||
#include "stringv.h"
|
||||
|
||||
char*
|
||||
strdup_printf(char* fmt, ...)
|
||||
{
|
||||
// Good for glibc 2.1 and above. Fedora5 is 2.4.
|
||||
|
||||
char *ret_str = NULL;
|
||||
va_list ap;
|
||||
int bytes_to_allocate;
|
||||
|
||||
va_start(ap, fmt);
|
||||
bytes_to_allocate = vsnprintf(ret_str, 0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// Add one for '\0'
|
||||
bytes_to_allocate++;
|
||||
|
||||
ret_str = (char*)malloc(bytes_to_allocate * sizeof(char));
|
||||
|
||||
va_start(ap, fmt);
|
||||
bytes_to_allocate = vsnprintf(ret_str, bytes_to_allocate, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret_str;
|
||||
}
|
||||
|
||||
char*
|
||||
strdup_join(char *string1,char *string2)
|
||||
{
|
||||
char *new_string;
|
||||
size_t string1_len;
|
||||
size_t string2_len;
|
||||
|
||||
if(string1 == NULL || string2 == NULL) return NULL;
|
||||
|
||||
string1_len = strlen(string1);
|
||||
string2_len = strlen(string2);
|
||||
|
||||
new_string = (char*)malloc(string1_len + string2_len + 1);
|
||||
|
||||
strncpy(new_string,string1,string1_len);
|
||||
strncat(new_string,string2,string2_len);
|
||||
|
||||
new_string[string1_len + string2_len] = '\0';
|
||||
|
||||
return new_string;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
strdup_subst(char *string,char *token,char *subst,int max)
|
||||
{
|
||||
size_t string_len = 0;
|
||||
size_t subst_len = 0;
|
||||
size_t token_len = 0;
|
||||
size_t total_len = 0;
|
||||
size_t copy_len = 0;
|
||||
size_t token_count;
|
||||
char *str_new = NULL;
|
||||
char **vectors;
|
||||
char **rewind;
|
||||
|
||||
if(string == NULL) return NULL;
|
||||
|
||||
if(token == NULL || subst == NULL) return NULL;
|
||||
|
||||
string_len = strlen(string);
|
||||
token_len = strlen(token);
|
||||
|
||||
// return on conditions that we could never handle.
|
||||
if(token_len > string_len) return NULL;
|
||||
if(token[0] == '\0') return NULL;
|
||||
|
||||
vectors = stringv_find(string,token,max);
|
||||
if(vectors == NULL) return NULL;
|
||||
rewind = vectors;
|
||||
|
||||
// count the number of tokens found in the string
|
||||
token_count = stringv_len(vectors);
|
||||
|
||||
if(token_count > max) token_count = max;
|
||||
|
||||
// start with the original string size;
|
||||
total_len = string_len;
|
||||
|
||||
// subtract the total number of token chars to be removed
|
||||
total_len -= (token_len * token_count);
|
||||
|
||||
// add back the total number of subst chars to be inserted
|
||||
total_len += (subst_len * token_count);
|
||||
|
||||
str_new = (char*)malloc((total_len + 1) * sizeof(char));
|
||||
str_new[0] = '\0';
|
||||
|
||||
while(*vectors != NULL)
|
||||
{
|
||||
// calculate distance to the next token from current position
|
||||
copy_len = *vectors - string;
|
||||
|
||||
if(copy_len > 0)
|
||||
{
|
||||
strncat(str_new,string,copy_len);
|
||||
string += copy_len;
|
||||
|
||||
// when total_len == 0 the process is complete
|
||||
total_len -= copy_len;
|
||||
}
|
||||
|
||||
strncat(str_new,token,token_len);
|
||||
|
||||
// when total_len == 0 the process is complete
|
||||
total_len -= token_len;
|
||||
|
||||
vectors++;
|
||||
}
|
||||
|
||||
// might have one more copy operation to complete
|
||||
if(total_len > 0)
|
||||
{
|
||||
strcat(str_new,string);
|
||||
}
|
||||
|
||||
// todo: can't free vectors directly cuz it was incremented
|
||||
free(rewind);
|
||||
|
||||
return str_new;
|
||||
}
|
||||
|
||||
void
|
||||
string_chomp(char *string)
|
||||
{
|
||||
size_t len;
|
||||
char *pos;
|
||||
|
||||
if(string == NULL) return;
|
||||
|
||||
len = strlen(string);
|
||||
|
||||
if(len == 0) return;
|
||||
|
||||
pos = &string[len - 1];
|
||||
|
||||
while(isspace((int)*pos) != 0)
|
||||
{
|
||||
*pos = '\0';
|
||||
pos--;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
string_strip_head(char *string,int c)
|
||||
{
|
||||
int count = 0;
|
||||
int len;
|
||||
char *pos;
|
||||
|
||||
if(string == NULL) return;
|
||||
|
||||
len = strlen(string);
|
||||
if(len == 0) return;
|
||||
|
||||
pos = string;
|
||||
|
||||
while(count < len)
|
||||
{
|
||||
|
||||
if(c <= 0)
|
||||
{
|
||||
if(isaspace((char)pos[0])
|
||||
{
|
||||
pos++;
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(
|
||||
|
||||
// fix a path with leading slashes
|
||||
while(strlen(string) > 0)
|
||||
{
|
||||
if(c > 0)
|
||||
{
|
||||
if(string[0] == c)
|
||||
{
|
||||
|
||||
|
||||
if(string[0] == (c)
|
||||
{
|
||||
string++;
|
||||
continue;
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
buffer = (char*)calloc(len + 1,sizeof(char));
|
||||
strncpy(buffer,path,len);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
A negative value shifts the string left, while a positive value
|
||||
shifts the string right. The vacuum-space is zero filled.
|
||||
*/
|
||||
/*
|
||||
void
|
||||
string_shift(char *string,ssize_t vector)
|
||||
{
|
||||
char *pos;
|
||||
ssize_t len;
|
||||
ssize_t i;
|
||||
|
||||
if(string == NULL) return;
|
||||
|
||||
len = strlen(string);
|
||||
if(len <= ABSINT(vector)) return;
|
||||
|
||||
// shift left
|
||||
if(vector < 0)
|
||||
{
|
||||
pos = string + (ABSINT(vector));
|
||||
strcpy(string,pos);
|
||||
string[len - ABSINT(vector) + 1] = '\0';
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
18
strings.h
Normal file
18
strings.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _STR_TOOLS_H_
|
||||
#define _STR_TOOLS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
char* strdup_printf(char* fmt, ...);
|
||||
|
||||
char* strdup_join(char *string1,char *string2);
|
||||
|
||||
char* strdup_subst(char *string,char *str_old,char *str_new,int max);
|
||||
|
||||
void string_chomp(char *string);
|
||||
|
||||
// void string_strip_head(char *string,char c);
|
||||
|
||||
// void string_strip_tail(char *string,char c);
|
||||
|
||||
#endif
|
||||
157
stringv.c
Normal file
157
stringv.c
Normal file
@@ -0,0 +1,157 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stringv.h"
|
||||
|
||||
size_t
|
||||
stringv_len(char **array)
|
||||
{
|
||||
size_t count = 0;
|
||||
char **pos;
|
||||
|
||||
if(array == NULL) return 0;
|
||||
|
||||
pos = array;
|
||||
while(pos[0] != NULL)
|
||||
{
|
||||
pos++;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
stringv_free(char **array,int b_free)
|
||||
{
|
||||
char **pos;
|
||||
|
||||
if(array == NULL) return;
|
||||
|
||||
pos = array;
|
||||
|
||||
while((*pos) != NULL)
|
||||
{
|
||||
free(*pos);
|
||||
++pos;
|
||||
}
|
||||
|
||||
if(b_free == STRINGV_FREE_ALL) free(array);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
char**
|
||||
stringv_copy(char **array)
|
||||
{
|
||||
uint32_t array_len;
|
||||
char **array_pos;
|
||||
|
||||
char **dup_array;
|
||||
char **dup_pos;
|
||||
|
||||
if(array == NULL) return (char**)NULL;
|
||||
|
||||
array_pos = array;
|
||||
|
||||
array_len = stringv_len(array);
|
||||
|
||||
if(array_len > UINT32_MAX - 1) array_len = UINT32_MAX -1;
|
||||
|
||||
dup_array = (char**)calloc(array_len,sizeof(char*));
|
||||
dup_pos = dup_array;
|
||||
|
||||
while((*array_pos) != NULL)
|
||||
{
|
||||
*dup_pos = strdup((const char*)*array_pos);
|
||||
|
||||
array_pos++;
|
||||
dup_pos++;
|
||||
}
|
||||
|
||||
return dup_array;
|
||||
}
|
||||
|
||||
char**
|
||||
stringv_find(char *string,char *token,int limit)
|
||||
{
|
||||
char **results = NULL;
|
||||
char *pos = NULL;
|
||||
int count = 0;
|
||||
|
||||
if(string == NULL) return (char**)NULL;
|
||||
if(token == NULL) return (char**)NULL;
|
||||
if(limit == 0) return (char**)NULL;
|
||||
|
||||
pos = string;
|
||||
|
||||
if(strlen(token) > strlen(string)) return (char**)NULL;
|
||||
|
||||
while(count != limit)
|
||||
{
|
||||
pos = strstr(pos,token);
|
||||
if(pos == NULL) break;
|
||||
|
||||
count++;
|
||||
results = (char**)realloc((void*)results,sizeof(char*) * count + 1);
|
||||
|
||||
results[count - 1] = pos;
|
||||
}
|
||||
|
||||
if(count == 0) return (char**)NULL;
|
||||
|
||||
results[count] = (char*)NULL;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
char**
|
||||
stringv_split(char *string,char *token,int limit)
|
||||
{
|
||||
char **results = NULL;
|
||||
char *curr = NULL;
|
||||
char *next = NULL;
|
||||
int count = 0;
|
||||
int len;
|
||||
size_t copy_len = 0;
|
||||
|
||||
if(string == NULL) return (char**)NULL;
|
||||
if(token == NULL) return (char**)NULL;
|
||||
if(limit == 0) return (char**)NULL;
|
||||
|
||||
len = strlen(string);
|
||||
if(strlen(token) > len) return (char**)NULL;
|
||||
|
||||
curr = string;
|
||||
|
||||
do
|
||||
{
|
||||
// alloc space for current item plus NULL vector terminator
|
||||
results = (char**)realloc(results,sizeof(char*) * (count + 2));
|
||||
|
||||
// find the next occurrence
|
||||
next = strstr(curr,token);
|
||||
|
||||
if(next != NULL)
|
||||
copy_len = next - curr;
|
||||
else
|
||||
copy_len = strlen(curr);
|
||||
|
||||
results[count] = (char*)calloc(copy_len + 1,sizeof(char));
|
||||
memcpy(results[count],curr,copy_len);
|
||||
|
||||
count++;
|
||||
|
||||
if(next == NULL) break;
|
||||
|
||||
curr = next;
|
||||
curr++;
|
||||
}
|
||||
while(count < limit);
|
||||
|
||||
results[count] = NULL;
|
||||
|
||||
return results;
|
||||
}
|
||||
25
stringv.h
Normal file
25
stringv.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef _STRING_V_H_
|
||||
#define _STRING_V_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define STRINGV_FREE_ALL 1
|
||||
|
||||
// count number of strings in a NULL in a string vector
|
||||
size_t stringv_len(char **array);
|
||||
|
||||
// free all of the strings in a vector and optionally the vector pointer
|
||||
void stringv_free(char **array,int b_free);
|
||||
|
||||
// deep copy of string vector. returns a new vector pointer
|
||||
char** stringv_copy(char **array);
|
||||
|
||||
// returns a NULL terminated vector array to every location 'token' is found
|
||||
char** stringv_find(char *string,char *token,int limit);
|
||||
|
||||
// returns a NULL terminated vector array of items delimited by 'token'
|
||||
char** stringv_split(char *string,char *token,int limit);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
141
user_session.c
Normal file
141
user_session.c
Normal file
@@ -0,0 +1,141 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "mfshell.h"
|
||||
#include "private.h"
|
||||
#include "user_session.h"
|
||||
#include "cfile.h"
|
||||
#include "strings.h"
|
||||
#include "json.h"
|
||||
|
||||
static int
|
||||
_decode_get_session_token(mfshell_t *mfshell,cfile_t *cfile);
|
||||
|
||||
int
|
||||
_get_session_token(mfshell_t *mfshell)
|
||||
{
|
||||
cfile_t *cfile;
|
||||
char *login_url;
|
||||
char *post_args;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
// create the object as a sender
|
||||
cfile = cfile_create();
|
||||
|
||||
cfile_set_defaults(cfile);
|
||||
|
||||
// cfile_set_opts(cfile,CFILE_OPT_ENABLE_SSL_LAX);
|
||||
|
||||
// configure url for operation
|
||||
login_url = strdup_printf("https://%s/api/user/get_session_token.php",
|
||||
mfshell->server);
|
||||
cfile_set_url(cfile,login_url);
|
||||
free(login_url);
|
||||
|
||||
// invalidate an existing user signature
|
||||
if(mfshell->user_signature != NULL)
|
||||
{
|
||||
free(mfshell->user_signature);
|
||||
mfshell->user_signature = NULL;
|
||||
}
|
||||
|
||||
// create user signature
|
||||
if(mfshell->user_signature == NULL)
|
||||
mfshell->user_signature = mfshell->create_user_signature(mfshell);
|
||||
|
||||
post_args = strdup_printf(
|
||||
"email=%s"
|
||||
"&password=%s"
|
||||
"&application_id=35860"
|
||||
"&signature=%s"
|
||||
"&token_version=2"
|
||||
"&response_format=json",
|
||||
mfshell->user,mfshell->passwd,mfshell->user_signature);
|
||||
|
||||
cfile_set_args(cfile,CFILE_ARGS_POST,post_args);
|
||||
free(post_args);
|
||||
|
||||
retval = cfile_exec(cfile);
|
||||
|
||||
// print an error code if something went wrong
|
||||
if(retval != CURLE_OK) printf("error %d\n\r",retval);
|
||||
|
||||
// printf("\n\r%s\n\r",cfile_get_rx_buffer(cfile));
|
||||
retval = _decode_get_session_token(mfshell,cfile);
|
||||
|
||||
cfile_destroy(cfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
_decode_get_session_token(mfshell_t *mfshell,cfile_t *cfile)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root = NULL;
|
||||
json_t *data;
|
||||
json_t *session_token;
|
||||
json_t *secret_key;
|
||||
json_t *secret_time;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(cfile == NULL) return -1;
|
||||
|
||||
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
|
||||
|
||||
data = json_object_by_path(root,"response");
|
||||
if(data == NULL) return -1;
|
||||
|
||||
session_token = json_object_get(data,"session_token");
|
||||
if(session_token == NULL)
|
||||
{
|
||||
json_decref(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mfshell->session_token = strdup(json_string_value(session_token));
|
||||
|
||||
secret_key = json_object_get(data,"secret_key");
|
||||
if(secret_key != NULL)
|
||||
mfshell->secret_key = atoll(json_string_value(secret_key));
|
||||
|
||||
/*
|
||||
time looks like a float but we must store it as a string to
|
||||
remain congruent with the server on decimal place presentation.
|
||||
*/
|
||||
secret_time = json_object_get(data,"time");
|
||||
if(secret_time != NULL)
|
||||
mfshell->secret_time = strdup(json_string_value(secret_time));
|
||||
|
||||
if(root != NULL) json_decref(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sample user callback
|
||||
/*
|
||||
static void
|
||||
_mycallback(char *data,size_t sz,cfile_t *cfile)
|
||||
{
|
||||
double bytes_read;
|
||||
double bytes_total;
|
||||
|
||||
bytes_read = cfile_get_rx_count(cfile);
|
||||
bytes_total = cfile_get_rx_length(cfile);
|
||||
|
||||
printf("bytes read: %.0f\n\r",bytes_read);
|
||||
|
||||
if(bytes_read == bytes_total)
|
||||
{
|
||||
printf("transfer complete!\n\r");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
8
user_session.h
Normal file
8
user_session.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MFSHELL_SESSION_H_
|
||||
#define _MFSHELL_SESSION_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int _get_session_token(mfshell_t *mfshell);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user