bool sendReply ( void *state ) { GigablastRequest *gr = (GigablastRequest *)state; // in order to see what sites are being added log it, then we can // more easily remove sites from sitesearch.gigablast.com that are // being added but not being searched SafeBuf xb; if ( gr->m_urlsBuf ) { xb.safeTruncateEllipsis ( gr->m_urlsBuf , 200 ); log( LOG_INFO, "http: add url %s (%s)", xb.getBufStart(), mstrerror( g_errno ) ); } char format = gr->m_hr.getReplyFormat(); TcpSocket *sock = gr->m_socket; if ( format == FORMAT_JSON || format == FORMAT_XML ) { bool status = g_httpServer.sendSuccessReply ( gr ); // nuke state mdelete ( gr , sizeof(gr) , "PageAddUrl" ); delete (gr); return status; } int32_t ulen = 0; const char *url = gr->m_urlsBuf; if ( url ) ulen = gbstrlen (url); // re-null it out if just http:// bool printUrl = true; if ( ulen == 0 ) printUrl = false; if ( ! gr->m_urlsBuf ) printUrl = false; if ( ulen==7 && printUrl && !strncasecmp(gr->m_url,"http://",7)) printUrl = false; if ( ulen==8 && printUrl && !strncasecmp(gr->m_url,"https://",8)) printUrl = false; // page is not more than 32k char buf[1024*32+MAX_URL_LEN*2]; SafeBuf sb(buf, 1024*32+MAX_URL_LEN*2); g_pages.printAdminTop ( &sb , sock , &gr->m_hr ); // if there was an error let them know SafeBuf mbuf; if ( g_errno ) { mbuf.safePrintf("<center><font color=red>"); mbuf.safePrintf("Error adding url(s): <b>%s[%i]</b>", mstrerror(g_errno) , g_errno); mbuf.safePrintf("</font></center>"); } else if ( printUrl ) { mbuf.safePrintf("<center><font color=red>"); mbuf.safePrintf("<b><u>"); mbuf.safeTruncateEllipsis(gr->m_urlsBuf,200); mbuf.safePrintf("</u></b></font> added to spider queue successfully<br><br>"); mbuf.safePrintf("</font></center>"); } if ( mbuf.length() ) { sb.safeStrcpy( mbuf.getBufStart() ); } g_parms.printParmTable ( &sb , sock , &gr->m_hr ); // print the final tail g_pages.printTail ( &sb, true ); // admin? // clear g_errno, if any, so our reply send goes through g_errno = 0; // nuke state mdelete ( gr , sizeof(GigablastRequest) , "PageAddUrl" ); delete (gr); return g_httpServer.sendDynamicPage( sock, sb.getBufStart(), sb.length(), -1 ); // cachetime }
bool sendReply ( void *state , bool addUrlEnabled ) { // allow others to add now //s_inprogress = false; // get the state properly //gr *st1 = (gr *) state; GigablastRequest *gr = (GigablastRequest *)state; // in order to see what sites are being added log it, then we can // more easily remove sites from sitesearch.gigablast.com that are // being added but not being searched SafeBuf xb; if ( gr->m_urlsBuf ) { xb.safeTruncateEllipsis ( gr->m_urlsBuf , 200 ); log(LOG_INFO,"http: add url %s (%s)", xb.getBufStart(),mstrerror(g_errno)); } char format = gr->m_hr.getReplyFormat(); TcpSocket *sock = gr->m_socket; if ( format == FORMAT_JSON || format == FORMAT_XML ) { bool status = g_httpServer.sendSuccessReply ( gr ); // nuke state mdelete ( gr , sizeof(gr) , "PageAddUrl" ); delete (gr); return status; } long ulen = 0; char *url = gr->m_urlsBuf; if ( url ) ulen = gbstrlen (url); // re-null it out if just http:// bool printUrl = true; if ( ulen == 0 ) printUrl = false; if ( ! gr->m_urlsBuf ) printUrl = false; if ( ulen==7 && printUrl && !strncasecmp(gr->m_url,"http://",7)) printUrl = false; if ( ulen==8 && printUrl && !strncasecmp(gr->m_url,"https://",8)) printUrl = false; // page is not more than 32k char buf[1024*32+MAX_URL_LEN*2]; SafeBuf sb(buf, 1024*32+MAX_URL_LEN*2); //char rawbuf[1024*8]; //SafeBuf rb(rawbuf, 1024*8); //rb.safePrintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); //rb.safePrintf("<status>\n"); //CollectionRec *cr = g_collectiondb.getRec ( gr->m_coll ); // collection name char tt [ 128 ]; tt[0] = '\0'; g_pages.printAdminTop ( &sb , sock , &gr->m_hr ); // display url //char *url = gr->m_urlsBuf; //if ( url && ! url[0] ) url = NULL; // watch out for NULLs if ( ! url ) url = "http://"; // if there was an error let them know //char msg[MAX_URL_LEN + 1024]; SafeBuf mbuf; //char *pm = ""; if ( g_errno ) { mbuf.safePrintf("<center><font color=red>"); mbuf.safePrintf("Error adding url(s): <b>%s[%i]</b>", mstrerror(g_errno) , g_errno); mbuf.safePrintf("</font></center>"); //pm = msg; //rb.safePrintf("Error adding url(s): %s[%i]", // mstrerror(g_errno) , g_errno); } else if ( printUrl ) { mbuf.safePrintf("<center><font color=red>"); mbuf.safePrintf("<b><u>"); mbuf.safeTruncateEllipsis(gr->m_urlsBuf,200); mbuf.safePrintf("</u></b> added to spider " "queue " "successfully<br><br>"); mbuf.safePrintf("</font></center>"); //rb.safePrintf("%s added to spider " // "queue successfully", url ); //pm = msg; //url = "http://"; //else // pm = "Don't forget to <a href=/gigaboost.html>" // "Gigaboost</a> your URL."; } if ( mbuf.length() ) sb.safeStrcpy ( mbuf.getBufStart() ); g_parms.printParmTable ( &sb , sock , &gr->m_hr ); // print the final tail g_pages.printTail ( &sb, true ); // admin? // clear g_errno, if any, so our reply send goes through g_errno = 0; // nuke state mdelete ( gr , sizeof(GigablastRequest) , "PageAddUrl" ); delete (gr); return g_httpServer.sendDynamicPage (sock, sb.getBufStart(), sb.length(), -1 ); // cachetime }
void printTcpTable ( SafeBuf* p, const char *title, TcpServer *server ) { // table headers for urls current being spiderd p->safePrintf ( "<table %s>" "<tr class=hdrow><td colspan=19>" "<center>" //"<font size=+1>" "<b>%s</b>" //"</font>" "</td></tr>" "<tr bgcolor=#%s>" "<td><b>#</td>" "<td><b>fd</td>" "<td><b>age</td>" "<td><b>idle</td>" //"<td><b>timeout</td>" "<td><b>ip</td>" "<td><b>port</td>" "<td><b>state</td>" "<td><b>bytes read</td>" "<td><b>bytes to read</td>" "<td><b>bytes sent</td>" "<td><b>bytes to send</td>" "</tr>\n" , TABLE_STYLE , title , DARK_BLUE ); // current time in milliseconds int64_t now = gettimeofdayInMilliseconds(); // store in buffer for sorting int32_t times[MAX_TCP_SOCKS]; TcpSocket *socks[MAX_TCP_SOCKS]; int32_t nn = 0; for ( int32_t i = 0 ; i<=server->m_lastFilled && nn<MAX_TCP_SOCKS; i++ ) { // get the ith socket TcpSocket *s = server->m_tcpSockets[i]; // continue if empty if ( ! s ) continue; // store it times[nn] = now - s->m_startTime; socks[nn] = s; nn++; } // bubble sort keepSorting: // assume no swap will happen bool didSwap = false; for ( int32_t i = 1 ; i < nn ; i++ ) { if ( times[i-1] >= times[i] ) continue; int32_t tmpTime = times[i-1]; TcpSocket *tmpSock = socks[i-1]; times[i-1] = times[i]; socks[i-1] = socks[i]; times[i ] = tmpTime; socks[i ] = tmpSock; didSwap = true; } if ( didSwap ) goto keepSorting; // now fill in the columns for ( int32_t i = 0 ; i < nn ; i++ ) { // get the ith socket TcpSocket *s = socks[i]; // set socket state const char *st = "ERROR"; switch ( s->m_sockState ) { case ST_AVAILABLE: st="available"; break; //case ST_CLOSED: st="closed"; break; case ST_CONNECTING: st="connecting"; break; case ST_READING: st="reading"; break; case ST_SSL_ACCEPT: st="ssl accept"; break; case ST_SSL_SHUTDOWN: st="ssl shutdown"; break; case ST_WRITING: st="sending"; break; case ST_NEEDS_CLOSE: st="needs close"; break; case ST_CLOSE_CALLED: st="close called"; break; case ST_SSL_HANDSHAKE: st = "ssl handshake"; break; } // bgcolor is lighter for incoming requests const char *bg = "c0c0f0"; if ( s->m_isIncoming ) bg = "e8e8ff"; // times int32_t elapsed1 = now - s->m_startTime ; int32_t elapsed2 = now - s->m_lastActionTime ; p->safePrintf ("<tr bgcolor=#%s>" "<td>%" PRId32"</td>" // i "<td>%i</td>" // fd "<td>%" PRId32"ms</td>" // elapsed seconds since start "<td>%" PRId32"ms</td>" // last action //"<td>%" PRId32"</td>" // timeout "<td>%s</td>" // ip "<td>%hu</td>" // port "<td>%s</td>" // state , bg , i, s->m_sd , elapsed1, elapsed2, //s->m_timeout , iptoa(s->m_ip) , s->m_port , st ); // tool tip to show top 500 bytes of send buf if ( s->m_readOffset && s->m_readBuf ) { p->safePrintf("<td><a title=\""); SafeBuf tmp; tmp.safeTruncateEllipsis ( s->m_readBuf , s->m_readOffset , 500 ); p->htmlEncode ( tmp.getBufStart() ); p->safePrintf("\">"); p->safePrintf("<u>%" PRId32"</u></td>",s->m_readOffset); } else p->safePrintf("<td>0</td>"); p->safePrintf( "<td>%" PRId32"</td>" // bytes to read "<td>%" PRId32"</td>" // bytes sent , s->m_totalToRead , s->m_sendOffset ); // tool tip to show top 500 bytes of send buf if ( s->m_totalToSend && s->m_sendBuf ) { p->safePrintf("<td><a title=\""); SafeBuf tmp; tmp.safeTruncateEllipsis ( s->m_sendBuf , s->m_totalToSend , 500 ); p->htmlEncode ( tmp.getBufStart() ); p->safePrintf("\">"); p->safePrintf("<u>%" PRId32"</u></td>",s->m_totalToSend); } else p->safePrintf("<td>0</td>"); p->safePrintf("</tr>\n"); } // end the table p->safePrintf ("</table><br>\n" ); }