Files
mediafire-fuse/mfapi/apicalls/device_get_patch.c
josch febb29f75c Add support for updating local cache through patches
- refactor some code:
   - code handling the file cache is now in fuse/filecache.c
   - base36 and base16 encoding and decoding moved to utils/hash.c
 - mfshell: add "updates" command calling device/get_updates
 - add container class to store patch information as mfapi/patch.c
 - apicalls: store more info retrieved by file/get_info
 - apicalls: add device/get_updates
 - apicalls: add device/get_patch
2014-12-01 16:30:32 +01:00

103 lines
2.8 KiB
C

/*
* Copyright (C) 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.
*
*/
#include <jansson.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../mfconn.h"
#include "../patch.h"
#include "../apicalls.h" // IWYU pragma: keep
static int _decode_device_get_patch(mfhttp * conn, void *data);
int mfconn_api_device_get_patch(mfconn * conn, mfpatch * patch,
const char *quickkey, uint64_t source_revision,
uint64_t target_revision)
{
const char *api_call;
int len;
mfhttp *http;
int retval;
if (conn == NULL)
return -1;
if (patch == NULL)
return -1;
if (quickkey == NULL)
return -1;
len = strlen(quickkey);
if (len != 15)
return -1;
api_call = mfconn_create_signed_get(conn, 0, "device/get_patch.php",
"?quick_key=%s"
"&source_revision=%" PRIu64
"&target_revision=%" PRIu64
"&response_format=json", quickkey,
source_revision, target_revision);
http = http_create();
retval = http_get_buf(http, api_call, _decode_device_get_patch,
(void *)patch);
http_destroy(http);
free((void *)api_call);
return retval;
}
static int _decode_device_get_patch(mfhttp * conn, void *data)
{
json_error_t error;
json_t *obj;
mfpatch *patch;
json_t *root;
json_t *node;
if (data == NULL)
return -1;
patch = (mfpatch *) data;
root = http_parse_buf_json(conn, 0, &error);
node = json_object_by_path(root, "response");
obj = json_object_get(node, "patch_hash");
if (obj != NULL)
patch_set_hash(patch, json_string_value(obj));
obj = json_object_get(node, "patch_link");
if (obj != NULL)
patch_set_link(patch, json_string_value(obj));
if (root != NULL)
json_decref(root);
return 0;
}