dropbox access

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of SimpleDropbox by wolf SSL

dropbox.cpp

Committer:
thursday1024
Date:
2015-07-22
Revision:
2:3b43fb225342
Parent:
0:b20eee676480

File content as of revision 2:3b43fb225342:

// dropbox.cpp
/* dropbox.c
 * Copyright (C) 2006-2014 wolfSSL Inc.
 * This file is part of CyaSSL.
 * CyaSSL is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * CyaSSL 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 "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"

extern HTTPClient http;

HTTPResult dropbox_get(const char *url, char *buff, int size)
{
    HTTPResult ret ;
#define LOCATION_SIZE 128
    static char location[LOCATION_SIZE] ;
    static const char HeaderLines[] =
        "User-Agent: curl/7.33.0\r\n"
        "Accept: */*\r\n" ;

    http.setHeader(HeaderLines) ;
    http.setLocationBuf(location, LOCATION_SIZE) ;

    ret = http.get(url, buff, size) ;
    if (ret != HTTP_REDIRECT) {
        printf("++ Err = %d - HTTP ret = %d ++\n",
               ret, http.getHTTPResponseCode());
        return ret ;
    }

    ret = http.get(location, buff, size) ;
    if (ret != HTTP_OK) {
        printf("++ Err = %d - HTTP ret = %d ++\n",
               ret, http.getHTTPResponseCode());
        return ret ;
    }
    return HTTP_OK ;
}