Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: FlashAir_Twitter CyaSSL-Twitter-OAuth4Tw TweetTest NetworkThermometer ... more
Fork of OAuth4Tw by
oauth_http.cpp@2:a057c813fb02, 2014-12-15 (annotated)
- Committer:
- ban4jp
- Date:
- Mon Dec 15 12:24:37 2014 +0000
- Revision:
- 2:a057c813fb02
- Parent:
- 1:0036880e6f71
remove debug code.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| takahashim | 0:0048b264a3ad | 1 | /* |
| takahashim | 0:0048b264a3ad | 2 | * OAuth http functions in POSIX-C. |
| takahashim | 0:0048b264a3ad | 3 | * |
| takahashim | 0:0048b264a3ad | 4 | * Copyright 2007, 2008, 2009, 2010 Robin Gareus <robin@gareus.org> |
| takahashim | 0:0048b264a3ad | 5 | * |
| takahashim | 0:0048b264a3ad | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| takahashim | 0:0048b264a3ad | 7 | * of this software and associated documentation files (the "Software"), to deal |
| takahashim | 0:0048b264a3ad | 8 | * in the Software without restriction, including without limitation the rights |
| takahashim | 0:0048b264a3ad | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| takahashim | 0:0048b264a3ad | 10 | * copies of the Software, and to permit persons to whom the Software is |
| takahashim | 0:0048b264a3ad | 11 | * furnished to do so, subject to the following conditions: |
| takahashim | 0:0048b264a3ad | 12 | * |
| takahashim | 0:0048b264a3ad | 13 | * The above copyright notice and this permission notice shall be included in |
| takahashim | 0:0048b264a3ad | 14 | * all copies or substantial portions of the Software. |
| takahashim | 0:0048b264a3ad | 15 | * |
| takahashim | 0:0048b264a3ad | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| takahashim | 0:0048b264a3ad | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| takahashim | 0:0048b264a3ad | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| takahashim | 0:0048b264a3ad | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| takahashim | 0:0048b264a3ad | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| takahashim | 0:0048b264a3ad | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| takahashim | 0:0048b264a3ad | 22 | * THE SOFTWARE. |
| takahashim | 0:0048b264a3ad | 23 | * |
| takahashim | 0:0048b264a3ad | 24 | */ |
| takahashim | 0:0048b264a3ad | 25 | #if HAVE_CONFIG_H |
| takahashim | 0:0048b264a3ad | 26 | # include <config.h> |
| takahashim | 0:0048b264a3ad | 27 | #endif |
| takahashim | 0:0048b264a3ad | 28 | |
| takahashim | 0:0048b264a3ad | 29 | #include <stdio.h> |
| takahashim | 0:0048b264a3ad | 30 | #include <stdarg.h> |
| takahashim | 0:0048b264a3ad | 31 | #include <stdlib.h> |
| takahashim | 0:0048b264a3ad | 32 | #include <string.h> |
| takahashim | 0:0048b264a3ad | 33 | |
| takahashim | 0:0048b264a3ad | 34 | #include "oauth.h" |
| takahashim | 0:0048b264a3ad | 35 | |
| takahashim | 0:0048b264a3ad | 36 | #include <HTTPClient.h> |
| ban4jp | 1:0036880e6f71 | 37 | #include "HTTPPostText.h" |
| ban4jp | 1:0036880e6f71 | 38 | |
| ban4jp | 1:0036880e6f71 | 39 | static char res_buffer[1024] = ""; |
| takahashim | 0:0048b264a3ad | 40 | |
| takahashim | 0:0048b264a3ad | 41 | /* wrapper functions */ |
| takahashim | 0:0048b264a3ad | 42 | |
| takahashim | 0:0048b264a3ad | 43 | /** |
| takahashim | 0:0048b264a3ad | 44 | * do a HTTP POST request, wait for it to finish |
| takahashim | 0:0048b264a3ad | 45 | * and return the content of the reply. |
| takahashim | 0:0048b264a3ad | 46 | * (requires libcurl or a command-line HTTP client) |
| takahashim | 0:0048b264a3ad | 47 | * |
| takahashim | 0:0048b264a3ad | 48 | * more documentation in oauth.h |
| takahashim | 0:0048b264a3ad | 49 | * |
| takahashim | 0:0048b264a3ad | 50 | * @param u url to query |
| takahashim | 0:0048b264a3ad | 51 | * @param p postargs to send along with the HTTP request. |
| takahashim | 0:0048b264a3ad | 52 | * @return In case of an error NULL is returned; otherwise a pointer to the |
| takahashim | 0:0048b264a3ad | 53 | * replied content from HTTP server. latter needs to be freed by caller. |
| takahashim | 0:0048b264a3ad | 54 | */ |
| takahashim | 0:0048b264a3ad | 55 | std::string oauth_http_post(const char *u, const char *p) |
| takahashim | 0:0048b264a3ad | 56 | { |
| takahashim | 0:0048b264a3ad | 57 | HTTPClient http; |
| ban4jp | 1:0036880e6f71 | 58 | HTTPPostText req((char *)p, strlen(p) + 1); |
| ban4jp | 1:0036880e6f71 | 59 | HTTPText res(res_buffer, sizeof(res_buffer)); |
| takahashim | 0:0048b264a3ad | 60 | http.post(u, req, &res); |
| ban4jp | 1:0036880e6f71 | 61 | return res_buffer; |
| takahashim | 0:0048b264a3ad | 62 | } |
| takahashim | 0:0048b264a3ad | 63 |
