|
From: CVS C. to T. <the...@li...> - 2011-01-16 03:15:14
|
Revision: 606
http://themis.svn.sourceforge.net/themis/?rev=606&view=rev
Author: z3r0_one
Date: 2011-01-16 03:15:07 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
A few more minor fixes in HTTP/Cookies to prevent crashes due to weird situations, and a bit more cleaning up of unnecessary debug messages.
Modified Paths:
--------------
trunk/themis/framework/connection.cpp
trunk/themis/framework/tcpmanager.cpp
trunk/themis/modules/http/cookieman.cpp
trunk/themis/modules/http/httpv4.cpp
Modified: trunk/themis/framework/connection.cpp
===================================================================
--- trunk/themis/framework/connection.cpp 2011-01-15 23:06:22 UTC (rev 605)
+++ trunk/themis/framework/connection.cpp 2011-01-16 03:15:07 UTC (rev 606)
@@ -97,7 +97,7 @@
}
int32 Connection::ConnectionResult() {
- printf("ConnectionResult\n");
+ //printf("ConnectionResult\n");
return connection_result;
}
bool Connection::NotifiedConnect() {
@@ -167,7 +167,7 @@
nonblocking=async;
}
Connection::~Connection() {
- printf("Connection: Connection to %s is going away.\n",host_name);
+ //printf("Connection: Connection to %s is going away.\n",host_name);
if (!IsBufferEmpty())
EmptyBuffer();
session_id=0;
@@ -202,7 +202,7 @@
void Connection::OwnerRelease() {
BAutolock alock(lock);
if (alock.IsLocked()) {
- printf("Connection::OwnerRelease\n");
+ //printf("Connection::OwnerRelease\n");
owner=NULL;
StopUsing();
NewSession();
@@ -216,7 +216,7 @@
}
void Connection::Connect() {
- printf("Connection::Connect()\n");
+ //printf("Connection::Connect()\n");
BAutolock alock(lock);
if (alock.IsLocked()) {
if (IsConnected()) {
@@ -255,7 +255,7 @@
}
- printf("Connection::Connect() done\n");
+ //printf("Connection::Connect() done\n");
}
void Connection::ConnectionEstablished(){
@@ -263,13 +263,13 @@
if (alock.IsLocked()) {
if (use_ssl) {
int cryptstatus;
- printf("CRYPT_OK: %d\n",CRYPT_OK);
+ //printf("CRYPT_OK: %d\n",CRYPT_OK);
cryptstatus=cryptCreateSession(&cryptSession,CRYPT_UNUSED,CRYPT_SESSION_SSL);
- printf("session creation: %d\n",cryptstatus);
+ //printf("session creation: %d\n",cryptstatus);
cryptstatus=cryptSetAttribute(cryptSession,CRYPT_SESSINFO_NETWORKSOCKET,socket_id);
- printf("passing network socket: %d\n",cryptstatus);
+ //printf("passing network socket: %d\n",cryptstatus);
cryptstatus=cryptSetAttribute(cryptSession,CRYPT_SESSINFO_ACTIVE,1);
- printf("activating session: %d\n",cryptstatus);
+ //printf("activating session: %d\n",cryptstatus);
if (cryptStatusError(cryptstatus))
{
int errorcode,errorstrlen;
@@ -281,7 +281,7 @@
cryptGetAttributeString(cryptSession,CRYPT_ATTRIBUTE_INT_ERRORMESSAGE,errstring,&errorstrlen);
printf("error: %d - %s\n",errorcode,errstring);
delete errstring;
- printf("Closing connection.\n");
+ //printf("Closing connection.\n");
last_error=ERROR_CONNECTION_RESET;
Disconnect();
NotifyDisconnect();
@@ -327,7 +327,7 @@
// if (owner!=NULL)
// owner->ConnectionEstablished(this);
// atomic_add(¬ified_connect,1);
- printf("connection %p: notified connect %ld\n",this,notified_connect);
+ //printf("connection %p: notified connect %ld\n",this,notified_connect);
}
}
@@ -371,7 +371,7 @@
//Error!! Call NetworkableObject's error function.
switch(errno) {
case EWOULDBLOCK:
- printf("Connection::IsConnected Would Block\n");
+ //printf("Connection::IsConnected Would Block\n");
last_error=ERROR_WOULD_BLOCK;
break;
case EINTR:
@@ -549,7 +549,7 @@
return id;
}
int32 Connection::NewSession() {
- printf("[NewSession]\n");
+ //printf("[NewSession]\n");
fflush(stdout);
int32 id=0;
BAutolock alock(lock);
@@ -598,12 +598,12 @@
current->buffer=new Buffer(data,size);
status=B_OK;
lastusedtime=real_time_clock();
- printf("[Connection::AppendData] Buffer is now %Ld bytes long\n",DataSize());
+ //printf("[Connection::AppendData] Buffer is now %Ld bytes long\n",DataSize());
// }
return status;
}
off_t Connection::Receive(void *data, off_t max_size) {
- printf("[Receive]\n");
+ //printf("[Receive]\n");
fflush(stdout);
off_t size=0L;
// BAutolock alock(lock);
@@ -619,10 +619,10 @@
break;
}
bytes=0;
- printf("[Receive] at most %Ld can be read now.\n", max_size-size);
+ //printf("[Receive] at most %Ld can be read now.\n", max_size-size);
bytes=current->buffer->GetData((unsigned char*)data+size,max_size-size);
size+=bytes;
- printf("[Receive] %ld (%Ld) bytes were copied into protocol buffer.\n",bytes,size);
+ //printf("[Receive] %ld (%Ld) bytes were copied into protocol buffer.\n",bytes,size);
prev=current;
current=current->next;
delete prev->buffer;
@@ -632,7 +632,7 @@
buffer_in=current;
lastusedtime=real_time_clock();
session_bytes_out+=size;
- printf("[Connection::Receive] %Ld bytes have been transferred to owner. %Ld bytes left in buffer.\n\n",session_bytes_received,DataSize());
+ //printf("[Connection::Receive] %Ld bytes have been transferred to owner. %Ld bytes left in buffer.\n\n",session_bytes_received,DataSize());
fflush(stdout);
lock.Unlock();
}
@@ -751,7 +751,7 @@
}
void Connection::StartUsing()
{
- printf("Connection::StartUsing beginning.\n");
+ //printf("Connection::StartUsing beginning.\n");
BAutolock alock(lock);
if (alock.IsLocked())
if (in_use==0)
@@ -766,7 +766,7 @@
// atomic_add(¬ified_connect,1);
}
- printf("Connection::StartUsing done.\n");
+ //printf("Connection::StartUsing done.\n");
}
void Connection::StopUsing()
{
Modified: trunk/themis/framework/tcpmanager.cpp
===================================================================
--- trunk/themis/framework/tcpmanager.cpp 2011-01-15 23:06:22 UTC (rev 605)
+++ trunk/themis/framework/tcpmanager.cpp 2011-01-16 03:15:07 UTC (rev 606)
@@ -51,7 +51,7 @@
}
TCPManager::~TCPManager() {
- printf("destroying connections...");
+ //printf("destroying connections...");
fflush(stdout);
if (Connection::CountConnections()>0) {
@@ -66,7 +66,7 @@
}
}
}
- printf("done.\n");
+ //printf("done.\n");
// delete lock;
delete Connection::ListLock;
delete_sem(process_sem_1);
@@ -218,7 +218,7 @@
}
Connection *TCPManager::CreateConnection(NetworkableObject *net_obj,const char *host,uint16 port,bool secure,bool asynch) {
- printf("CreateConnection begun\n");
+ //printf("CreateConnection begun\n");
Connection *connection=NULL;
BAutolock alock(lock);
if (alock.IsLocked()) {
@@ -239,7 +239,7 @@
}
}
if (existing_available) {
- printf("TCP Manager: found available connection for use. (n: %p\tc: %p)\n",net_obj,connection);
+ //printf("TCP Manager: found available connection for use. (n: %p\tc: %p)\n",net_obj,connection);
connection->AssignNetObject(net_obj);
connection->StartUsing();
// connection->Connect();
@@ -252,7 +252,7 @@
}
}
- printf("CreateConnection is done: %p\n",connection);
+ //printf("CreateConnection is done: %p\n",connection);
return connection;
}
void TCPManager::Disconnect(Connection *connection) {
Modified: trunk/themis/modules/http/cookieman.cpp
===================================================================
--- trunk/themis/modules/http/cookieman.cpp 2011-01-15 23:06:22 UTC (rev 605)
+++ trunk/themis/modules/http/cookieman.cpp 2011-01-16 03:15:07 UTC (rev 606)
@@ -136,6 +136,7 @@
// printf("Finding cookie directory...\n");
FindCookieDirectory();
LoadAllCookies();
+ ClearExpiredCookies();
}
CookieManager::~CookieManager() {
@@ -642,7 +643,7 @@
HTTP->AppSettings->FindString(kPrefsSettingsDirectory,&temp);
temp<<"/cookies";
}
- printf("Cookie Directory: %s\n",temp.String() );
+ //printf("Cookie Directory: %s\n",temp.String() );
BEntry ent;
FindCookieDirPoint1:
ent.SetTo(temp.String());
@@ -847,7 +848,7 @@
if( nvpairs[i] == ',' && strchr((nvpairs+i),'=') != NULL)
nvpair_counter++;
}// kick it old school
- printf("name=value pairs: %d\n",nvpair_counter);
+ //printf("name=value pairs: %d\n",nvpair_counter);
cookie_array = new char*[nvpair_counter];
int32 pair_length = 0;
if( nvpair_counter > 1)
@@ -933,7 +934,7 @@
//printf("\t\tcookie attributes: %s\n",attributes[i]);
for(int8 kac = 0; kac < 10; kac++)
{
- if(strncasecmp(attributes[i],known_attributes[kac],min_c(strlen(known_attributes[kac]),strlen(attributes[i]))) == 0)
+ if(attributes[i] != NULL && strncasecmp(attributes[i],known_attributes[kac],min_c(strlen(known_attributes[kac]),strlen(attributes[i]))) == 0)
{
//printf("\t\t\tattrib: %s\n",known_attributes[kac]);
if( strcasecmp(known_attributes[kac],"path") == 0 ) {
@@ -981,7 +982,7 @@
*/
}
else if( strcasecmp(known_attributes[kac],"domain") == 0 ) {
- printf("\t\t\t\tdomain: %s\n",attvalue(attributes[i]));
+ //printf("\t\t\t\tdomain: %s\n",attvalue(attributes[i]));
if( default_cookie->domain != NULL)
{
memset(default_cookie->domain,0,strlen(default_cookie->domain)+1);
@@ -1098,7 +1099,7 @@
if( DuplicatedCookie(new_cookie) )
{
original = FindCookie(new_cookie->name,new_cookie->path, new_cookie->domain);
- printf("found cookie %s, updating value from \"%s\" to \"%s\"\n",new_cookie->name,original->value,new_cookie->value);
+ //printf("found cookie %s, updating value from \"%s\" to \"%s\"\n",new_cookie->name,original->value,new_cookie->value);
if( original->secure == new_cookie->secure )
{
original->discard = new_cookie->discard;
@@ -1213,10 +1214,10 @@
return false;
while (current!=NULL)
{
- if (
- strcmp(cookie->name,current->name)==0 &&
- strcmp(cookie->path,current->path)==0 &&
- strcasecmp(cookie->domain,current->domain)==0 && cookie->secure == current->secure
+ if ( ((cookie->name == NULL && current->name == NULL) ||
+ strcmp(cookie->name,current->name)==0) && ((cookie->path == NULL && current->path == NULL) ||
+ strcmp(cookie->path,current->path)==0) && ((cookie->domain == NULL && current->domain == NULL) ||
+ strcasecmp(cookie->domain,current->domain)==0) && cookie->secure == current->secure
)
{
found=true;
@@ -1348,10 +1349,10 @@
while (cur!=NULL) {
// printf("Expire %s: current time: %ld\texpire time: %ld\tdifference: %2.2f\n",cur->name,currenttime,cur->expiredate,difftime(cur->expiredate,currenttime));
if (cur->session == false && cur->discard == false && cur->expiredate<=currenttime) {
-// printf("The following cookie has expired:\n");
-// PrintCookie(cur);
+ //printf("The following cookie has expired:\n");
+ //PrintCookie(cur);
if (cur==cookie_head) {
- printf("ClearExpiredCookies line 1764: cur %p\n",cur);
+ //printf("ClearExpiredCookies line 1764: cur %p\n",cur);
cookie_head=cookie_head->next;
BEntry ent(&cur->ref);
if (ent.InitCheck() == B_OK && ent.Exists())
@@ -1453,8 +1454,8 @@
if ((cookie->maxage+cookie->datereceived)<=currenttime)
return ValidateFail("Cookie has already expired.");
}
- else if( cookie->discard ) printf("Cookie is marked for discarding.\n");
- else if( cookie->session ) printf("Cookie is a session cookie.\n");
+ //else if( cookie->discard ) printf("Cookie is marked for discarding.\n");
+ //else if( cookie->session ) printf("Cookie is a session cookie.\n");
if (cookie->domain==NULL)
return ValidateFail("Cookie domain is NULL.");
else {
@@ -1507,8 +1508,10 @@
memset(attname,0,B_ATTR_NAME_LENGTH+1);
BNode node(&cookie->ref);
cookie->discard=false;
+ cookie->session = false;
unsigned char *data=NULL;
BString aname;
+ int32 current_time = real_time_clock();
node.Lock();
while (node.GetNextAttrName(attname)==B_OK) {
node.GetAttrInfo(attname,&ai);
@@ -1520,6 +1523,7 @@
}
if (strcasecmp(attname,"Themis:expiredate")==0) {
node.ReadAttr("Themis:expiredate",B_INT32_TYPE,0,&cookie->expiredate,ai.size);
+ cookie->maxage = cookie->expiredate - current_time;
}
}break;
@@ -1625,7 +1629,8 @@
else
{
status_t res = node.RemoveAttr("Themis:cookievalue");
- printf("removal of cookievalue attribute (null cookie value) successful? %s\n", (res == B_OK ? "yes":"no"));
+ //printf("removal of cookievalue attribute (null cookie value) successful? %s\n", (res == B_OK ? "yes":"no"));
+ if( res != B_OK) node.WriteAttr("Themis:cookievalue",B_STRING_TYPE,0,"",1);
}
if (cookie->version==1)
if (cookie->ports!=NULL)
Modified: trunk/themis/modules/http/httpv4.cpp
===================================================================
--- trunk/themis/modules/http/httpv4.cpp 2011-01-15 23:06:22 UTC (rev 605)
+++ trunk/themis/modules/http/httpv4.cpp 2011-01-16 03:15:07 UTC (rev 606)
@@ -1672,10 +1672,12 @@
strcpy(request->header_buffer,data);
} else
{
+ if( eol != NULL) {
int32 Length=strlen(eol)-2;
request->header_buffer=(char*)malloc(Length+1);
memset(request->header_buffer,0,Length+1);
strcpy(request->header_buffer,eol+2);
+ }
}
}
} else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|