Usage example, Dropbox with wolfSSL

Dependencies:   EthernetInterface HTTPClient SDFileSystem mbed-rtos mbed wolfSSL

Fork of SimpleDropbox by wolf SSL

Committer:
wolfSSL
Date:
Tue Jul 21 23:25:17 2015 +0000
Revision:
3:0bf592148055
Parent:
0:b20eee676480
Dropbox example with wolfSSL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:b20eee676480 1 /* dropbox.c
wolfSSL 0:b20eee676480 2 *
wolfSSL 0:b20eee676480 3 * Copyright (C) 2006-2014 wolfSSL Inc.
wolfSSL 0:b20eee676480 4 *
wolfSSL 0:b20eee676480 5 * This file is part of CyaSSL.
wolfSSL 0:b20eee676480 6 *
wolfSSL 0:b20eee676480 7 * CyaSSL is free software; you can redistribute it and/or modify
wolfSSL 0:b20eee676480 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:b20eee676480 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:b20eee676480 10 * (at your option) any later version.
wolfSSL 0:b20eee676480 11 *
wolfSSL 0:b20eee676480 12 * CyaSSL is distributed in the hope that it will be useful,
wolfSSL 0:b20eee676480 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:b20eee676480 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:b20eee676480 15 * GNU General Public License for more details.
wolfSSL 0:b20eee676480 16 *
wolfSSL 0:b20eee676480 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:b20eee676480 18 * along with this program; if not, write to the Free Software
wolfSSL 0:b20eee676480 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:b20eee676480 20 */
wolfSSL 0:b20eee676480 21
wolfSSL 0:b20eee676480 22 #include "mbed.h"
wolfSSL 0:b20eee676480 23 #include "EthernetInterface.h"
wolfSSL 0:b20eee676480 24 #include "HTTPClient.h"
wolfSSL 0:b20eee676480 25
wolfSSL 0:b20eee676480 26 extern HTTPClient http;
wolfSSL 0:b20eee676480 27
wolfSSL 0:b20eee676480 28 HTTPResult dropbox_get(const char *url, char *buff, int size)
wolfSSL 0:b20eee676480 29 {
wolfSSL 0:b20eee676480 30 HTTPResult ret ;
wolfSSL 0:b20eee676480 31 #define LOCATION_SIZE 128
wolfSSL 0:b20eee676480 32 static char location[LOCATION_SIZE] ;
wolfSSL 0:b20eee676480 33 static const char HeaderLines[] =
wolfSSL 0:b20eee676480 34 "User-Agent: curl/7.33.0\r\n"
wolfSSL 0:b20eee676480 35 "Accept: */*\r\n" ;
wolfSSL 0:b20eee676480 36
wolfSSL 0:b20eee676480 37 http.setHeader(HeaderLines) ;
wolfSSL 0:b20eee676480 38 http.setLocationBuf(location, LOCATION_SIZE) ;
wolfSSL 3:0bf592148055 39 http.dumpReqHeader(true) ;
wolfSSL 3:0bf592148055 40 http.dumpResHeader(true) ;
wolfSSL 3:0bf592148055 41
wolfSSL 0:b20eee676480 42 ret = http.get(url, buff, size) ;
wolfSSL 0:b20eee676480 43 if (ret != HTTP_REDIRECT) {
wolfSSL 0:b20eee676480 44 printf("++ Err = %d - HTTP ret = %d ++\n",
wolfSSL 0:b20eee676480 45 ret, http.getHTTPResponseCode());
wolfSSL 0:b20eee676480 46 return ret ;
wolfSSL 0:b20eee676480 47 }
wolfSSL 0:b20eee676480 48
wolfSSL 3:0bf592148055 49 printf("\nHTTP GET: %s\n\n", location) ;
wolfSSL 3:0bf592148055 50 http.dumpReqHeader(false) ;
wolfSSL 3:0bf592148055 51 http.dumpResHeader(false) ;
wolfSSL 0:b20eee676480 52 ret = http.get(location, buff, size) ;
wolfSSL 0:b20eee676480 53 if (ret != HTTP_OK) {
wolfSSL 0:b20eee676480 54 printf("++ Err = %d - HTTP ret = %d ++\n",
wolfSSL 0:b20eee676480 55 ret, http.getHTTPResponseCode());
wolfSSL 0:b20eee676480 56 return ret ;
wolfSSL 0:b20eee676480 57 }
wolfSSL 0:b20eee676480 58 return HTTP_OK ;
wolfSSL 0:b20eee676480 59 }