Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 1 | // Copyright (C) 2006-2010 David Sugar, Tycho Softworks. |
| 2 | // |
| 3 | // This file is part of GNU uCommon C++. |
| 4 | // |
| 5 | // GNU uCommon C++ is free software: you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU Lesser General Public License as published |
| 7 | // by the Free Software Foundation, either version 3 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // GNU uCommon C++ is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU Lesser General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU Lesser General Public License |
| 16 | // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | #ifndef DEBUG |
| 19 | #define DEBUG |
| 20 | #endif |
| 21 | |
| 22 | #include <ucommon-config.h> |
| 23 | #include <ucommon/secure.h> |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | |
| 27 | using namespace UCOMMON_NAMESPACE; |
| 28 | |
| 29 | int main(int argc, char **argv) |
| 30 | { |
| 31 | const char *proto = "80"; |
| 32 | secure::client_t ctx = NULL; |
| 33 | |
| 34 | if(secure::init()) { |
| 35 | proto = "443"; |
| 36 | ctx = secure::client(); |
| 37 | } |
| 38 | |
| 39 | printf("protocol %s\n", proto); |
| 40 | |
| 41 | if(ctx) |
| 42 | printf("ctx %p %d\n", (void *)ctx, ctx->err()); |
| 43 | |
| 44 | ssl_t ssl(ctx); |
| 45 | ssl.open("www.google.com", proto); |
| 46 | printf("open %d\n", ssl.is_open()); |
| 47 | |
| 48 | ssl.putline("GET /\r\n\r\n"); |
| 49 | ssl.flush(); |
| 50 | |
| 51 | char buf[256]; |
| 52 | |
| 53 | while(!ssl.eof()) { |
| 54 | ssl.getline(buf, sizeof(buf)); |
| 55 | printf("%s\n", buf); |
| 56 | } |
| 57 | |
| 58 | ssl.close(); |
| 59 | } |
| 60 | |
| 61 | |