allow to pass no api_key when constructing the signature

This commit is contained in:
josch
2014-09-23 18:53:16 +02:00
parent 60e0824f68
commit 036954df35
3 changed files with 23 additions and 7 deletions

View File

@@ -94,8 +94,13 @@ const char *mfconn_create_user_signature(mfconn * conn,
if (conn == NULL) if (conn == NULL)
return NULL; return NULL;
signature_raw = strdup_printf("%s%s%d%s", if (app_key == NULL) {
username, password, app_id, app_key); signature_raw = strdup_printf("%s%s%d",
username, password, app_id);
} else {
signature_raw = strdup_printf("%s%s%d%s",
username, password, app_id, app_key);
}
SHA1((const unsigned char *)signature_raw, SHA1((const unsigned char *)signature_raw,
strlen(signature_raw), signature_enc); strlen(signature_raw), signature_enc);

View File

@@ -21,6 +21,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "../utils/strings.h" #include "../utils/strings.h"
#include "mfshell.h" #include "mfshell.h"
@@ -51,8 +52,12 @@ int main(int argc, char *const argv[])
opts.server = strdup("www.mediafire.com"); opts.server = strdup("www.mediafire.com");
} }
shell = mfshell_create(35860, "2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg", shell = mfshell_create(35860, NULL,
opts.server); opts.server);
if (shell == NULL) {
fprintf(stderr, "cannot create shell\n");
exit(1);
}
// if at least username was set, authenticate automatically // if at least username was set, authenticate automatically
if (opts.username != NULL) { if (opts.username != NULL) {

View File

@@ -56,8 +56,6 @@ mfshell *mfshell_create(int app_id, char *app_key, char *server)
if (app_id <= 0) if (app_id <= 0)
return NULL; return NULL;
if (app_key == NULL)
return NULL;
if (server == NULL) if (server == NULL)
return NULL; return NULL;
@@ -72,7 +70,11 @@ mfshell *mfshell_create(int app_id, char *app_key, char *server)
shell = (mfshell *) calloc(1, sizeof(mfshell)); shell = (mfshell *) calloc(1, sizeof(mfshell));
shell->app_id = app_id; shell->app_id = app_id;
shell->app_key = strdup(app_key); if (app_key == NULL) {
shell->app_key = NULL;
} else {
shell->app_key = strdup(app_key);
}
shell->server = strdup(server); shell->server = strdup(server);
// object to track folder location // object to track folder location
@@ -89,6 +91,9 @@ int mfshell_exec(mfshell * shell, int argc, char *const argv[])
{ {
mfcmd *curr_cmd; mfcmd *curr_cmd;
if (shell == NULL)
return -1;
for (curr_cmd = shell->commands; curr_cmd->name != NULL; curr_cmd++) { for (curr_cmd = shell->commands; curr_cmd->name != NULL; curr_cmd++) {
if (strcmp(argv[0], curr_cmd->name) == 0) { if (strcmp(argv[0], curr_cmd->name) == 0) {
return curr_cmd->handler(shell, argc, argv); return curr_cmd->handler(shell, argc, argv);
@@ -222,7 +227,8 @@ void mfshell_run(mfshell * shell)
void mfshell_destroy(mfshell * shell) void mfshell_destroy(mfshell * shell)
{ {
free(shell->app_key); if (shell->app_key != NULL)
free(shell->app_key);
free(shell->server); free(shell->server);
free(shell->local_working_dir); free(shell->local_working_dir);
folder_free(shell->folder_curr); folder_free(shell->folder_curr);