Replace cfile.c with connection.c

- cfile.h needed too many function calls and was too complex
 - connection.h does
     - only download in binary mode (json can handle that)
     - have no excess of getters and setters
     - allow to execute the whole request in a single function call
     - allow to be re-used for multiple requests
 - as a result, the code has 600 lines of code less
 - originally, connection.h was developed to use a global curl
   handle for all requests such that the same connection could be
   re-used. Unfortunately the MediaFire servers will close the
   connection after each request from their end:

      Bryan: "Unfortunately, we won't ever do keep-alive.  Closing the
      connection is a small part of a larger set of heuristics we have in
      place to prevent DOS/DDOS attacks."

   This causes massive performance impacts and those grow even larger when
   using SSL because the handshake has to be executed for every single
   request again.
This commit is contained in:
josch
2014-09-17 11:20:23 +02:00
parent fe42b6e668
commit ebedf596db
20 changed files with 346 additions and 974 deletions

View File

@@ -1,5 +1,6 @@
/*
* 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
@@ -27,17 +28,16 @@
#include "mfshell.h"
#include "private.h"
#include "account.h"
#include "cfile.h"
#include "strings.h"
#include "json.h"
#include "connection.h"
static int
_decode_folder_get_info(mfshell_t *mfshell,cfile_t *cfile,folder_t *folder);
_decode_folder_get_info(conn_t *conn, void *data);
int
_folder_get_info(mfshell_t *mfshell,folder_t *folder,char *folderkey)
{
cfile_t *cfile;
char *api_call;
int retval;
@@ -54,33 +54,21 @@ _folder_get_info(mfshell_t *mfshell,folder_t *folder,char *folderkey)
if(strcmp(folderkey,"myfiles") == 0) return -1;
}
// create the object as a sender
cfile = cfile_create();
// take the traditional defaults
cfile_set_defaults(cfile);
api_call = mfshell->create_signed_get(mfshell,0,"folder/get_info.php",
"?folder_key=%s"
"&session_token=%s"
"&response_format=json",
folderkey,mfshell->session_token);
cfile_set_url(cfile,api_call);
retval = cfile_exec(cfile);
if(retval != CURLE_OK) printf("error %d\n\r",retval);
retval = _decode_folder_get_info(mfshell,cfile,folder);
cfile_destroy(cfile);
conn_t *conn = conn_create();
retval = conn_get_buf(conn, api_call, _decode_folder_get_info, folder);
conn_destroy(conn);
return retval;
}
static int
_decode_folder_get_info(mfshell_t *mfshell,cfile_t *cfile,folder_t *folder)
_decode_folder_get_info(conn_t *conn, void *data)
{
json_error_t error;
json_t *root;
@@ -89,11 +77,13 @@ _decode_folder_get_info(mfshell_t *mfshell,cfile_t *cfile,folder_t *folder)
json_t *folder_name;
json_t *parent_folder;
int retval = 0;
folder_t *folder;
if(mfshell == NULL) return -1;
if(cfile == NULL) return -1;
if(data == NULL) return -1;
root = json_loads(cfile_get_rx_buffer(cfile),0,&error);
folder = (folder_t *)data;
root = json_loadb(conn->write_buf, conn->write_buf_len, 0, &error);
node = json_object_by_path(root,"response/folder_info");