00001 /* 00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net) 00003 This file is part of Beesnest. 00004 Beesnest is released under the GNU General Public License. 00005 But this file is in the public domain, you can do whatever you want with it. 00006 */ 00007 00008 #ifndef __IDC_RESPONSE 00009 #define __IDC_RESPONSE 00010 00011 #include "BufferHolder.h" 00012 00013 /** 00014 * This interface is implemented by Beesnest! <br> 00015 * 00016 * This abstract class is the interface for <b>CdcResponse</b>. The purpose of 00017 * this interface is that an <b>IdcEngine</b> will be able to use some features 00018 * of the Response class. IdcEngine should let a script to set headers and 00019 * cookies, to clear the response and start over, and to send the current 00020 * response buffer (flush) but continue to build it. 00021 * 00022 * <p> 00023 * All interfaces uses BufferHolder to pass strings or buffers. 00024 */ 00025 class IdcResponse 00026 { 00027 public: 00028 00029 /** 00030 * Empty virtual Destructor. 00031 */ 00032 virtual ~IdcResponse () {} 00033 00034 /** 00035 * SetHeadrField lets a script to add a name-value pair to the response 00036 * headers list. 00037 * <p> 00038 * @param name The name of this new response header, as a BufferHolder. 00039 * @param value The value of this header, as a BufferHolder. 00040 */ 00041 virtual void SetResponseHeader (BufferHolder name, BufferHolder value) = 0; 00042 00043 /** 00044 * SetCookie lets a script to add a cookie to the response headers list. 00045 * <p> 00046 * @param name The name of the cookie, as a BufferHolder. 00047 * @param val The value of the cookie, as a BufferHolder. 00048 * @param days The number of days this cookie will be valid. This number 00049 * can be negative (to delete a cookie). 1 is the default. 00050 * @param path The path of this cookie, as a BufferHolder. "/" is the default. 00051 */ 00052 virtual void SetResponseCookie (BufferHolder name, BufferHolder val, 00053 int days = 1, BufferHolder path = BufferHolder ("/")) = 0; 00054 00055 /** 00056 * Clear all data in the response (body and headers), so a script can start 00057 * over. This function does not clear the headers-sent flag, so if the 00058 * Response class has already sent the headers, it will not send them again. 00059 * <br> 00060 * It is the engine responsibility to clear its own buffer. 00061 */ 00062 virtual void Clear () = 0; 00063 00064 /** 00065 * This function will send the part of the response that is already built. 00066 * The class will send the response headers just in the first call to Flush. 00067 * following calls will send just the added response body. <br> 00068 * This function is implementing the Chunk Response protocol. 00069 * <p> 00070 * This function will call Clear to clear all data that has been sent. But, 00071 * it is the engine responsibility to clear its own buffer. 00072 * <p> 00073 * @param buff The current buffer, as a BufferHolder. The script engine 00074 * should pass its current buffer so the class can send it (but it will not 00075 * clear it). 00076 * @return (int) The length of the sent data. 00077 * @throw (int) This function will throw an integer value if the socket 00078 * generate an exception (the user has closed the connection for an instance). 00079 * The value will be the value Beesnest got from it's socket. You will have 00080 * to do whatever you need to close the script engine. If you do catch 00081 * this exception, you will have to throw it back to Beesnest. 00082 */ 00083 virtual int Flush (BufferHolder buff) throw (int) = 0; 00084 00085 }; 00086 00087 #endif /* __IDC_RESPONSE */ 00088