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://www.mrpt.org/                                |
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 #include <mrpt/utils/TParameters.h>
00034 
00035 namespace mrpt
00036 {
00037         namespace utils
00038         {
00039                 /** A set of useful routines for networking.
00040                   * \ingroup network_grp
00041                   */
00042                 namespace net
00043                 {
00044                         /** \addtogroup network_grp
00045                           * @{ */
00046 
00047                         using std::string;
00048 
00049                         /** Possible returns from a HTTP request.
00050                           */
00051                         enum ERRORCODE_HTTP {
00052                                 erOk = 0,
00053                                 erBadURL,
00054                                 erCouldntConnect,
00055                                 erNotFound,
00056                                 erOtherHTTPError
00057                         };
00058 
00059                         /** Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
00060                           * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
00061                           * \param port The server port, if different from 80.
00062                           * \param extra_headers If provided, the given extra HTTP headers will be sent.
00063                           * \param out_errormsg On exit will contain a description of the error or "Ok".
00064                           * \param out_content The buffer with the retrieved data.
00065                           * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
00066                           * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
00067                           * \param auth_user Send a basic HTTP authorization request with the given user & password.
00068                           * \param auth_pass Send a basic HTTP authorization request with the given user & password.
00069                           *
00070                           * \return The error or success code.
00071                           * \sa mrpt::utils::vectorToBinaryFile
00072                           */
00073                         ERRORCODE_HTTP BASE_IMPEXP
00074                         http_get(
00075                                 const string    &url,
00076                                 vector_byte             &out_content,
00077                                 string                  &out_errormsg,
00078                                 int                             port = 80,
00079                                 const string    &auth_user = string(),
00080                                 const string    &auth_pass = string(),
00081                                 int                             *out_http_responsecode = NULL,
00082                                 mrpt::utils::TParameters<string>  *extra_headers = NULL,
00083                                 mrpt::utils::TParameters<string>  *out_headers = NULL,
00084                                 int  timeout_ms = 1000
00085                                 );
00086 
00087                         /** Perform an HTTP GET operation (version for retrieving the data as text)
00088                           * \param url Must be a simple string of the form "http://<servername>/<relative-address>".
00089                           * \param port The server port, if different from 80.
00090                           * \param extra_headers If provided, the given extra HTTP headers will be sent.
00091                           * \param out_errormsg On exit will contain a description of the error or "Ok".
00092                           * \param out_content The buffer with the retrieved data.
00093                           * \param out_http_responsecode If provided, will hold the HTTP code, eg: 200, 404...
00094                           * \param out_headers If provided, a copy of all the headers returned by the server will be saved here.
00095                           * \param auth_user Send a basic HTTP authorization request with the given user & password.
00096                           * \param auth_pass Send a basic HTTP authorization request with the given user & password.
00097                           *
00098                           * \return The error or success code.
00099                           * \sa mrpt::utils::vectorToBinaryFile
00100                           */
00101                         ERRORCODE_HTTP  BASE_IMPEXP
00102                         http_get(
00103                                 const string    &url,
00104                                 string                  &out_content,
00105                                 string                  &out_errormsg,
00106                                 int                             port = 80,
00107                                 const string    &auth_user = string(),
00108                                 const string    &auth_pass = string(),
00109                                 int                             *out_http_responsecode = NULL,
00110                                 mrpt::utils::TParameters<string>  *extra_headers = NULL,
00111                                 mrpt::utils::TParameters<string>  *out_headers = NULL,
00112                                 int  timeout_ms = 1000
00113                                 );
00114 
00115 
00116                         /** 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.
00117                           *   For example: server_name="www.google.com" -> out_ip="209.85.227.99"
00118                           *
00119                           * \return true on success, false on timeout or other error.
00120                           */
00121                         bool DNS_resolve_async(
00122                                 const std::string &server_name,
00123                                 std::string      &out_ip,
00124                                 const unsigned int timeout_ms = 3000
00125                                 );
00126 
00127                         /** @} */  // end grouping
00128 
00129                 } // End of namespace
00130         } // End of namespace
00131 } // end of namespace
00132 
00133 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011