Main MRPT website > C++ reference
MRPT logo

net_utils.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  MRPT_NET_UTILS_H
00029 #define  MRPT_NET_UTILS_H
00030 
00031 #include <mrpt/utils/CClientTCPSocket.h>
00032 #include <mrpt/utils/CServerTCPSocket.h>
00033 
00034 namespace mrpt
00035 {
00036         namespace utils
00037         {
00038                 /** A set of useful routines for networking. 
00039                   */
00040                 namespace net
00041                 {
00042                         using std::string;
00043 
00044                         /** Possible returns from a HTTP request.
00045                           */
00046                         enum ERRORCODE_HTTP {
00047                                 erOk = 0,
00048                                 erBadURL,
00049                                 erCouldntConnect,
00050                                 erNotFound,
00051                                 erOtherHTTPError
00052                         };
00053 
00054                         /** Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
00055                           * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
00056                           * \param port The server port, if different from 80.
00057                           * \param extra_headers If provided, the given extra HTTP headers will be sent.
00058                           * \param out_errormsg On exit will contain a description of the error or "Ok".
00059                           * \param out_content The buffer with the retrieved data.
00060                           * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
00061                           * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
00062                           * \param auth_user Send a basic HTTP authorization request with the given user & password.
00063                           * \param auth_pass Send a basic HTTP authorization request with the given user & password. 
00064                           *
00065                           * \return The error or success code.
00066                           * \sa mrpt::utils::vectorToBinaryFile
00067                           */
00068                         ERRORCODE_HTTP BASE_IMPEXP 
00069                         http_get(
00070                                 const string    &url,
00071                                 vector_byte             &out_content,
00072                                 string                  &out_errormsg,
00073                                 int                             port = 80,
00074                                 const string    &auth_user = string(),          
00075                                 const string    &auth_pass = string(),          
00076                                 int                             *out_http_responsecode = NULL,
00077                                 mrpt::utils::TParameters<string>  *extra_headers = NULL,
00078                                 mrpt::utils::TParameters<string>  *out_headers = NULL,
00079                                 int  timeout_ms = 1000
00080                                 ); 
00081 
00082                         /** Perform an HTTP GET operation (version for retrieving the data as text)
00083                           * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
00084                           * \param port The server port, if different from 80.
00085                           * \param extra_headers If provided, the given extra HTTP headers will be sent.
00086                           * \param out_errormsg On exit will contain a description of the error or "Ok".
00087                           * \param out_content The buffer with the retrieved data.
00088                           * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
00089                           * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
00090                           * \param auth_user Send a basic HTTP authorization request with the given user & password.
00091                           * \param auth_pass Send a basic HTTP authorization request with the given user & password. 
00092                           *
00093                           * \return The error or success code.
00094                           * \sa mrpt::utils::vectorToBinaryFile
00095                           */
00096                         ERRORCODE_HTTP  BASE_IMPEXP
00097                         http_get(
00098                                 const string    &url,
00099                                 string                  &out_content,
00100                                 string                  &out_errormsg,
00101                                 int                             port = 80,
00102                                 const string    &auth_user = string(),          
00103                                 const string    &auth_pass = string(),          
00104                                 int                             *out_http_responsecode = NULL,
00105                                 mrpt::utils::TParameters<string>  *extra_headers = NULL,
00106                                 mrpt::utils::TParameters<string>  *out_headers = NULL,
00107                                 int  timeout_ms = 1000
00108                                 );
00109 
00110 
00111                         /** Resolve a server address by its name, returning its IP address as a string - This method has a timeout for the maximum time to wait for the DNS server.
00112                           *   For example: server_name="www.google.com" -> out_ip="209.85.227.99"
00113                           *
00114                           * \return true on success, false on timeout or other error.
00115                           */
00116                         bool DNS_resolve_async(
00117                                 const std::string &server_name,
00118                                 std::string      &out_ip,
00119                                 const unsigned int timeout_ms = 3000
00120                                 );
00121 
00122 
00123                 } // End of namespace
00124         } // End of namespace
00125 } // end of namespace
00126 
00127 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011