File: Cookie.cc

package info (click to toggle)
postman 2.1-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,248 kB
  • ctags: 3,249
  • sloc: cpp: 33,376; ansic: 2,014; sh: 768; makefile: 300
file content (120 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*                                                           
Cookie.cc
*/

#include "Cookie.h"

Cookie::Cookie (const char *user, const char *connid)
  {
  newCookie(connid);
  setSecure(false); 
  setName(user);
  setValue((char *)thecookie.cstr()); 
  setDomain(""); 
  setPath("");   
  }

Cookie::~Cookie()
  {
  }

void Cookie::newCookie (const char *connid)
  {
  char cookie_chars[] = ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
  int i, p;
  char rawid[24 + 1], letra[2];
  TSBuffer abuf;
  
  letra[1] = '\0';
  initStr (rawid);
  for (i = 1; i <= 24; ++i)
    {
    p = (int) Rand(62);
    letra[0] = cookie_chars[p];
    xstrncat (rawid, 24 + 1, letra);
    }
  xstrncpy (abuf, CSMALLBUFFER, connid); 
  xstrncat (abuf, CSMALLBUFFER, "@"); 
  xstrncat (abuf, CSMALLBUFFER, rawid);
  thecookie = abuf;        
  }

const char *Cookie::getSetFullCookieLine(void)
  {
  acook =  getName(); acook += '='; acook += getValue();
  if(fPath.empty() == false) {acook += "; Path="; acook += fPath;}  
  if(fDomain.empty() == false)  {acook += "; Domain="; acook += fDomain;}  
//  acook += "; Expires=Wednesday, 22-Nov-20 09:09:00 GMT";
  if(fSecure == true) {acook += "; Secure";}
  acook += "; Version=1";
  return acook.cstr();
  }

const char *Cookie::getSetClearFullCookieLine(void)
  {
  acook =  getName(); acook += '='; acook += getValue();
  if(fPath.empty() == false) {acook += "; Path="; acook += fPath;}  
  if(fDomain.empty() == false)  {acook += "; Domain="; acook += fDomain;}  
  acook += "; Expires=Wednesday, 22-Nov-00 09:09:00 GMT";
  if(fSecure == true) {acook += "; Secure";}
  acook += "; Version=1";
  return acook.cstr();
  }

const char *Cookie::getName (void)
  { 
  return fName.cstr(); 
  }

const char *Cookie::getValue (void)
  { 
  return fValue.cstr(); 
  }

const char *Cookie::getDomain (void)
  { 
  return fDomain.cstr(); 
  }

const char *Cookie::getPath (void)
  { 
  return fPath.cstr(); 
  }    

bool Cookie::isSecure() const 
  { 
  return fSecure; 
  }

void Cookie::setName(const char *name) 
  { 
  fName = name; 
  }

void Cookie::setValue(const char *value) 
  { 
  fValue = value; 
  }

void Cookie::setDomain(const char *domain) 
  { 
  fDomain = domain; 
  }

void Cookie::setPath(const char *path) 
  { 
  fPath = path; 
  }

void Cookie::setSecure(bool secure) 
  { 
  fSecure = secure; 
  }
  
bool Cookie::isGoodCookie (const char *acookiestring)
  {
  if (strcmp (acookiestring, getValue()) != 0) return false;
  else return true;              
  }