浏览代码

Cpp implementation for mg_get_cookie().
The user can pass standard strings for cookie name get back the corresponding value.
The method returns the size of the cookie string read.

HariKamath 12 年之前
父节点
当前提交
b28f41fc9f
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 10 0
      include/CivetServer.h
  2. 10 0
      src/CivetServer.cpp

+ 10 - 0
include/CivetServer.h

@@ -151,6 +151,16 @@ public:
      * @returns the handler that matches the requested URI or 0 if none were found.
      * @returns the handler that matches the requested URI or 0 if none were found.
      */
      */
     CivetHandler *getHandler(const char *uri, unsigned urilen) const;
     CivetHandler *getHandler(const char *uri, unsigned urilen) const;
+	
+	/**
+	 * getCookie(const std::string &_cookieName, std::string &_cookieValue)
+	 * @param conn - the 
+	 * @param _cookieName - cookie name to h=get the value from
+	 * @param _cookieValue - cookie value is returned using thiis reference
+	 * @puts the cookie value string that matches the cookie name in the _cookieValue string.
+	 * @returns the size of the cookie value string read.
+	*/
+	int getCookie(struct mg_connection *conn, const std::string &cookieName, std::string &cookieValue);
 
 
 protected:
 protected:
 
 

+ 10 - 0
src/CivetServer.cpp

@@ -153,3 +153,13 @@ void CivetServer::close() {
     uris.clear();
     uris.clear();
 
 
 }
 }
+
+int CivetServer::getCookie(struct mg_connection *conn, const std::string &cookieName, std::string &cookieValue)
+{
+	//Maximum cookie length as per microsoft is 4096. http://msdn.microsoft.com/en-us/library/ms178194.aspx
+	char _cookieValue[4096];
+	const char *cookie = mg_get_header(conn, "Cookie");
+	int lRead = mg_get_cookie(cookie, cookieName.c_str(), _cookieValue, sizeof(_cookieValue));
+	cookieValue = std::string(_cookieValue);
+	return lRead;
+}