added the framework for supporting new link types in the file-get-links API

This commit is contained in:
root
2014-12-27 22:26:24 -06:00
parent 59e7fe33f9
commit 53e85e0de1
7 changed files with 88 additions and 12 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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
View 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")