/** * \brief Saves the Clone rule database to disk */ void saveTriggerData(void) { int totrules = 0; CloneRule *rule; extern CloneRule *first_crule; db.trigger = fopen(TRG_DB, "w"); if (!db.trigger) { logDump(corelog, "Unable to open trigger database for read access: %s", strerror(errno)); sSend (":%s GLOBOPS :Unable to open trigger database for read access: %s", NickServ, strerror(errno)); return; } for (rule = first_crule; rule; rule = rule->next, ++totrules) { if (fprintf (db.trigger, "Trigger %s %d %d %ld\n", rule->mask, rule->trigger, rule->utrigger, rule->flags) < 0) { logDump(corelog, "Error in writing rule to trigger database: %s", strerror(errno)); break; } if (rule->kill_msg) { if ((fprintf(db.trigger, "Killmsg %s\n", rule->kill_msg)) < 0) { logDump(corelog, "Error in writing trigger rule (killmsg) to trigger database: %s", strerror(errno)); break; } } if (rule->warn_msg) { if ((fprintf(db.trigger, "Warnmsg %s\n", rule->warn_msg)) < 0) { logDump(corelog, "Error in writing trigger rule (warnlmsg) to trigger database: %s", strerror(errno)); break; } } } fprintf(db.trigger, "done\n"); if (fclose(db.trigger) < 0) { logDump(corelog, "Error closing trigger database: %s", strerror(errno)); return; } sSend(":%s PRIVMSG " LOGCHAN " :Completed trigger save (%u rules)", OperServ, totrules); }
/*! * \fn void handler(int signal) * \brief Signal handler * \param signal A signal number (such as SIGTERM) * This is the function used by services to handle signals. */ void handler(int sig) { switch (sig) { case SIGTERM: sSend("WALLOPS " ":Received some signal thats telling me to shutdown"); timed_akill_queue(NULL); sshutdown(0); break; case SIGSEGV: timed_akill_queue(NULL); logDump(corelog, "Core dumped ---\n\"%s\"", coreBuffer); sSend("WALLOPS :Segmentation Violation, shutdown NOW"); sSend("GOPER :Buffer is -> %s", coreBuffer); dlogDump(corelog); sshutdown(1); break; case SIGPIPE: timed_akill_queue(NULL); signal(SIGPIPE, SIG_IGN); /*! \bug XXXMLG probably not QUITE right */ /* sshutdown(0);*/ break; default: sSend("GNOTICE :Recieved unidentified signal %i", sig); return; } }
static bool main_view(WINDOW *state, enum STATE *current_state, struct program *program) { int input; while (1) { set_state(current_state); input = wgetch(state); if (QUIT == input) { return false; } else if (LOGDUMP == input) { if (logDump(program)) { return false; } } else if (SIMVIEW == input) { *current_state = SIM; return true; } else if (MEMVIEW == input) { *current_state = MEM; return true; } else if (FILESEL == input) { prompt((char const *) NULL, "Enter the .obj file: ", program->objectfile); if (init_machine(program)) { return false; } } } }
/** * \brief Saves the InfoServ database to disk */ void saveInfoData(void) { SomeNews *news = NULL; int index = 0; db.is = fopen(IS_DB, "w"); if (db.is == NULL) { sSend(":%s GOPER :ERROR: Unable to save Info Article database fopen failed: %s", myname, strerror(errno)); logDump(corelog, "Unable to save Info Article database: fopen: %s", strerror(errno)); return; } /*! \bug Huh? Why check for NULL -twice- ? */ if (is_listhead != NULL) { /* In case list is empty, thanks to Echostar for pointing this cack-handed error out... */ for (news = is_listhead, index = 0; news; news = news->next, index++) { fprintf(db.is, "article %i %s %li %s\n", news->importance, news->from, news->timestamp, news->header); dbWriteString(db.is, news->content); } } fprintf(db.is, "done\n"); fclose(db.is); sSend(":%s PRIVMSG " LOGCHAN " :Completed save(%i articles)", InfoServ, index); }
/** * \brief a printf-like function for sending data to the services uplink * socket * \param format Format string * \param ... Variable-argument list */ void sSend(char *format, ...) { char sBuffer[IRCBUF]; va_list stuff; /* * set things up to print into the buffer. Up to sizeof(sBuffer) - 2 is * used (well, -3, since vsnprintf saves room for the \0 as well) and * the \r\n is appended using strcat. */ va_start(stuff, format); vsnprintf(sBuffer, sizeof(sBuffer) - 3, format, stuff); va_end(stuff); /* * Append a \r\n to the buffer, and send it to the server */ strcat(sBuffer, "\r\n"); /* strcat is safe */ #if 0 printf("Writing: %s\n", sBuffer); #endif if (server != -1) { if (net_write(server, sBuffer, strlen(sBuffer)) == -1) { if (errno == EPIPE || errno == EBADF || errno == EINVAL || errno == EFAULT) { logDump(corelog, "Terminating on write error, errno=%d", errno); close(server); server = -1; sshutdown(0); } } } else { logDump(corelog, "[ServerFd=-1] sSend : %s", sBuffer); } #ifdef DEBUG printf("-> %s\n", sBuffer); #endif }
void logDisplay() { if(receivingLog) { logDump(logFile, &logInfo, logStorage, logTotal); logClose(); if(logTotal > 0) consolePrintf("\n"); consoleNotef("LOG DUMP COMPLETED\n"); } logTotal = 0; }
int32 spoke_get_net_time() { static int32 sPreviousDelay = -1; int32 theDelay = (sSpokePreferences.mAdjustTiming && sTimingMeasurementValid) ? sTimingMeasurement : 0; if(theDelay != sPreviousDelay) { logDump("local delay is now %d", theDelay); sPreviousDelay = theDelay; } return (sConnected ? sOutgoingFlags.getWriteTick() - theDelay : getNetworkPlayer(sLocalPlayerIndex).mQueue->getWriteTick()); }
/** * \brief Used at services startup to connect to its uplink * \param hostname Hostname of uplink * \param IRC port * Returns a file descriptor of a connected socket if successful. */ int ConnectToServer(char *hostname, int portnum) { fd_set wfd, xfd; struct sockaddr_in sa; struct hostent *hp; int s; if ((hp = gethostbyname(hostname)) == NULL) { errno = ECONNREFUSED; return (-1); } bzero(&sa, sizeof(sa)); bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length); /* set address */ sa.sin_family = hp->h_addrtype; sa.sin_port = htons((u_short) portnum); if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) /* get socket */ return (-1); if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) { /* connect */ printf("Error: %s\n", strerror(errno)); close(s); return (-1); } /* * whoo hoo, we got connected. For some reason, if we don't pause here a * little while, we loose. XXX This should be fixed... */ FD_ZERO(&wfd); FD_ZERO(&xfd); FD_SET(s, &wfd); FD_SET(s, &xfd); if (select(s + 2, NULL, &wfd, &xfd, NULL) < 0 || !FD_ISSET(s, &wfd) || FD_ISSET(s, &xfd)) { logDump(corelog, "Error occured while attempting to establish connection [%d]", errno); flushLogs(NULL); sshutdown(2); } return (s); }
/** * @param source Sender nickname * @param buf Message text * @param which Value indicating which client received the message * @brief handle an incoming message to a MassServ fake client */ void detect_mass(UserList *nl_from, char *buf, int which) { aMassAd *booya; aMassAd *f1, *f2, *f1o, *f2o; expire_ads(); if (nl_from != 0) { f1o = f1 = find_ad(nl_from, 0); f2o = f2 = find_ad(nl_from, 1); } else return; if (nl_from && ((!f1 && which == 0) || (!f2 && which == 1))) { booya = (aMassAd *) oalloc(sizeof(aMassAd)); booya->sender = nl_from; booya->utc = time(NULL); booya->rcvd_by = which; insert_ad(booya); if (!booya->sender) logDump(corelog, "[***] bug: booya->sender is NULL in detect_mass()"); } if (f1 == NULL) f1 = find_ad(nl_from, 0); if (f2 == NULL) f2 = find_ad(nl_from, 1); if (f1 != NULL && f2 != NULL) { sSend(":%s GLOBOPS :\2Mass Ad:\2 (%s) %s", MassServ, nl_from->nick, buf); flush_ad(nl_from); // sSend(":%s SVSKILL %s :killed ([services] (Mass msg'ing))", source); } else if (!f1o && !f2o) sSend(":%s GLOBOPS :(Debug) \2Possible Mass Ad:\2 (%s) %s", MassServ, nl_from->nick, buf); return; }
/** * \brief Saves the ChanServ database to disk */ void saveChanData(RegChanList * first) { RegChanList *cl = first; cAccessList *accitem; cAkickList *akitem; const char *tmpFounderNick; int x = 0; saveChanUrls(first); db.cs = NULL; db.cs = fopen(CS_DIR "chanserv.db", "w"); if (db.cs == NULL) { sSend(":%s GOPER :ERROR: Unable to save Channel database fopen failed: %s", myname, strerror(errno)); logDump(corelog, "Unable to save Channel database: fopen: %s", strerror(errno)); return; } fprintf(db.cs, "version 2\n"); while (cl) { tmpFounderNick = cl->founderId.getNick(); if (tmpFounderNick == NULL) tmpFounderNick = "-"; /* New chan insertion point */ fprintf(db.cs, "channel "); fprintf(db.cs, "%s %s ", cl->name, tmpFounderNick); fprintf(db.cs, "%lu %lu ", cl->mlock, cl->flags); if (!(cl->flags & CENCRYPT)) { strcpy(cryptstr, (char *)cl->password); xorit(cryptstr); fprintf(db.cs, "@%s ", cryptstr); } else { u_char *tmpup = toBase64(cl->password, 16); if (!tmpup) abort(); fprintf(db.cs, "$%s ", tmpup); FREE(tmpup); } fprintf(db.cs, "%lu ", (unsigned long)cl->timereg); fprintf(db.cs, "%lu ", (unsigned long)cl->timestamp); fprintf(db.cs, "%s %lu %i ", cl->key, cl->limit, cl->memolevel); fprintf(db.cs, "%i %i :%s\n", cl->tlocklevel, cl->restrictlevel, cl->desc); if (cl->topic) fprintf(db.cs, "topic %s %s %lu :%s\n", cl->name, cl->tsetby, cl->ttimestamp, cl->topic); if (cl->url) fprintf(db.cs, "url %s :%s\n", cl->name, cl->url); if (cl->autogreet != NULL) fprintf(db.cs, "autogreet %s :%s\n", cl->name, cl->autogreet); if ((cl->flags & CMARK) && cl->markby) fprintf(db.cs, "markby %s %s\n", cl->name, cl->markby); if (cl->chpw_key) fprintf(db.cs, "chkey %X\n", cl->chpw_key); if (cl->firstOp) { const char *tmpName; for (accitem = cl->firstOp; accitem; accitem = accitem->next) { tmpName = (accitem->nickId).getNick(); if (tmpName == NULL) continue; fprintf(db.cs, "op %s %s ", cl->name, tmpName); fprintf(db.cs, "%i\n", accitem->uflags); } } if (cl->firstAkick) { for (akitem = cl->firstAkick; akitem; akitem = akitem->next) { fprintf(db.cs, "akick %s %s ", cl->name, akitem->mask); fprintf(db.cs, "%lu :%s\n", (u_long) akitem->added, akitem->reason); } } x++; fflush(db.cs); #ifdef DBDEBUG sSend(":%s PRIVMSG " DEBUGCHAN " :Saved chan data (%s)", ChanServ, cl->name); #endif cl = cl->next; } fprintf(db.cs, "done\n"); fflush(db.cs); fclose(db.cs); #ifdef GLOBOPS_TIMED_MSGS sSend(":%s GLOBOPS :Completed save(%i)", ChanServ, x); #else sSend(":%s PRIVMSG " LOGCHAN " :Completed save(%i)", ChanServ, x); #endif }
/** * \brief Saves the NickServ database to disk */ void saveNickData(void) { RegNickList *nl; nAccessList *accitem; int x = 0, bucket; db.ns = fopen(NS_DB, "w"); if (db.ns == NULL) { sSend(":%s GOPER :ERROR: Unable to save NickServ database fopen failed: %s", myname, strerror(errno)); logDump(corelog, "Unable to save NickServ database: fopen: %s", strerror(errno)); return; } fprintf(db.ns, "version 3\n"); for (bucket = 0; bucket < NICKHASHSIZE; bucket++) { nl = LIST_FIRST(&RegNickHash[bucket]); while (nl != NULL) { /* New nick insertion point */ fprintf(db.ns, "nick "); if (nl->user[0] == '\0') fprintf(db.ns, "%s . %s ", nl->nick, nl->host); else fprintf(db.ns, "%s %s %s ", nl->nick, nl->user, nl->host); if (!(nl->flags & NENCRYPT)) { strcpy(cryptstr, (char *)nl->password); xorit(cryptstr); fprintf(db.ns, "@%s ", cryptstr); } else { unsigned char *p; // XXX Put note that PASSLEN must be at least 15 p = toBase64(nl->password, 16); fprintf(db.ns, "$%s ", p); FREE(p); } fprintf(db.ns, "%lu ", (unsigned long)nl->timestamp); fprintf(db.ns, "%lu ", (unsigned long)nl->timereg); fprintf(db.ns, "%i %X*%X\n", nl->flags, nl->regnum.a, nl->regnum.b); /* Infoserv data */ fprintf(db.ns, "is %ld\n", nl->is_readtime); #ifdef REQ_EMAIL if (!(nl->flags & NACTIVE) || (nl->flags & NDEACC)) fprintf(db.ns, "akey %lu\n", nl->email_key); #endif if (nl->chpw_key) fprintf(db.ns, "chkey %X\n", nl->chpw_key); if (nl->url != NULL) fprintf(db.ns, "url %s %s\n", nl->nick, nl->url); #ifdef TRACK_GECOS if (nl->gecos != NULL) fprintf(db.ns, "gecos :%s\n", nl->gecos); #endif if (nl->email[0] && strcmp(nl->email, "(none)")) fprintf(db.ns, "email %s %s\n", nl->nick, nl->email); if ((nl->opflags & ~(OROOT | OSERVOP))) fprintf(db.ns, "oper %s %lu 0 0\n", nl->nick, nl->opflags); if ((nl->flags & NMARK) && nl->markby) fprintf(db.ns, "markby %s %s\n", nl->nick, nl->markby); if (nl->idtime != DEF_NDELAY) fprintf(db.ns, "idtime %s %i\n", nl->nick, nl->idtime); for (accitem = LIST_FIRST(&nl->acl); accitem; accitem = LIST_NEXT(accitem, al_lst)) fprintf(db.ns, "access %s %s\n", nl->nick, accitem->mask); x++; fflush(db.ns); #ifdef DBDEBUG sSend(":%s PRIVMSG " DEBUGCHAN " :Saved nick data (%s)", NickServ, nl->nick); #endif nl = LIST_NEXT(nl, rn_lst); } } fprintf(db.ns, "done\n"); fflush(db.ns); fclose(db.ns); #ifdef GLOBOPS_TIMED_MSGS sSend(":%s GLOBOPS :Completed save(%i)", NickServ, x); #else sSend(":%s PRIVMSG " LOGCHAN " :Completed save(%i)", NickServ, x); #endif }
/** * \brief Loads the NickServ database from disk */ void readNickData() { RegNickList *rnl = NULL; char *command, *tmpp; unsigned char *tmpup; int done = 0, db_version = 1; int line_num = 0, do_enc = 0; #ifdef REQ_EMAIL readRegData(); #endif db.ns = fopen(NS_DB, "r"); if (db.ns == NULL) { logDump(corelog, "Unable to open " NS_DB ": %s", strerror(errno)); return; } while (!done) { if (!(sfgets(dbLine, 1024, db.ns))) { if (!done) { unexpected_eof(NS_DB); } done = 1; fclose(db.ns); return; } line_num++; if (parse_init(&state, dbLine) != 0) { /*! \bug XXX make a nicer error here! */ abort(); } command = parse_getarg(&state); if (strcmp(command, "version") == 0) { tmpp = parse_getarg(&state); assert(tmpp); if (tmpp) db_version = atoi(tmpp); } else if (strcmp(command, "nick") == 0) { rnl = (RegNickList *) oalloc(sizeof(RegNickList)); char *sNick, *sUser, *sHost, *sPass; sNick = parse_getarg(&state); sUser = parse_getarg(&state); sHost = parse_getarg(&state); sPass = parse_getarg(&state); if (strlen(sNick) >= NICKLEN) { fprintf(stderr, NS_DB ":%d: " " Nickname '%.80s' exceeds " " NICKLEN.\n", line_num, sNick); sshutdown(-1); } strcpy(rnl->nick, sNick); strncpyzt(rnl->user, sUser, USERLEN); SetDynBuffer(&rnl->host, sHost); if (db_version < 2) { if (strlen(sPass) > PASSLEN) { fprintf(stderr, NS_DB ":%d: " " Password for nick '%s' " " exceeds PASSLEN.\n", line_num, sNick); sshutdown(-1); } strcpy((char *)rnl->password, xorit(sPass)); } else { char encType = *sPass; if (encType == '@') { if (strlen(sPass+1) > PASSLEN) { fprintf(stderr, NS_DB ":%d: " " Password for nick '%s' " " exceeds PASSLEN.\n", line_num, sNick); sshutdown(-1); } strcpy((char *)rnl->password, xorit(sPass + 1)); do_enc = 0; } else if (encType == '$') { int q, len; tmpup = fromBase64(sPass + 1, &len); assert(tmpup); for(q = 0; q < 16; q++) rnl->password[q] = tmpup[q]; do_enc = 1; FREE(tmpup); } else rnl->password[0] = '\0'; } rnl->timestamp = (time_t) atol(parse_getarg(&state)); rnl->timereg = (time_t) atol(parse_getarg(&state)); rnl->flags = atoi(parse_getarg(&state)); if (db_version >= 3) { const char *idString = parse_getarg(&state); int av, bv; sscanf(idString, "%X*%X", &av, &bv); rnl->regnum.SetDirect(top_regnick_idnum, av, bv); } else { rnl->regnum.SetNext(top_regnick_idnum); } if (do_enc) rnl->flags |= NENCRYPT; else rnl->flags &= ~NENCRYPT; rnl->opflags = 0; rnl->idtime = DEF_NDELAY; ADD_MEMO_BOX(rnl); addRegNick(rnl); } else if (strcmp(command, "is") == 0) { char *data = parse_getarg(&state); if (rnl && data) rnl->is_readtime = atol(data); } else if (strcmp(command, "oper") == 0) { char *opflags_s; if (rnl && (rnl == getRegNickData(parse_getarg(&state)))) { if ((opflags_s = parse_getarg(&state))) rnl->opflags |= (strtoul(opflags_s, (char **)0, 10) & ~(OROOT | OSERVOP)); if (rnl->opflags) addOpData(rnl); } } else if (strcmp(command, "url") == 0) { if (rnl && (rnl == getRegNickData(parse_getarg(&state)))) { rnl->url = strdup(parse_getarg(&state)); if (strlen(rnl->url) > (URLLEN - 1)) rnl->url[URLLEN - 1] = '\0'; } } else if (strcmp(command, "gecos") == 0) { #ifdef TRACK_GECOS char *gecos = parse_getallargs(&state); if (gecos != NULL) rnl->gecos = strdup(gecos); #endif } else if (strcmp(command, "akey") == 0) { #ifdef REQ_EMAIL if (rnl) rnl->email_key = atoi(parse_getarg(&state)); #endif } else if (strcmp(command, "chkey") == 0) { char *tmpp = parse_getarg(&state); if (rnl && tmpp) rnl->chpw_key = strtoul(tmpp, (char **)0, 16); } else if (strcmp(command, "markby") == 0) { char *mby; rnl = getRegNickData(parse_getarg(&state)); if (!rnl || !(mby = parse_getarg(&state))) continue; rnl->markby = strdup(mby); } else if (strcmp(command, "access") == 0) { rnl = getRegNickData(parse_getarg(&state)); addAccItem(rnl, parse_getarg(&state)); } else if (!strcmp(command, "email")) { rnl = getRegNickData(parse_getarg(&state)); strncpyzt(rnl->email, parse_getarg(&state), EMAILLEN); if (!strcmp(rnl->email, "(none)")) strcat(rnl->email, " "); } else if (!strcmp(command, "idtime")) { rnl = getRegNickData(parse_getarg(&state)); rnl->idtime = atoi(parse_getarg(&state)); } else if (!strcmp(command, "done")) done = 1; else { fprintf(stderr, NS_DB ":%d: Error reading nick data (%s)", line_num, dbLine); sshutdown(-1); } #ifdef DBDEBUG sSend(":%s PRIVMSG " DEBUGCHAN " :Read nick data (%s)", NICKSERV, dbLine); #endif parse_cleanup(&state); } fclose(db.ns); readMemoData(); }
VBool CurlSocket::SendFromQueue() { // Is there something to send? if (!m_bIsConnected) { vnclog.Print(LL_DIMDIM, "Not Connected. Exiting\r\n"); return VFalse; } if (out_queue.empty()) return VTrue; omni_mutex_lock l(curl_lock); ByteBuffer* buffer = out_queue.dequeue(m_blockSize); ScopedPointer<ByteBuffer> bufPtr(buffer); if ((1 == m_uOperationType || 3 == m_uOperationType) && buffer->getLength() > 0) { dumpPackets((char*)buffer->getData(), buffer->getLength()); } if (m_uOperationType >= 2) { std::string url(""); try { DimdimHelpers::PrepareURL(url, "send", CurlClientData::getInstance()->m_subscriptionID); std::stringstream index; index.clear(); index << m_postCount; url.append("/"); url.append(index.str()); index.clear(); } catch(...) { vnclog.Print(LL_DIMDIM, VNCLOG("Caught exception in PrepareURL\r\n")); return VFalse; } // Try to send some data TimeStampGenerator tempGen; tempGen.reset(); bool bValidResponse = false; for (int i = 0; i < CurlClientData::getInstance()->m_maxRetries + 1; i++) { CURLcode res; ByteBuffer chunk; ByteBuffer headers; try { curl_easy_setopt(m_handler, CURLOPT_URL, url.c_str()); curl_easy_setopt(m_handler, CURLOPT_POSTFIELDSIZE, buffer->getLength()); curl_easy_setopt(m_handler, CURLOPT_COPYPOSTFIELDS, buffer->getData()); curl_easy_setopt(m_handler, CURLOPT_TIMEOUT, (CurlClientData::getInstance()->m_maxWaitTime) * 2); curl_easy_setopt(m_handler, CURLOPT_CONNECTTIMEOUT, CurlClientData::getInstance()->m_maxWaitTime); //curl_easy_setopt(m_handler, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_easy_setopt(m_handler, CURLOPT_WRITEFUNCTION, DimdimHelpers::ContentWriteCallback); curl_easy_setopt(m_handler, CURLOPT_WRITEDATA, &chunk); curl_easy_setopt(m_handler, CURLOPT_HEADERFUNCTION, DimdimHelpers::HeadersWriteCallback); curl_easy_setopt(m_handler, CURLOPT_HEADERDATA, &headers); curl_easy_setopt(m_handler, CURLOPT_HTTPHEADER, m_headerList); if (0 != m_proxyType.compare("DIRECT")) { // DIRECT can be ignored curl_easy_setopt(m_handler, CURLOPT_PROXY, m_proxyURL.c_str()); if (0 == m_proxyType.compare("SOCKS")) curl_easy_setopt(m_handler, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } // curl_easy_setopt(m_handler, CURLOPT_DEBUGFUNCTION, my_trace); // curl_easy_setopt(m_handler, CURLOPT_DEBUGDATA, &config); // curl_easy_setopt(m_handler, CURLOPT_VERBOSE, 1); } catch(...) { vnclog.Print(LL_DIMDIM, VNCLOG("Caught Exception in setting regular options to curl handle\r\n")); return VFalse; } try { res = curl_easy_perform(m_handler); } catch(...) { vnclog.Print(LL_DIMDIM, VNCLOG("Caught Exception in performing\r\n")); return VFalse; } // if (CURLE_OK != res || true != DimdimHelpers::ValidResponseHeaders(headers, "send")) if ((CURLE_OK != res) || (1 != DimdimHelpers::ValidResponseHeaders(headers, "send"))) { // A 200 or a 500 doesn't warrant retries. // Don't worry about CURL_RESULT either. logDump(buffer->getData(), buffer->getLength(), "SEND PACKET"); vnclog.Print(LL_DIMDIM, "CURL RESULT = %d\r\n", res); if (headers.getData()) { vnclog.Print(LL_DIMDIM, "%s", headers.getData()); } else { vnclog.Print(LL_DIMDIM, VNCLOG("Got headers with empty data and length = %d bytes\r\n"), headers.getLength()); } curl_easy_cleanup(m_handler); m_handler = curl_easy_init(); } else { bValidResponse = true; break; } ::WaitForSingleObject(m_eTimer, 500 * (i + 1)); } if (false == bValidResponse) { vnclog.Print(LL_DIMDIM, VNCLOG("Setting connected status to false, because of send failures\r\n")); m_bIsConnected = false; m_bSendFailed = true; logDump(buffer->getData(), buffer->getLength(), "LAST FAILED SEND PACKET"); vnclog.Print(LL_DIMDIM, VNCLOG("\r\nTotal Data Queued before send failure = %d bytes\r\n\r\n"), (m_totalDataCreated - buffer->getLength())); vnclog.Print(LL_DIMDIM, VNCLOG("Total Data Sent = %d bytes\r\n\r\n"), m_totalDataSent); vnclog.Print(LL_DIMDIM, VNCLOG("Returning false\r\n")); return VFalse; } m_totalDataSent += buffer->getLength(); m_postCount += 1; // if (0 == (m_postCount % 10)) // vnclog.Print(LL_DIMDIM, "Data sent so far (bytes),%d,Average Bitrate (Kbps),%f\n", m_totalDataSent, getBitRate(m_totalDataSent,tg.getTimeStamp())); /* if (0 == (m_postCount % 100)) { vnclog.Print(LL_DIMDIM, "Cleaning up curl handle every 100 posts\r\n"); curl_easy_cleanup(m_handler); m_handler = curl_easy_init(); vnclog.Print(LL_DIMDIM, "Curl handle cleaned up and re-initialized\r\n"); } */ } return VTrue; }
/** * \brief Loads the clone rule database from disk */ void readTriggerData(void) { CloneRule *rule = NULL; char *command, *text; int done = 0; unsigned long linenum = 0; db.trigger = fopen(TRG_DB, "r"); if (db.trigger == NULL) { logDump(corelog, "Unable to open trigger database for read access: %s", strerror(errno)); return; } while (!done) { if (!(sfgets(dbLine, 2048, db.trigger))) { if (!done) { unexpected_eof(TRG_DB); } done = 1; fclose(db.trigger); return; } linenum++; if (parse_init(&state, dbLine) != 0) { /*! \bug XXX be nicer here... */ abort(); } command = parse_getarg(&state); if (strcmp(command, "Trigger") == 0) { rule = NewCrule(); rule->kill_msg = NULL; rule->warn_msg = NULL; strncpyzt(rule->mask, parse_getarg(&state), sizeof(rule->mask)); rule->mask[sizeof(rule->mask) - 1] = '\0'; rule->trigger = atoi(parse_getarg(&state)); rule->utrigger = atoi(parse_getarg(&state)); rule->flags = atol(parse_getarg(&state)); AddCrule(rule, -2); /* -2 is magic for append to end */ } else if (strcmp(command, "Killmsg") == 0) { text = parse_getallargs(&state); if (text && rule) rule->kill_msg = strdup(text); } else if (strcmp(command, "Warnmsg") == 0) { text = parse_getallargs(&state); if (text && rule) rule->warn_msg = strdup(text); } else if (strcmp(command, "done") == 0) { done = 1; } else { fprintf(stderr, "Error in reading trigger data (%s) %lu\n", dbLine, linenum); parse_cleanup(&state); return; } #ifdef DBDEBUG sSend(":%s PRIVMSG " DEBUGCHAN " :Read trigger data (%s)", OperServ, dbLine); #endif parse_cleanup(&state); } fclose(db.trigger); }
void CBoostLog::logDump(const std::string& prefix, const std::vector<uint8_t>& data) { logDump(LOG_TRACE, prefix, data); }
/** * @brief Handle an unexpected EOF in database file error * @pre file_name points to a valid Zero-terminated character array * @post None */ void unexpected_eof( const char* file_name ) { fprintf(stderr, "Unexpected EOF: %s\n", file_name); logDump(corelog, "Unexpected EOF: %s", file_name); sshutdown(-1); }
int requestHandler(void *) { logTest("requestHandler", "Going to handle the new request"); for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++) { if (processes[i] != NULL) { logTest("requestHandler", "Cleaning up process table"); delete processes[i]; processes[i] = NULL; } } logTest("requestHandler", "Cleaning up listener and dispatcher"); delete listener; listener = NULL; delete dispatcher; dispatcher = NULL; char buffer[DEFAULT_BUFFER_LENGTH]; // // Create the class for parsing and // handling the HTTP request. // Request *request = new Request(); /* FIXME */ request -> setRootPath("/home/pinzari/NX/apache_1.3.33/htdocs/manual"); /* request -> setRootPath("/usr/share/doc/HTML"); */ request -> setProgramPath("/home/pinzari/NX/nxproxy"); request -> setProgramName("nxproxy"); for (;;) { logTest("requestHandler", "Reading from descriptor %d", fileno(stdin)); /* FIXME: This is temporarily used to dump the content of data sent by X clients at connection time. */ char data[1024]; int result; while ((result = read(0, data, 1024)) > 0) { logDump("requestHandler", data, result); } logTest("requestHandler", "Exiting"); exit(0); if (fgets(buffer, sizeof(buffer), stdin) != NULL) { // // We are waiting for 1, when the request is // complete, or -1, in the case of an error. // if (request -> parse(buffer, strlen(buffer)) != 0) { break; } } } if (request -> isError() != request_error_none) { logTest("requestHandler", "Aborting request with error '%s'", request -> getErrorString()); } else { logTest("requestHandler", "Executing request with URL '%s'", request -> getUrl()); } // // Read from the file and write to the socket. // const char *name = request -> getFile(); if (name != NULL) { int in = open(name, O_RDONLY); if (in != -1) { int out = fileno(stdout); write(out, "HTTP/1.1 200 OK", strlen("HTTP/1.1 200 OK")); write(out, "Content-type: ", strlen("Content-Type: ")); write(out, request -> getMimeString(), strlen(request -> getMimeString())); write(out, "\n\n", strlen("\n\n")); int result; while ((result = read(in, buffer, sizeof(buffer))) > 0) { write(fileno(stdout), buffer, result); } } } fclose(stdin); fclose(stdout); delete request; logTest("requestHandler", "Exiting from the request handler"); return 1; }