Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

cookie.cc

00001 /*
00002 *  Name:      cgi_cookie.cc
00003 *  Author:    Francisco Rodrigo Escobedo Robles
00004 *  Summary:   HTTP Cookie handling
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 2000  Francisco Rodrigo Escobedo Robles <frer@pepix.net>
00009 *  Copyright (C) 2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00027 #include <iostream>
00028 #include <mpcl/net/cgi/cookie.hh>
00029 
00030 
00031 //
00032 //  C O N S T R U C T O R S
00033 //
00034 
00035 void mpcl::net::cgi::TCookie::
00036 read (std::basic_istream<char_type, traits_type>& rtSOURCE_ISTREAM)
00037 {
00038 
00039   char   cTmpChar;
00040 
00041   yName  = "";
00042   yValue = "";
00043 
00044   //
00045   //  Skips blank space.
00046   //
00047   while ( ( (cTmpChar = rtSOURCE_ISTREAM.get()) == ' ' ) && rtSOURCE_ISTREAM.good() );
00048 
00049   //
00050   //  Reads the name.
00051   //
00052   if ( cTmpChar != EOF )
00053   {
00054     do
00055     {
00056       yName += cTmpChar;
00057     }
00058     while ( ( (cTmpChar = rtSOURCE_ISTREAM.get()) != '=' ) && rtSOURCE_ISTREAM.good() );
00059     
00060     //
00061     //  Reads the value.
00062     //
00063     while ( ( (cTmpChar = rtSOURCE_ISTREAM.get()) != ';'  ) && 
00064             (  cTmpChar                           != '\n' ) &&
00065             rtSOURCE_ISTREAM.good()                          )
00066     {
00067       yValue += cTmpChar;
00068     }
00069   }
00070 
00071 }  // read()
00072 
00073 
00074 void mpcl::net::cgi::TCookie::
00075 write (std::basic_ostream<char_type, traits_type>& rtTARGET_OSTREAM) const
00076 {
00077 
00078   using std::endl;
00079 
00080   //
00081   //  Minimum data: name and value of the cookie
00082   //
00083   rtTARGET_OSTREAM << "Set-Cookie: " << yName << "=" << yValue;
00084 
00085   //
00086   //  Optional attributes.
00087   //
00088   if ( !tExpires.empty() )
00089   {
00090     rtTARGET_OSTREAM << "; expires=" << tExpires.get ("%a, %d-%b-%Y %H:%M:%S GMT");
00091   }
00092   if ( !yPath.empty() )
00093   {
00094     rtTARGET_OSTREAM << "; path=" << yPath;
00095   }
00096   if ( !yDomain.empty() )
00097   {
00098     rtTARGET_OSTREAM << "; domain=" << yDomain;
00099   }
00100   if ( gSecure )
00101   {
00102     rtTARGET_OSTREAM << "; secure";
00103   }
00104   rtTARGET_OSTREAM << endl;
00105 
00106 }  // write()

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18