mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
added the framework for supporting new link types in the file-get-links API
This commit is contained in:
@@ -334,7 +334,9 @@ static int filecache_download_file(const char *filecache_path,
|
||||
remote_revision);
|
||||
|
||||
file = file_alloc();
|
||||
retval = mfconn_api_file_get_links(conn, file, (char *)quickkey);
|
||||
retval = mfconn_api_file_get_links(conn, file,
|
||||
(char *)quickkey,
|
||||
LINK_TYPE_DIRECT_DOWNLOAD);
|
||||
|
||||
if (retval != 0) {
|
||||
fprintf(stderr, "mfconn_api_file_get_links failed\n");
|
||||
|
||||
@@ -22,6 +22,14 @@
|
||||
|
||||
#include "../utils/http.h"
|
||||
|
||||
#define X_LINK_TYPE(a,b,c) c,
|
||||
const char *link_types[]={
|
||||
#include "link_type.def"
|
||||
NULL
|
||||
};
|
||||
#undef X_LINK_TYPE
|
||||
|
||||
|
||||
int mfapi_check_response(json_t * response, const char *apicall)
|
||||
{
|
||||
json_t *j_obj;
|
||||
|
||||
@@ -43,6 +43,13 @@ enum mfconn_device_change_type {
|
||||
MFCONN_DEVICE_CHANGE_END
|
||||
};
|
||||
|
||||
#define X_LINK_TYPE(a,b,c) a,
|
||||
enum {
|
||||
#include "link_type.def"
|
||||
};
|
||||
#undef X_LINK_TYPE
|
||||
|
||||
|
||||
struct mfconn_device_change {
|
||||
enum mfconn_device_change_type change;
|
||||
char key[16];
|
||||
@@ -58,7 +65,8 @@ int mfconn_api_file_get_info(mfconn * conn, mffile * file,
|
||||
const char *quickkey);
|
||||
|
||||
int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||
const char *quickkey);
|
||||
const char *quickkey,
|
||||
uint32_t link_mask);
|
||||
|
||||
int mfconn_api_file_move(mfconn * conn, const char *quickkey,
|
||||
const char *folderkey);
|
||||
|
||||
@@ -23,20 +23,24 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "../../utils/http.h"
|
||||
#include "../../utils/strings.h"
|
||||
#include "../mfconn.h"
|
||||
#include "../file.h"
|
||||
#include "../apicalls.h" // IWYU pragma: keep
|
||||
|
||||
|
||||
static int _decode_file_get_links(mfhttp * conn, void *data);
|
||||
|
||||
int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||
const char *quickkey)
|
||||
const char *quickkey,uint32_t link_mask)
|
||||
{
|
||||
const char *api_call;
|
||||
int retval;
|
||||
int len;
|
||||
mfhttp *http;
|
||||
int i;
|
||||
const char *api_call;
|
||||
extern const char *link_types[]; // declared in apicalls.c
|
||||
char *link_params = NULL;
|
||||
int retval;
|
||||
int len;
|
||||
mfhttp *http;
|
||||
int i;
|
||||
|
||||
if (conn == NULL)
|
||||
return -1;
|
||||
@@ -52,13 +56,18 @@ int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||
if (len != 11 && len != 15)
|
||||
return -1;
|
||||
|
||||
link_params = strdup_printf("link_type=%s",
|
||||
link_types[link_mask]);
|
||||
|
||||
for (i = 0; i < mfconn_get_max_num_retries(conn); i++) {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "file/get_links.php",
|
||||
"?quick_key=%s"
|
||||
"&link_type=direct_download"
|
||||
"&response_format=json", quickkey);
|
||||
"&%s"
|
||||
"&response_format=json",
|
||||
link_params, quickkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
if(link_params != NULL) free(link_params);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -86,6 +95,8 @@ int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||
}
|
||||
}
|
||||
|
||||
if(link_params != NULL) free(link_params);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
41
mfapi/link_type.def
Normal file
41
mfapi/link_type.def
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
x-macro for link type definitions used with the file/get_links as of
|
||||
REST API version 1.2 and higher.
|
||||
|
||||
|
||||
field definitions
|
||||
|
||||
field 1 - enumerated name
|
||||
field 2 - bit value
|
||||
field 3 - REST API paramenter string
|
||||
*/
|
||||
|
||||
X_LINK_TYPE(LINK_TYPE_SHARING, (1 << 0), "normal_download")
|
||||
X_LINK_TYPE(LINK_TYPE_DIRECT_DOWNLOAD, (1 << 1), "direct_download")
|
||||
X_LINK_TYPE(LINK_TYPE_VIEW, (1 << 2), "view")
|
||||
X_LINK_TYPE(LINK_TYPE_EDIT, (1 << 3), "edit")
|
||||
X_LINK_TYPE(LINK_TYPE_WATCH, (1 << 4), "watch")
|
||||
X_LINK_TYPE(LINK_TYPE_LISTEN, (1 << 5), "listen")
|
||||
X_LINK_TYPE(LINK_TYPE_STREAMING, (1 << 6), "streaming")
|
||||
|
||||
X_LINK_TYPE(LINK_TYPE_ONE_TIME_DOWNLOAD, (1 << 16), "one_time_download")
|
||||
|
||||
@@ -78,7 +78,9 @@ int mfshell_cmd_get(mfshell * mfshell, int argc, char *const argv[])
|
||||
return -1;
|
||||
}
|
||||
// request a direct download (streaming) link
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file,
|
||||
(char *)quickkey,
|
||||
LINK_TYPE_DIRECT_DOWNLOAD);
|
||||
|
||||
if (retval != 0) {
|
||||
file_free(file);
|
||||
|
||||
@@ -59,7 +59,11 @@ int mfshell_cmd_links(mfshell * mfshell, int argc, char *const argv[])
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
|
||||
// when the lower-level call gets updated to support multiple link types
|
||||
// this should be updated.
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file,
|
||||
(char *)quickkey,
|
||||
LINK_TYPE_DIRECT_DOWNLOAD);
|
||||
if (retval != 0) {
|
||||
fprintf(stderr, "api call unsuccessful\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user