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