shinichi satoh / Mbed 2 deprecated dropbox_access

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of SimpleDropbox by wolf SSL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dropbox.cpp Source File

dropbox.cpp

00001 // dropbox.cpp
00002 /* dropbox.c
00003  * Copyright (C) 2006-2014 wolfSSL Inc.
00004  * This file is part of CyaSSL.
00005  * CyaSSL is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * CyaSSL is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00016  */
00017 #include "mbed.h"
00018 #include "EthernetInterface.h"
00019 #include "HTTPClient.h"
00020 
00021 extern HTTPClient http;
00022 
00023 HTTPResult dropbox_get(const char *url, char *buff, int size)
00024 {
00025     HTTPResult ret ;
00026 #define LOCATION_SIZE 128
00027     static char location[LOCATION_SIZE] ;
00028     static const char HeaderLines[] =
00029         "User-Agent: curl/7.33.0\r\n"
00030         "Accept: */*\r\n" ;
00031 
00032     http.setHeader(HeaderLines) ;
00033     http.setLocationBuf(location, LOCATION_SIZE) ;
00034 
00035     ret = http.get(url, buff, size) ;
00036     if (ret != HTTP_REDIRECT) {
00037         printf("++ Err = %d - HTTP ret = %d ++\n",
00038                ret, http.getHTTPResponseCode());
00039         return ret ;
00040     }
00041 
00042     ret = http.get(location, buff, size) ;
00043     if (ret != HTTP_OK) {
00044         printf("++ Err = %d - HTTP ret = %d ++\n",
00045                ret, http.getHTTPResponseCode());
00046         return ret ;
00047     }
00048     return HTTP_OK ;
00049 }
00050  
00051  
00052 
00053 
00054 
00055