GR-peach example of Dropbox shared link access
Dependencies: HTTPClient mbed-rtos-initial-thread-larger-stack mbed-src
Fork of GR-peach-HTTPSClient by
dropbox.cpp@1:2744673f6256, 2014-12-05 (annotated)
- Committer:
- takashikojo
- Date:
- Fri Dec 05 11:42:02 2014 +0000
- Revision:
- 1:2744673f6256
Dropbox Shared Link access example, Initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takashikojo | 1:2744673f6256 | 1 | /* dropbox.c |
takashikojo | 1:2744673f6256 | 2 | * |
takashikojo | 1:2744673f6256 | 3 | * Copyright (C) 2006-2014 wolfSSL Inc. |
takashikojo | 1:2744673f6256 | 4 | * |
takashikojo | 1:2744673f6256 | 5 | * This file is part of CyaSSL. |
takashikojo | 1:2744673f6256 | 6 | * |
takashikojo | 1:2744673f6256 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
takashikojo | 1:2744673f6256 | 8 | * it under the terms of the GNU General Public License as published by |
takashikojo | 1:2744673f6256 | 9 | * the Free Software Foundation; either version 2 of the License, or |
takashikojo | 1:2744673f6256 | 10 | * (at your option) any later version. |
takashikojo | 1:2744673f6256 | 11 | * |
takashikojo | 1:2744673f6256 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
takashikojo | 1:2744673f6256 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
takashikojo | 1:2744673f6256 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
takashikojo | 1:2744673f6256 | 15 | * GNU General Public License for more details. |
takashikojo | 1:2744673f6256 | 16 | * |
takashikojo | 1:2744673f6256 | 17 | * You should have received a copy of the GNU General Public License |
takashikojo | 1:2744673f6256 | 18 | * along with this program; if not, write to the Free Software |
takashikojo | 1:2744673f6256 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
takashikojo | 1:2744673f6256 | 20 | */ |
takashikojo | 1:2744673f6256 | 21 | |
takashikojo | 1:2744673f6256 | 22 | #include "mbed.h" |
takashikojo | 1:2744673f6256 | 23 | #include "EthernetInterface.h" |
takashikojo | 1:2744673f6256 | 24 | #include "HTTPClient.h" |
takashikojo | 1:2744673f6256 | 25 | |
takashikojo | 1:2744673f6256 | 26 | extern HTTPClient http; |
takashikojo | 1:2744673f6256 | 27 | |
takashikojo | 1:2744673f6256 | 28 | HTTPResult dropbox_get(const char *url, char *buff, int size) |
takashikojo | 1:2744673f6256 | 29 | { |
takashikojo | 1:2744673f6256 | 30 | HTTPResult ret ; |
takashikojo | 1:2744673f6256 | 31 | #define LOCATION_SIZE 128 |
takashikojo | 1:2744673f6256 | 32 | static char location[LOCATION_SIZE] ; |
takashikojo | 1:2744673f6256 | 33 | static const char HeaderLines[] = |
takashikojo | 1:2744673f6256 | 34 | "User-Agent: curl/7.33.0\r\n" |
takashikojo | 1:2744673f6256 | 35 | "Accept: */*\r\n" ; |
takashikojo | 1:2744673f6256 | 36 | |
takashikojo | 1:2744673f6256 | 37 | http.setHeader(HeaderLines) ; |
takashikojo | 1:2744673f6256 | 38 | http.setLocationBuf(location, LOCATION_SIZE) ; |
takashikojo | 1:2744673f6256 | 39 | |
takashikojo | 1:2744673f6256 | 40 | ret = http.get(url, buff, size) ; |
takashikojo | 1:2744673f6256 | 41 | if ((ret == HTTP_OK) || (ret == HTTP_REDIRECT)) { |
takashikojo | 1:2744673f6256 | 42 | if(ret == HTTP_REDIRECT) { |
takashikojo | 1:2744673f6256 | 43 | /* goto next */ |
takashikojo | 1:2744673f6256 | 44 | } |
takashikojo | 1:2744673f6256 | 45 | } else { |
takashikojo | 1:2744673f6256 | 46 | printf("++ Err = %d - HTTP ret = %d ++\n", |
takashikojo | 1:2744673f6256 | 47 | ret, http.getHTTPResponseCode()); |
takashikojo | 1:2744673f6256 | 48 | return ret ; |
takashikojo | 1:2744673f6256 | 49 | } |
takashikojo | 1:2744673f6256 | 50 | wait(0.5) ; |
takashikojo | 1:2744673f6256 | 51 | if(ret != HTTP_REDIRECT) { |
takashikojo | 1:2744673f6256 | 52 | printf("No Redirection. Not reached at the contents.") ; |
takashikojo | 1:2744673f6256 | 53 | } else { |
takashikojo | 1:2744673f6256 | 54 | ret = http.get(location, buff, size) ; |
takashikojo | 1:2744673f6256 | 55 | if ((ret == HTTP_OK) || (ret == HTTP_REDIRECT)) { |
takashikojo | 1:2744673f6256 | 56 | /* goto next */ |
takashikojo | 1:2744673f6256 | 57 | } else { |
takashikojo | 1:2744673f6256 | 58 | printf("++ Err = %d - HTTP ret = %d ++\n", |
takashikojo | 1:2744673f6256 | 59 | ret, http.getHTTPResponseCode()); |
takashikojo | 1:2744673f6256 | 60 | return ret ; |
takashikojo | 1:2744673f6256 | 61 | } |
takashikojo | 1:2744673f6256 | 62 | } |
takashikojo | 1:2744673f6256 | 63 | } |