Files
mediafire-fuse/folder_create.c
josch ebedf596db 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.
2014-09-17 21:21:20 +02:00

81 lines
2.2 KiB
C

/*
* 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.
*
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include "mfshell.h"
#include "private.h"
#include "account.h"
#include "connection.h"
#include "strings.h"
int
_folder_create(mfshell_t *mfshell,char *parent,char *name)
{
char *api_call;
int retval;
if(mfshell == NULL) return -1;
if(mfshell->user_signature == NULL) return -1;
if(mfshell->session_token == NULL) return -1;
if(name == NULL) return -1;
if(strlen(name) < 1) return -1;
// key must either be 11 chars or "myfiles"
if(parent != NULL)
{
if(strlen(parent) != 13)
{
// if it is myfiles, set paret to NULL
if(strcmp(parent,"myfiles") == 0) parent = NULL;
}
}
if(parent != NULL)
{
api_call = mfshell->create_signed_get(mfshell,0,"folder/create.php",
"?parent_key=%s"
"&foldername=%s"
"&session_token=%s"
"&response_format=json",
parent,name,mfshell->session_token);
}
else
{
api_call = mfshell->create_signed_get(mfshell,0,"folder/create.php",
"?foldername=%s",
"&session_token=%s"
"&response_format=json",
name,mfshell->session_token);
}
conn_t *conn = conn_create();
retval = conn_get_buf(conn, api_call, NULL, NULL);
conn_destroy(conn);
return retval;
}