ssl.cpp

Example of SSL socket code.

00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #ifndef DEBUG
00019 #define DEBUG
00020 #endif
00021 
00022 #include <ucommon-config.h>
00023 #include <ucommon/secure.h>
00024 
00025 #include <stdio.h>
00026 
00027 using namespace UCOMMON_NAMESPACE;
00028 
00029 int main(int argc, char **argv)
00030 {
00031     const char *proto = "80";
00032     secure::client_t ctx = NULL;
00033 
00034     if(secure::init()) {
00035         proto = "443";
00036         ctx = secure::client();
00037     }
00038 
00039     printf("protocol %s\n", proto);
00040 
00041     if(ctx)
00042         printf("ctx %p %d\n", (void *)ctx, ctx->err());
00043 
00044     ssl_t ssl(ctx);
00045     ssl.open("www.google.com", proto);
00046     printf("open %d\n", ssl.is_open());
00047 
00048     ssl.putline("GET /\r\n\r\n");
00049     ssl.flush();
00050 
00051     char buf[256];
00052 
00053     while(!ssl.eof()) {
00054         ssl.getline(buf, sizeof(buf));
00055         printf("%s\n", buf);
00056     }
00057 
00058     ssl.close();
00059 }
00060 
00061 

Generated on 14 Aug 2013 for UCommon by  doxygen 1.4.7