build with -Wall -Wextra -Werror and fix errors

This commit is contained in:
josch
2014-09-19 09:21:28 +02:00
parent ef3b2aa844
commit b322f68ad2
21 changed files with 66 additions and 24 deletions

View File

@@ -4,9 +4,11 @@ project(mediafire-tools)
add_library(mfapi SHARED mfapi/mfconn.c mfapi/file.c mfapi/folder.c mfapi/apicalls/file_get_info.c mfapi/apicalls/user_get_info.c mfapi/apicalls/file_get_links.c mfapi/apicalls/user_session.c mfapi/apicalls/folder_get_info.c mfapi/apicalls/folder_create.c mfapi/apicalls/folder_get_content.c) add_library(mfapi SHARED mfapi/mfconn.c mfapi/file.c mfapi/folder.c mfapi/apicalls/file_get_info.c mfapi/apicalls/user_get_info.c mfapi/apicalls/file_get_links.c mfapi/apicalls/user_session.c mfapi/apicalls/folder_get_info.c mfapi/apicalls/folder_create.c mfapi/apicalls/folder_get_content.c)
set_target_properties(mfapi PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
add_library(mfutils SHARED utils/http.c utils/json.c utils/strings.c utils/stringv.c) add_library(mfutils SHARED utils/http.c utils/json.c utils/strings.c utils/stringv.c)
set_target_properties(mfutils PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
add_executable(mfshell mfshell/main.c mfshell/mfshell.c mfshell/commands/auth.c mfshell/commands/chdir.c mfshell/commands/debug.c mfshell/commands/file.c mfshell/commands/get.c mfshell/commands/help.c mfshell/commands/host.c mfshell/commands/lcd.c mfshell/commands/links.c mfshell/commands/list.c mfshell/commands/lpwd.c mfshell/commands/mkdir.c mfshell/commands/pwd.c mfshell/commands/whoami.c) add_executable(mfshell mfshell/main.c mfshell/mfshell.c mfshell/commands/auth.c mfshell/commands/chdir.c mfshell/commands/debug.c mfshell/commands/file.c mfshell/commands/get.c mfshell/commands/help.c mfshell/commands/host.c mfshell/commands/lcd.c mfshell/commands/links.c mfshell/commands/list.c mfshell/commands/lpwd.c mfshell/commands/mkdir.c mfshell/commands/pwd.c mfshell/commands/whoami.c)
set_target_properties(mfshell PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
target_link_libraries(mfshell curl ssl crypto jansson mfapi mfutils) target_link_libraries(mfshell curl ssl crypto jansson mfapi mfutils)

View File

@@ -70,7 +70,6 @@ _decode_file_get_info(http_t *conn, void *data)
json_t *quickkey; json_t *quickkey;
json_t *file_hash; json_t *file_hash;
json_t *file_name; json_t *file_name;
json_t *file_folder;
int retval = 0; int retval = 0;
file_t *file; file_t *file;

View File

@@ -43,7 +43,6 @@ mfconn_api_folder_get_content(mfconn_t *mfconn, int mode, folder_t *folder_curr)
{ {
char *api_call; char *api_call;
int retval; int retval;
char *rx_buffer;
char *content_type; char *content_type;
if(mfconn == NULL) return -1; if(mfconn == NULL) return -1;
@@ -96,6 +95,9 @@ _decode_folder_get_content_folders(http_t *conn, void *user_ptr)
int array_sz; int array_sz;
int i = 0; int i = 0;
if (user_ptr != NULL)
return -1;
root = http_parse_buf_json(conn, 0, &error); root = http_parse_buf_json(conn, 0, &error);
/*json_t *result = json_object_by_path(root, "response/action"); /*json_t *result = json_object_by_path(root, "response/action");
@@ -154,6 +156,9 @@ _decode_folder_get_content_files(http_t *conn, void *user_ptr)
int array_sz; int array_sz;
int i = 0; int i = 0;
if (user_ptr != NULL)
return -1;
root = http_parse_buf_json(conn, 0, &error); root = http_parse_buf_json(conn, 0, &error);
node = json_object_by_path(root,"response/folder_content"); node = json_object_by_path(root,"response/folder_content");

View File

@@ -63,6 +63,9 @@ _decode_user_get_info(http_t *conn, void *data)
json_t *first_name; json_t *first_name;
json_t *last_name; json_t *last_name;
if (data != NULL)
return -1;
root = http_parse_buf_json(conn, 0, &error); root = http_parse_buf_json(conn, 0, &error);
node = json_object_by_path(root,"response/user_info"); node = json_object_by_path(root,"response/user_info");

View File

@@ -87,7 +87,7 @@ mfconn_create_user_signature(mfconn_t *mfconn, char *username, char *password,
{ {
char *signature_raw; char *signature_raw;
unsigned char signature_enc[20]; // sha1 is 160 bits unsigned char signature_enc[20]; // sha1 is 160 bits
unsigned char signature_hex[41]; char signature_hex[41];
int i; int i;
if(mfconn == NULL) return NULL; if(mfconn == NULL) return NULL;
@@ -114,7 +114,7 @@ mfconn_create_call_signature(mfconn_t *mfconn,char *url,char *args)
{ {
char *signature_raw; char *signature_raw;
unsigned char signature_enc[16]; // md5 is 128 bits unsigned char signature_enc[16]; // md5 is 128 bits
unsigned char signature_hex[33]; char signature_hex[33];
char *api; char *api;
int i; int i;
@@ -156,7 +156,6 @@ mfconn_create_signed_get(mfconn_t *mfconn,int ssl,char *api,char *fmt,...)
char *call_hash; char *call_hash;
char *session_token; char *session_token;
int bytes_to_alloc; int bytes_to_alloc;
int api_request_len;
int api_args_len; int api_args_len;
int api_len; int api_len;
va_list ap; va_list ap;

View File

@@ -36,7 +36,6 @@ _get_passwd_from_user(void);
int int
mfshell_cmd_auth(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_auth(mfshell_t *mfshell, int argc, char **argv)
{ {
int retval;
char *username; char *username;
char *password; char *password;

View File

@@ -30,6 +30,7 @@
int int
mfshell_cmd_debug(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_debug(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
if (argc != 1) { if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n"); fprintf(stderr, "Invalid number of arguments\n");
return -1; return -1;

View File

@@ -52,6 +52,9 @@ mfshell_cmd_file(mfshell_t *mfshell, int argc, char **argv)
file = file_alloc(); file = file_alloc();
retval = mfconn_api_file_get_info(mfshell->mfconn,file,(char*)quickkey); retval = mfconn_api_file_get_info(mfshell->mfconn,file,(char*)quickkey);
if (retval != 0) {
fprintf(stderr, "api call unsuccessful\n");
}
mfconn_update_secret_key(mfshell->mfconn); mfconn_update_secret_key(mfshell->mfconn);
quickkey = file_get_key(file); quickkey = file_get_key(file);

View File

@@ -80,9 +80,9 @@ mfshell_cmd_get(mfshell_t *mfshell, int argc, char **argv)
getcwd(mfshell->local_working_dir,PATH_MAX); getcwd(mfshell->local_working_dir,PATH_MAX);
} }
retval = file_download_direct(file, mfshell->local_working_dir); bytes_read = file_download_direct(file, mfshell->local_working_dir);
if(retval != -1) if(bytes_read != -1)
printf("\r Downloaded %zd bytes OK!\n\r",bytes_read); printf("\r Downloaded %zd bytes OK!\n\r",bytes_read);
else else
printf("\r\n Download FAILED!\n\r"); printf("\r\n Download FAILED!\n\r");

View File

@@ -28,6 +28,12 @@
int int
mfshell_cmd_help(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_help(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
if (argc != 1) {
fprintf(stderr, "Invalid number of arguments\n");
return -1;
}
printf( printf(
" arguments:\n\r" " arguments:\n\r"
" <optional>\n\r" " <optional>\n\r"
@@ -35,8 +41,8 @@ mfshell_cmd_help(mfshell_t *mfshell, int argc, char **argv)
printf("\n\r"); printf("\n\r");
int column1_width = 0; unsigned int column1_width = 0;
int column2_width = 0; unsigned int column2_width = 0;
_cmd_t* curr_cmd; _cmd_t* curr_cmd;
for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) { for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) {

View File

@@ -53,6 +53,9 @@ mfshell_cmd_links(mfshell_t *mfshell, int argc, char **argv)
file = file_alloc(); file = file_alloc();
retval = mfconn_api_file_get_links(mfshell->mfconn,file,(char*)quickkey); retval = mfconn_api_file_get_links(mfshell->mfconn,file,(char*)quickkey);
if (retval != 0) {
fprintf(stderr, "api call unsuccessful\n");
}
mfconn_update_secret_key(mfshell->mfconn); mfconn_update_secret_key(mfshell->mfconn);
share_link = file_get_share_link(file); share_link = file_get_share_link(file);

View File

@@ -29,6 +29,7 @@
int int
mfshell_cmd_list(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_list(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
int retval; int retval;
const char *folder_curr; const char *folder_curr;

View File

@@ -29,6 +29,7 @@
int int
mfshell_cmd_lpwd(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_lpwd(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
if(mfshell == NULL) return -1; if(mfshell == NULL) return -1;
if (argc != 1) { if (argc != 1) {

View File

@@ -29,6 +29,7 @@
int int
mfshell_cmd_pwd(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_pwd(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
const char *folder_name; const char *folder_name;
char *folder_name_tmp = NULL; char *folder_name_tmp = NULL;

View File

@@ -29,6 +29,7 @@
int int
mfshell_cmd_whoami(mfshell_t *mfshell, int argc, char **argv) mfshell_cmd_whoami(mfshell_t *mfshell, int argc, char **argv)
{ {
(void)argv;
int retval; int retval;
if (argc != 1) { if (argc != 1) {

View File

@@ -35,7 +35,7 @@ mfshell_run(mfshell_t *mfshell);
static void static void
mfshell_parse_commands(mfshell_t *mfshell, char *command); mfshell_parse_commands(mfshell_t *mfshell, char *command);
void print_help(mfshell_t *mfshell, char *cmd) void print_help(char *cmd)
{ {
fprintf(stderr, "A shell to access a MediaFire account.\n"); fprintf(stderr, "A shell to access a MediaFire account.\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@@ -62,7 +62,7 @@ void print_help(mfshell_t *mfshell, char *cmd)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void parse_argv(mfshell_t *mfshell, int argc, char **argv, char **username, void parse_argv(int argc, char **argv, char **username,
char **password, char **server, char **command) char **password, char **server, char **command)
{ {
static struct option long_options[] = { static struct option long_options[] = {
@@ -94,7 +94,7 @@ void parse_argv(mfshell_t *mfshell, int argc, char **argv, char **username,
*server = strdup(optarg); *server = strdup(optarg);
break; break;
case 'h': case 'h':
print_help(mfshell, argv[0]); print_help(argv[0]);
exit(0); exit(0);
case 'v': case 'v':
exit(0); exit(0);
@@ -125,12 +125,10 @@ int main(int argc,char **argv)
char *username = NULL; char *username = NULL;
char *password = NULL; char *password = NULL;
char *command = NULL; char *command = NULL;
size_t len;
int retval;
SSL_library_init(); SSL_library_init();
parse_argv(mfshell, argc, argv, &username, &password, &server, &command); parse_argv(argc, argv, &username, &password, &server, &command);
mfshell = mfshell_create(35860, mfshell = mfshell_create(35860,
"2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",server); "2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",server);
@@ -156,6 +154,15 @@ mfshell_parse_commands(mfshell_t *mfshell, char *command)
while ((next = strsep(&command, ";")) != NULL) { while ((next = strsep(&command, ";")) != NULL) {
// FIXME: handle non-zero return value of wordexp // FIXME: handle non-zero return value of wordexp
ret = wordexp(next, &p, WRDE_SHOWERR | WRDE_UNDEF); ret = wordexp(next, &p, WRDE_SHOWERR | WRDE_UNDEF);
if (ret != 0) {
switch (ret) {
case WRDE_BADCHAR: fprintf(stderr, "wordexp: WRDE_BADCHAR\n"); break;
case WRDE_BADVAL: fprintf(stderr, "wordexp: WRDE_BADVAL\n"); break;
case WRDE_CMDSUB: fprintf(stderr, "wordexp: WRDE_CMDSUB\n"); break;
case WRDE_NOSPACE: fprintf(stderr, "wordexp: WRDE_NOSPACE\n"); break;
case WRDE_SYNTAX: fprintf(stderr, "wordexp: WRDE_SYNTAX\n"); break;
}
}
if (p.we_wordc < 1) { if (p.we_wordc < 1) {
fprintf(stderr, "Need more than zero arguments\n"); fprintf(stderr, "Need more than zero arguments\n");
exit(1); exit(1);

View File

@@ -101,6 +101,7 @@ mfshell_exec(mfshell_t *mfshell, int argc, char **argv)
return curr_cmd->handler(mfshell, argc, argv); return curr_cmd->handler(mfshell, argc, argv);
} }
} }
return -1;
} }
int int
@@ -114,6 +115,15 @@ mfshell_exec_shell_command(mfshell_t *mfshell,char *command)
// FIXME: handle non-zero return value of wordexp // FIXME: handle non-zero return value of wordexp
retval = wordexp(command, &p, WRDE_SHOWERR | WRDE_UNDEF); retval = wordexp(command, &p, WRDE_SHOWERR | WRDE_UNDEF);
if (retval != 0) {
switch (retval) {
case WRDE_BADCHAR: fprintf(stderr, "wordexp: WRDE_BADCHAR\n"); break;
case WRDE_BADVAL: fprintf(stderr, "wordexp: WRDE_BADVAL\n"); break;
case WRDE_CMDSUB: fprintf(stderr, "wordexp: WRDE_CMDSUB\n"); break;
case WRDE_NOSPACE: fprintf(stderr, "wordexp: WRDE_NOSPACE\n"); break;
case WRDE_SYNTAX: fprintf(stderr, "wordexp: WRDE_SYNTAX\n"); break;
}
}
if (p.we_wordc < 1) if (p.we_wordc < 1)
return 0; return 0;

View File

@@ -133,15 +133,14 @@ http_get_buf(http_t *conn, const char *url, int (*data_handler)(http_t *conn, vo
static size_t static size_t
http_read_buf_cb(char *data, size_t size, size_t nmemb, void *user_ptr) http_read_buf_cb(char *data, size_t size, size_t nmemb, void *user_ptr)
{ {
http_t *conn;
size_t data_len; size_t data_len;
if (user_ptr == NULL) return 0; if (user_ptr == NULL) return 0;
conn = (http_t*)user_ptr;
data_len = size*nmemb; data_len = size*nmemb;
if (data_len > 0) { if (data_len > 0) {
fwrite(data, size, nmemb, stderr);
fprintf(stderr, "Not implemented"); fprintf(stderr, "Not implemented");
exit(1); exit(1);
} }
@@ -225,9 +224,11 @@ http_write_file_cb(char *data, size_t size, size_t nmemb, void *user_ptr)
fwrite(data, size, nmemb, conn->stream); fwrite(data, size, nmemb, conn->stream);
fprintf(stderr, "\r %.0f / %.0f", conn->dl_now, conn->dl_len); fprintf(stderr, "\r %.0f / %.0f", conn->dl_now, conn->dl_len);
return size*nmemb;
} }
int /*int
http_post_file(http_t *conn, const char *url, const char *post_args, FILE *fd) http_post_file(http_t *conn, const char *url, const char *post_args, FILE *fd)
{ {
} }*/

View File

@@ -75,7 +75,7 @@ strdup_join(char *string1,char *string2)
char* char*
strdup_subst(char *string,char *token,char *subst,int max) strdup_subst(char *string,char *token,char *subst, unsigned int max)
{ {
size_t string_len = 0; size_t string_len = 0;
size_t subst_len = 0; size_t subst_len = 0;

View File

@@ -26,7 +26,7 @@ char* strdup_printf(char* fmt, ...);
char* strdup_join(char *string1,char *string2); char* strdup_join(char *string1,char *string2);
char* strdup_subst(char *string,char *str_old,char *str_new,int max); char* strdup_subst(char *string,char *str_old,char *str_new, unsigned int max);
void string_chomp(char *string); void string_chomp(char *string);

View File

@@ -133,7 +133,7 @@ stringv_split(char *string,char *token,int limit)
char *curr = NULL; char *curr = NULL;
char *next = NULL; char *next = NULL;
int count = 0; int count = 0;
int len; unsigned int len;
size_t copy_len = 0; size_t copy_len = 0;
if(string == NULL) return (char**)NULL; if(string == NULL) return (char**)NULL;