diff --git a/HttpServer.cpp b/HttpServer.cpp index 7e817d724..a72caa3eb 100644 --- a/HttpServer.cpp +++ b/HttpServer.cpp @@ -136,7 +136,7 @@ bool HttpServer::getDoc ( char *url , long defPort = 80; // check for a secured site TcpServer *tcp = &m_tcp; - if ( strncasecmp(url, "https://", 8) == 0 ) { + if ( url && strncasecmp(url, "https://", 8) == 0 ) { if (!m_ssltcp.m_ready) { // TODO: set an error here log("https: Trying to get HTTPS site when SSL " diff --git a/Msg3a.cpp b/Msg3a.cpp index cb079f0dc..4016186e2 100644 --- a/Msg3a.cpp +++ b/Msg3a.cpp @@ -20,6 +20,10 @@ void Msg3a::constructor ( ) { m_finalBuf = NULL; m_docsToGet = 0; m_numDocIds = 0; + + // need to call all safebuf constructors now to set m_label + m_rbuf2.constructor(); + // NULLify all the reply buffer ptrs for ( long j = 0; j < MAX_INDEXDB_SPLIT; j++ ) m_reply[j] = NULL; diff --git a/Process.cpp b/Process.cpp index 21997e991..4823207d7 100644 --- a/Process.cpp +++ b/Process.cpp @@ -2265,14 +2265,17 @@ void Process::checkFanSwitch ( ) { if ( m_desiredFanState ) // this turns it on - urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&" + if ( !urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&" "command=1&time=%li", - getTimeGlobal()); + getTimeGlobal()) ) + return; else // this turns it off - urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&" + if ( !urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&" "command=0&time=%li", - getTimeGlobal()); + getTimeGlobal()) ) + return; + // . make a cookie with the login info // . on chrome open the console and click "Network" tab // to view the http network requests and replies diff --git a/SafeBuf.cpp b/SafeBuf.cpp index e31d5d843..549d62458 100644 --- a/SafeBuf.cpp +++ b/SafeBuf.cpp @@ -33,6 +33,14 @@ SafeBuf::SafeBuf(long initSize, char *label ) { m_encoding = csUTF8; } +void SafeBuf::constructor ( ) { + m_capacity = 0; + m_length = 0; + m_buf = NULL; + m_usingStack = false; + m_encoding = csUTF8; + m_label = NULL; +} SafeBuf::SafeBuf() { m_capacity = 0; diff --git a/SafeBuf.h b/SafeBuf.h index 6046e54bd..6904dd76c 100644 --- a/SafeBuf.h +++ b/SafeBuf.h @@ -9,6 +9,9 @@ struct SafeBuf { //*TRUCTORS SafeBuf(); SafeBuf(long initSize, char *label = NULL); + + void constructor(); + //be careful with passing in a stackBuf! it could go out //of scope independently of the safebuf. SafeBuf(char* stackBuf, long cap); diff --git a/TcpServer.cpp b/TcpServer.cpp index 588f9e8a5..91440644e 100644 --- a/TcpServer.cpp +++ b/TcpServer.cpp @@ -1657,7 +1657,32 @@ long TcpServer::connectSocket ( TcpSocket *s ) { void TcpServer::destroySocket ( TcpSocket *s ) { if ( ! s ) return ; // sanity check - if ( s->m_udpSlot ) { char *xx=NULL;*xx = 0; } + if ( s->m_udpSlot ) { + log("tcp: sending back error on udp slot err=%s", + mstrerror(g_errno)); + //char *sendBuf = "Error. destroying sock."; + //long sendBufUsed = gbstrlen(sendBuf); + long timeout = 30*1000; + // sen back the error i guess + g_udpServer.sendReply_ass ( NULL,//sendBuf , + 0,//sendBufUsed , + NULL,//sendBuf , + 0,//sendBufSize , + s->m_udpSlot , + timeout , // timeout? + NULL,//state , + NULL );// callback + // we now free the read buffer here since PageDirectory.cpp + // might have reallocated it. + if ( s->m_readBuf ) + mfree (s->m_readBuf, s->m_readBufSize,"TcpUdp"); + // free it! we allocated in HttpServer.cpp handleRequestfd() + mfree ( s , sizeof(TcpSocket) , "tcpudp" ); + // assume did not block + return; + //char *xx=NULL;*xx = 0; } + } + // . you cannot destroy socket's who have called a handler and the // handler is still in progress, because when he's got a reply ready // he expects this TcpSocket to still be there