remove the _t postfix from type names because POSIX reserves types ending in _t

This commit is contained in:
josch
2014-09-19 23:13:29 +02:00
parent e0ee1e5f8f
commit 4b2563d800
34 changed files with 294 additions and 294 deletions

View File

@@ -27,19 +27,19 @@
#include "folder.h"
#include "mfconn.h"
int mfconn_api_file_get_info(mfconn_t *mfconn, file_t *file, char *quickkey);
int mfconn_api_file_get_info(mfconn *conn, mffile *file, char *quickkey);
int mfconn_api_file_get_links(mfconn_t *mfconn, file_t *file, char *quickkey);
int mfconn_api_file_get_links(mfconn *conn, mffile *file, char *quickkey);
int mfconn_api_folder_create(mfconn_t *mfconn, char *parent, char *name);
int mfconn_api_folder_create(mfconn *conn, char *parent, char *name);
long mfconn_api_folder_get_content(mfconn_t *mfconn, int mode, folder_t *folder_curr);
long mfconn_api_folder_get_content(mfconn *conn, int mode, mffolder *folder_curr);
int mfconn_api_folder_get_info(mfconn_t *mfconn, folder_t *folder, char *folderkey);
int mfconn_api_folder_get_info(mfconn *conn, mffolder *folder, char *folderkey);
int mfconn_api_user_get_info(mfconn_t *mfconn);
int mfconn_api_user_get_info(mfconn *conn);
int mfconn_api_user_get_session_token(mfconn_t *mfconn, char *server,
int mfconn_api_user_get_session_token(mfconn *conn, char *server,
char *username, char *password, int app_id, char *app_key,
uint32_t *secret_key, char **secret_time, char **session_token);

View File

@@ -32,16 +32,16 @@
#include "../../utils/http.h"
static int
_decode_file_get_info(http_t *conn, void *data);
_decode_file_get_info(mfhttp *conn, void *data);
int
mfconn_api_file_get_info(mfconn_t *mfconn,file_t *file,char *quickkey)
mfconn_api_file_get_info(mfconn *conn,mffile *file,char *quickkey)
{
char *api_call;
int retval;
int len;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
if(file == NULL) return -1;
if(quickkey == NULL) return -1;
@@ -51,18 +51,18 @@ mfconn_api_file_get_info(mfconn_t *mfconn,file_t *file,char *quickkey)
// key must either be 11 or 15 chars
if(len != 11 && len != 15) return -1;
api_call = mfconn_create_signed_get(mfconn, 1, "file/get_info.php",
api_call = mfconn_create_signed_get(conn, 1, "file/get_info.php",
"?quick_key=%s&response_format=json", quickkey);
http_t *conn = http_create();
retval = http_get_buf(conn, api_call, _decode_file_get_info, file);
http_destroy(conn);
mfhttp *http = http_create();
retval = http_get_buf(http, api_call, _decode_file_get_info, file);
http_destroy(http);
return retval;
}
static int
_decode_file_get_info(http_t *conn, void *data)
_decode_file_get_info(mfhttp *conn, void *data)
{
json_error_t error;
json_t *root;
@@ -71,11 +71,11 @@ _decode_file_get_info(http_t *conn, void *data)
json_t *file_hash;
json_t *file_name;
int retval = 0;
file_t *file;
mffile *file;
if(data == NULL) return -1;
file = (file_t *)data;
file = (mffile *)data;
root = http_parse_buf_json(conn, 0, &error);

View File

@@ -32,16 +32,16 @@
#include "../../utils/http.h"
static int
_decode_file_get_links(http_t *conn, void *data);
_decode_file_get_links(mfhttp *conn, void *data);
int
mfconn_api_file_get_links(mfconn_t *mfconn,file_t *file,char *quickkey)
mfconn_api_file_get_links(mfconn *conn,mffile *file,char *quickkey)
{
char *api_call;
int retval;
int len;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
if(file == NULL) return -1;
if(quickkey == NULL) return -1;
@@ -51,18 +51,18 @@ mfconn_api_file_get_links(mfconn_t *mfconn,file_t *file,char *quickkey)
// key must either be 11 or 15 chars
if(len != 11 && len != 15) return -1;
api_call = mfconn_create_signed_get(mfconn,0,"file/get_links.php",
api_call = mfconn_create_signed_get(conn,0,"file/get_links.php",
"?quick_key=%s&response_format=json", quickkey);
http_t *conn = http_create();
retval = http_get_buf(conn, api_call, _decode_file_get_links, file);
http_destroy(conn);
mfhttp *http = http_create();
retval = http_get_buf(http, api_call, _decode_file_get_links, file);
http_destroy(http);
return retval;
}
static int
_decode_file_get_links(http_t *conn, void *data)
_decode_file_get_links(mfhttp *conn, void *data)
{
json_error_t error;
json_t *root;
@@ -73,11 +73,11 @@ _decode_file_get_links(http_t *conn, void *data)
json_t *onetime_link;
json_t *links_array;
int retval = 0;
file_t *file;
mffile *file;
if(data == NULL) return -1;
file = (file_t *)data;
file = (mffile *)data;
root = http_parse_buf_json(conn, 0, &error);

View File

@@ -30,12 +30,12 @@
#include "../../utils/strings.h"
int
mfconn_api_folder_create(mfconn_t *mfconn,char *parent,char *name)
mfconn_api_folder_create(mfconn *conn,char *parent,char *name)
{
char *api_call;
int retval;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
if(name == NULL) return -1;
if(strlen(name) < 1) return -1;
@@ -52,7 +52,7 @@ mfconn_api_folder_create(mfconn_t *mfconn,char *parent,char *name)
if(parent != NULL)
{
api_call = mfconn_create_signed_get(mfconn,0,"folder/create.php",
api_call = mfconn_create_signed_get(conn,0,"folder/create.php",
"?parent_key=%s"
"&foldername=%s"
"&response_format=json",
@@ -60,13 +60,13 @@ mfconn_api_folder_create(mfconn_t *mfconn,char *parent,char *name)
}
else
{
api_call = mfconn_create_signed_get(mfconn,0,"folder/create.php",
api_call = mfconn_create_signed_get(conn,0,"folder/create.php",
"?foldername=%s&response_format=json", name);
}
http_t *conn = http_create();
retval = http_get_buf(conn, api_call, NULL, NULL);
http_destroy(conn);
mfhttp *http = http_create();
retval = http_get_buf(http, api_call, NULL, NULL);
http_destroy(http);
return retval;
}

View File

@@ -33,19 +33,19 @@
#include "../../utils/http.h"
static int
_decode_folder_get_content_folders(http_t *conn, void *data);
_decode_folder_get_content_folders(mfhttp *conn, void *data);
static int
_decode_folder_get_content_files(http_t *conn, void *data);
_decode_folder_get_content_files(mfhttp *conn, void *data);
long
mfconn_api_folder_get_content(mfconn_t *mfconn, int mode, folder_t *folder_curr)
mfconn_api_folder_get_content(mfconn *conn, int mode, mffolder *folder_curr)
{
char *api_call;
int retval;
char *content_type;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
if(mode == 0)
content_type = "folders";
@@ -61,26 +61,26 @@ mfconn_api_folder_get_content(mfconn_t *mfconn, int mode, folder_t *folder_curr)
fprintf(stderr, "folder_get_key '\\0'\n");
return 0;
}*/
api_call = mfconn_create_signed_get(mfconn,0,"folder/get_content.php",
api_call = mfconn_create_signed_get(conn,0,"folder/get_content.php",
"?folder_key=%s"
"&content_type=%s"
"&response_format=json",
folderkey,
content_type);
http_t* conn = http_create();
mfhttp* http = http_create();
if(mode == 0)
retval = http_get_buf(conn, api_call, _decode_folder_get_content_folders, NULL);
retval = http_get_buf(http, api_call, _decode_folder_get_content_folders, NULL);
else
retval = http_get_buf(conn, api_call, _decode_folder_get_content_files, NULL);
http_destroy(conn);
retval = http_get_buf(http, api_call, _decode_folder_get_content_files, NULL);
http_destroy(http);
return retval;
}
static int
_decode_folder_get_content_folders(http_t *conn, void *user_ptr)
_decode_folder_get_content_folders(mfhttp *conn, void *user_ptr)
{
json_error_t error;
json_t *root;
@@ -143,7 +143,7 @@ _decode_folder_get_content_folders(http_t *conn, void *user_ptr)
}
static int
_decode_folder_get_content_files(http_t *conn, void *user_ptr)
_decode_folder_get_content_files(mfhttp *conn, void *user_ptr)
{
json_error_t error;
json_t *root;

View File

@@ -33,15 +33,15 @@
#include "../../utils/http.h"
static int
_decode_folder_get_info(http_t *conn, void *data);
_decode_folder_get_info(mfhttp *conn, void *data);
int
mfconn_api_folder_get_info(mfconn_t *mfconn,folder_t *folder,char *folderkey)
mfconn_api_folder_get_info(mfconn *conn,mffolder *folder,char *folderkey)
{
char *api_call;
int retval;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
if(folder == NULL) return -1;
if(folderkey == NULL) return -1;
@@ -52,18 +52,18 @@ mfconn_api_folder_get_info(mfconn_t *mfconn,folder_t *folder,char *folderkey)
if(strcmp(folderkey,"myfiles") == 0) return -1;
}
api_call = mfconn_create_signed_get(mfconn,0,"folder/get_info.php",
api_call = mfconn_create_signed_get(conn,0,"folder/get_info.php",
"?folder_key=%s&response_format=json", folderkey);
http_t *conn = http_create();
retval = http_get_buf(conn, api_call, _decode_folder_get_info, folder);
http_destroy(conn);
mfhttp *http = http_create();
retval = http_get_buf(http, api_call, _decode_folder_get_info, folder);
http_destroy(http);
return retval;
}
static int
_decode_folder_get_info(http_t *conn, void *data)
_decode_folder_get_info(mfhttp *conn, void *data)
{
json_error_t error;
json_t *root;
@@ -72,11 +72,11 @@ _decode_folder_get_info(http_t *conn, void *data)
json_t *folder_name;
json_t *parent_folder;
int retval = 0;
folder_t *folder;
mffolder *folder;
if(data == NULL) return -1;
folder = (folder_t *)data;
folder = (mffolder *)data;
root = http_parse_buf_json(conn, 0, &error);
@@ -110,7 +110,7 @@ _decode_folder_get_info(http_t *conn, void *data)
// sample user callback
/*
static void
_mycallback(char *data,size_t sz,cfile_t *cfile)
_mycallback(char *data,size_t sz,cmffile *cfile)
{
double bytes_read;
double bytes_total;

View File

@@ -32,29 +32,29 @@
#include "../../utils/http.h"
static int
_decode_user_get_info(http_t *conn, void *data);
_decode_user_get_info(mfhttp *conn, void *data);
int
mfconn_api_user_get_info(mfconn_t *mfconn)
mfconn_api_user_get_info(mfconn *conn)
{
char *api_call;
int retval;
// char *rx_buffer;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
api_call = mfconn_create_signed_get(mfconn,0,"user/get_info.php",
api_call = mfconn_create_signed_get(conn,0,"user/get_info.php",
"&response_format=json");
http_t* conn = http_create();
retval = http_get_buf(conn, api_call, _decode_user_get_info, NULL);
http_destroy(conn);
mfhttp* http = http_create();
retval = http_get_buf(http, api_call, _decode_user_get_info, NULL);
http_destroy(http);
return retval;
}
static int
_decode_user_get_info(http_t *conn, void *data)
_decode_user_get_info(mfhttp *conn, void *data)
{
json_error_t error;
json_t *root;
@@ -92,7 +92,7 @@ _decode_user_get_info(http_t *conn, void *data)
// sample user callback
/*
static void
_mycallback(char *data,size_t sz,cfile_t *cfile)
_mycallback(char *data,size_t sz,cmffile *cfile)
{
double bytes_read;
double bytes_total;

View File

@@ -32,7 +32,7 @@
#include "../../utils/json.h"
static int
_decode_get_session_token(http_t *conn, void *data);
_decode_get_session_token(mfhttp *conn, void *data);
struct user_get_session_token_response
{
@@ -42,7 +42,7 @@ struct user_get_session_token_response
};
int
mfconn_api_user_get_session_token(mfconn_t *mfconn, char *server,
mfconn_api_user_get_session_token(mfconn *conn, char *server,
char *username, char *password, int app_id, char *app_key,
uint32_t *secret_key, char **secret_time, char **session_token)
{
@@ -52,14 +52,14 @@ mfconn_api_user_get_session_token(mfconn_t *mfconn, char *server,
int retval;
struct user_get_session_token_response response;
if(mfconn == NULL) return -1;
if(conn == NULL) return -1;
// configure url for operation
login_url = strdup_printf("https://%s/api/user/get_session_token.php",
server);
// create user signature
user_signature = mfconn_create_user_signature(mfconn, username, password, app_id, app_key);
user_signature = mfconn_create_user_signature(conn, username, password, app_id, app_key);
post_args = strdup_printf(
"email=%s"
@@ -70,9 +70,9 @@ mfconn_api_user_get_session_token(mfconn_t *mfconn, char *server,
"&response_format=json",
username, password, user_signature);
http_t *conn = http_create();
retval = http_post_buf(conn, login_url, post_args, _decode_get_session_token, (void *)(&response));
http_destroy(conn);
mfhttp *http = http_create();
retval = http_post_buf(http, login_url, post_args, _decode_get_session_token, (void *)(&response));
http_destroy(http);
free(login_url);
free(post_args);
@@ -85,7 +85,7 @@ mfconn_api_user_get_session_token(mfconn_t *mfconn, char *server,
}
static int
_decode_get_session_token(http_t *conn, void *user_ptr)
_decode_get_session_token(mfhttp *conn, void *user_ptr)
{
json_error_t error;
json_t *root = NULL;
@@ -133,7 +133,7 @@ _decode_get_session_token(http_t *conn, void *user_ptr)
// sample user callback
/*
static void
_mycallback(char *data,size_t sz,cfile_t *cfile)
_mycallback(char *data,size_t sz,cmffile *cfile)
{
double bytes_read;
double bytes_total;

View File

@@ -37,18 +37,18 @@ struct _file_s
char *onetime_link;
};
file_t*
mffile*
file_alloc(void)
{
file_t *file;
mffile *file;
file = (file_t*)calloc(1,sizeof(file_t));
file = (mffile*)calloc(1,sizeof(mffile));
return file;
}
void
file_free(file_t *file)
file_free(mffile *file)
{
if(file == NULL) return;
@@ -62,7 +62,7 @@ file_free(file_t *file)
}
int
file_set_key(file_t *file,const char *key)
file_set_key(mffile *file,const char *key)
{
int len;
@@ -79,7 +79,7 @@ file_set_key(file_t *file,const char *key)
}
const char*
file_get_key(file_t *file)
file_get_key(mffile *file)
{
if(file == NULL) return NULL;
@@ -87,7 +87,7 @@ file_get_key(file_t *file)
}
int
file_set_hash(file_t *file,const char *hash)
file_set_hash(mffile *file,const char *hash)
{
if(file == NULL) return -1;
if(hash == NULL) return -1;
@@ -102,7 +102,7 @@ file_set_hash(file_t *file,const char *hash)
}
const char*
file_get_hash(file_t *file)
file_get_hash(mffile *file)
{
if(file == NULL) return NULL;
@@ -110,7 +110,7 @@ file_get_hash(file_t *file)
}
int
file_set_name(file_t *file,const char *name)
file_set_name(mffile *file,const char *name)
{
if(file == NULL) return -1;
if(name == NULL) return -1;
@@ -124,7 +124,7 @@ file_set_name(file_t *file,const char *name)
}
const char*
file_get_name(file_t *file)
file_get_name(mffile *file)
{
if(file == NULL) return NULL;
@@ -132,7 +132,7 @@ file_get_name(file_t *file)
}
int
file_set_share_link(file_t *file,const char *share_link)
file_set_share_link(mffile *file,const char *share_link)
{
if(file == NULL) return -1;
if(share_link == NULL) return -1;
@@ -149,7 +149,7 @@ file_set_share_link(file_t *file,const char *share_link)
}
const char*
file_get_share_link(file_t *file)
file_get_share_link(mffile *file)
{
if(file == NULL) return NULL;
@@ -157,7 +157,7 @@ file_get_share_link(file_t *file)
}
int
file_set_direct_link(file_t *file,const char *direct_link)
file_set_direct_link(mffile *file,const char *direct_link)
{
if(file == NULL) return -1;
if(direct_link == NULL) return -1;
@@ -174,7 +174,7 @@ file_set_direct_link(file_t *file,const char *direct_link)
}
const char*
file_get_direct_link(file_t *file)
file_get_direct_link(mffile *file)
{
if(file == NULL) return NULL;
@@ -182,7 +182,7 @@ file_get_direct_link(file_t *file)
}
int
file_set_onetime_link(file_t *file,const char *onetime_link)
file_set_onetime_link(mffile *file,const char *onetime_link)
{
if(file == NULL) return -1;
if(onetime_link == NULL) return -1;
@@ -199,7 +199,7 @@ file_set_onetime_link(file_t *file,const char *onetime_link)
}
const char*
file_get_onetime_link(file_t *file)
file_get_onetime_link(mffile *file)
{
if(file == NULL) return NULL;
@@ -222,7 +222,7 @@ file_get_onetime_link(file_t *file)
#include "../utils/strings.h"
ssize_t
file_download_direct(file_t *file, char *local_dir)
file_download_direct(mffile *file, char *local_dir)
{
const char *url;
const char *file_name;
@@ -246,7 +246,7 @@ file_download_direct(file_t *file, char *local_dir)
else
file_path = strdup_printf("%s/%s",local_dir,file_name);
http_t *conn = http_create();
mfhttp *conn = http_create();
retval = http_get_file(conn, url, file_path);
http_destroy(conn);

View File

@@ -20,38 +20,38 @@
#ifndef __MFAPI_FILE_H__
#define __MFAPI_FILE_H__
typedef struct _file_s file_t;
typedef struct _file_s mffile;
struct _file_s;
file_t* file_alloc(void);
mffile* file_alloc(void);
void file_free(file_t *file);
void file_free(mffile *file);
int file_set_key(file_t *file,const char *quickkey);
int file_set_key(mffile *file,const char *quickkey);
const char* file_get_key(file_t *file);
const char* file_get_key(mffile *file);
int file_set_hash(file_t *file,const char *hash);
int file_set_hash(mffile *file,const char *hash);
const char* file_get_hash(file_t *file);
const char* file_get_hash(mffile *file);
int file_set_name(file_t *file,const char *name);
int file_set_name(mffile *file,const char *name);
const char* file_get_name(file_t *file);
const char* file_get_name(mffile *file);
int file_set_share_link(file_t *file,const char *share_link);
int file_set_share_link(mffile *file,const char *share_link);
const char* file_get_share_link(file_t *file);
const char* file_get_share_link(mffile *file);
int file_set_direct_link(file_t *file,const char *direct_link);
int file_set_direct_link(mffile *file,const char *direct_link);
const char* file_get_direct_link(file_t *file);
const char* file_get_direct_link(mffile *file);
int file_set_onetime_link(file_t *file,const char *onetime_link);
int file_set_onetime_link(mffile *file,const char *onetime_link);
const char* file_get_onetime_link(file_t *file);
const char* file_get_onetime_link(mffile *file);
ssize_t file_download_direct(file_t *file, char *local_dir);
ssize_t file_download_direct(mffile *file, char *local_dir);
#endif

View File

@@ -34,18 +34,18 @@ struct _folder_s
uint32_t file_count;
};
folder_t*
mffolder*
folder_alloc(void)
{
folder_t *folder;
mffolder *folder;
folder = (folder_t*)calloc(1,sizeof(folder_t));
folder = (mffolder*)calloc(1,sizeof(mffolder));
return folder;
}
void
folder_free(folder_t *folder)
folder_free(mffolder *folder)
{
if(folder == NULL) return;
@@ -55,7 +55,7 @@ folder_free(folder_t *folder)
}
int
folder_set_key(folder_t *folder,const char *key)
folder_set_key(mffolder *folder,const char *key)
{
if(folder == NULL) return -1;
if(key == NULL) return -1;
@@ -69,7 +69,7 @@ folder_set_key(folder_t *folder,const char *key)
}
const char*
folder_get_key(folder_t *folder)
folder_get_key(mffolder *folder)
{
if(folder == NULL) return NULL;
@@ -77,7 +77,7 @@ folder_get_key(folder_t *folder)
}
int
folder_set_parent(folder_t *folder,const char *parent_key)
folder_set_parent(mffolder *folder,const char *parent_key)
{
if(folder == NULL) return -1;
if(parent_key == NULL) return -1;
@@ -94,7 +94,7 @@ folder_set_parent(folder_t *folder,const char *parent_key)
}
const char*
folder_get_parent(folder_t *folder)
folder_get_parent(mffolder *folder)
{
if(folder == NULL) return NULL;
@@ -102,7 +102,7 @@ folder_get_parent(folder_t *folder)
}
int
folder_set_name(folder_t *folder,const char *name)
folder_set_name(mffolder *folder,const char *name)
{
if(folder == NULL) return -1;
if(name == NULL) return -1;
@@ -116,7 +116,7 @@ folder_set_name(folder_t *folder,const char *name)
}
const char*
folder_get_name(folder_t *folder)
folder_get_name(mffolder *folder)
{
if(folder == NULL) return NULL;

View File

@@ -20,24 +20,24 @@
#ifndef __MFAPI_FOLDER_H__
#define __MFAPI_FOLDER_H__
typedef struct _folder_s folder_t;
typedef struct _folder_s mffolder;
struct _folder_s;
folder_t* folder_alloc(void);
mffolder* folder_alloc(void);
void folder_free(folder_t *folder);
void folder_free(mffolder *folder);
int folder_set_key(folder_t *folder,const char *folderkey);
int folder_set_key(mffolder *folder,const char *folderkey);
const char* folder_get_key(folder_t *folder);
const char* folder_get_key(mffolder *folder);
int folder_set_parent(folder_t *folder,const char *folderkey);
int folder_set_parent(mffolder *folder,const char *folderkey);
const char* folder_get_parent(folder_t *folder);
const char* folder_get_parent(mffolder *folder);
int folder_set_name(folder_t *folder,const char *name);
int folder_set_name(mffolder *folder,const char *name);
const char* folder_get_name(folder_t *folder);
const char* folder_get_name(mffolder *folder);
#endif

View File

@@ -28,7 +28,7 @@
#include "mfconn.h"
#include "apicalls.h"
struct mfconn_t
struct mfconn
{
char *server;
uint32_t secret_key;
@@ -36,51 +36,51 @@ struct mfconn_t
char *session_token;
};
mfconn_t*
mfconn*
mfconn_create(char *server, char *username, char *password, int app_id, char *app_key)
{
mfconn_t *mfconn;
mfconn *conn;
int retval;
mfconn = (mfconn_t *)calloc(1,sizeof(mfconn_t));
conn = (mfconn *)calloc(1,sizeof(mfconn));
mfconn->server = strdup(server);
retval = mfconn_api_user_get_session_token(mfconn, mfconn->server,
username, password, app_id, app_key, &(mfconn->secret_key),
&(mfconn->secret_time), &(mfconn->session_token));
conn->server = strdup(server);
retval = mfconn_api_user_get_session_token(conn, conn->server,
username, password, app_id, app_key, &(conn->secret_key),
&(conn->secret_time), &(conn->session_token));
if (retval == 0)
return mfconn;
return conn;
else
return NULL;
}
void
mfconn_destroy(mfconn_t *mfconn)
mfconn_destroy(mfconn *conn)
{
free(mfconn->server);
free(mfconn->secret_time);
free(mfconn->session_token);
free(mfconn);
free(conn->server);
free(conn->secret_time);
free(conn->session_token);
free(conn);
}
void
mfconn_update_secret_key(mfconn_t *mfconn)
mfconn_update_secret_key(mfconn *conn)
{
uint64_t new_val;
if(mfconn == NULL) return;
if(conn == NULL) return;
new_val = ((uint64_t)mfconn->secret_key) * 16807;
new_val = ((uint64_t)conn->secret_key) * 16807;
new_val %= 0x7FFFFFFF;
mfconn->secret_key = new_val;
conn->secret_key = new_val;
return;
}
char*
mfconn_create_user_signature(mfconn_t *mfconn, char *username, char *password,
mfconn_create_user_signature(mfconn *conn, char *username, char *password,
int app_id, char *app_key)
{
char *signature_raw;
@@ -88,7 +88,7 @@ mfconn_create_user_signature(mfconn_t *mfconn, char *username, char *password,
char signature_hex[41];
int i;
if(mfconn == NULL) return NULL;
if(conn == NULL) return NULL;
signature_raw = strdup_printf("%s%s%d%s",
username, password, app_id, app_key);
@@ -108,7 +108,7 @@ mfconn_create_user_signature(mfconn_t *mfconn, char *username, char *password,
}
char*
mfconn_create_call_signature(mfconn_t *mfconn,char *url,char *args)
mfconn_create_call_signature(mfconn *conn,char *url,char *args)
{
char *signature_raw;
unsigned char signature_enc[16]; // md5 is 128 bits
@@ -116,7 +116,7 @@ mfconn_create_call_signature(mfconn_t *mfconn,char *url,char *args)
char *api;
int i;
if(mfconn == NULL) return NULL;
if(conn == NULL) return NULL;
if(url == NULL) return NULL;
if(args == NULL) return NULL;
@@ -127,8 +127,8 @@ mfconn_create_call_signature(mfconn_t *mfconn,char *url,char *args)
if(api == NULL) return NULL;
signature_raw = strdup_printf("%d%s%s%s",
(mfconn->secret_key % 256),
mfconn->secret_time,
(conn->secret_key % 256),
conn->secret_time,
api,args);
MD5((const unsigned char *)signature_raw,
@@ -146,7 +146,7 @@ mfconn_create_call_signature(mfconn_t *mfconn,char *url,char *args)
}
char*
mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
mfconn_create_signed_get(mfconn *conn,int ssl,char *api,char *fmt,...)
{
char *api_request = NULL;
char *api_args = NULL;
@@ -158,10 +158,10 @@ mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
int api_len;
va_list ap;
if(mfconn == NULL) return NULL;
if(mfconn->server == NULL) return NULL;
if(mfconn->secret_time == NULL) return NULL;
if(mfconn->session_token == NULL) return NULL;
if(conn == NULL) return NULL;
if(conn->server == NULL) return NULL;
if(conn->secret_time == NULL) return NULL;
if(conn->session_token == NULL) return NULL;
// make sure the api (ex: user/get_info.php) is sane
if(api == NULL) return NULL;
@@ -173,7 +173,7 @@ mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
api_args_len = (vsnprintf(NULL, 0, fmt, ap) + 1); // + 1 for NULL
va_end(ap);
session_token = strdup_printf("&session_token=%s", mfconn->session_token);
session_token = strdup_printf("&session_token=%s", conn->session_token);
api_args_len += strlen(session_token);
@@ -193,9 +193,9 @@ mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
if(api[api_len - 1] == '/') api[api_len - 1] = '\0';
api_request = strdup_printf("%s//%s/api/%s",
(ssl ? "https:" : "http:"), mfconn->server,api);
(ssl ? "https:" : "http:"), conn->server,api);
call_hash = mfconn_create_call_signature(mfconn,api_request,api_args);
call_hash = mfconn_create_call_signature(conn,api_request,api_args);
signature = strdup_printf("&signature=%s",call_hash);
free(call_hash);
@@ -217,19 +217,19 @@ mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
}
const char*
mfconn_get_session_token(mfconn_t *mfconn)
mfconn_get_session_token(mfconn *conn)
{
return mfconn->session_token;
return conn->session_token;
}
const char*
mfconn_get_secret_time(mfconn_t *mfconn)
mfconn_get_secret_time(mfconn *conn)
{
return mfconn->secret_time;
return conn->secret_time;
}
uint32_t
mfconn_get_secret_key(mfconn_t *mfconn)
mfconn_get_secret_key(mfconn *conn)
{
return mfconn->secret_key;
return conn->secret_key;
}

View File

@@ -23,24 +23,24 @@
#include "file.h"
typedef struct mfconn_t mfconn_t;
typedef struct mfconn mfconn;
mfconn_t* mfconn_create(char *server, char *username, char *password, int app_id, char *app_key);
mfconn* mfconn_create(char *server, char *username, char *password, int app_id, char *app_key);
void mfconn_destroy(mfconn_t *mfconn);
void mfconn_destroy(mfconn *conn);
ssize_t mfconn_download_direct(file_t *file,char *local_dir);
ssize_t mfconn_download_direct(mffile *file,char *local_dir);
char* mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...);
char* mfconn_create_signed_get(mfconn *conn,int ssl,char *api,char *fmt,...);
char* mfconn_create_user_signature(mfconn_t *mfconn, char *username,
char* mfconn_create_user_signature(mfconn *conn, char *username,
char *password, int app_id, char *app_key);
void mfconn_update_secret_key(mfconn_t *mfconn);
void mfconn_update_secret_key(mfconn *conn);
const char* mfconn_get_session_token(mfconn_t *mfconn);
const char* mfconn_get_session_token(mfconn *conn);
const char* mfconn_get_secret_time(mfconn_t *mfconn);
const char* mfconn_get_secret_time(mfconn *conn);
uint32_t mfconn_get_secret_key(mfconn_t *mfconn);
uint32_t mfconn_get_secret_key(mfconn *conn);
#endif