/* * Startup the server listener. */ int startup_server(void) { int optval = 1; /* Initialize client_info list */ llist_init(&list_start); /* Create socket */ server_sockfd = socket(AF_INET, SOCK_STREAM, 0); if (setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0) { logline(LOG_DEBUG, "Error calling setsockopt(): %s", strerror(errno)); return -1; } /* Name the socket */ server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = inet_addr(params->ip); server_address.sin_port = htons(params->port); server_len = sizeof(server_address); if (bind(server_sockfd, (struct sockaddr *)&server_address, server_len) != 0) { logline(LOG_DEBUG, "Error calling bind(): %s", strerror(errno)); return -2; } /* Create a connection queue and wait for incoming connections */ if (listen(server_sockfd, 5) != 0) { logline(LOG_DEBUG, "Error calling listen(): %s", strerror(errno)); return -3; } return 0; }
uint32_t __stdcall Client::handleSvc(void* param) { HINSTANCE hInst = 0; bool connected = false; Client * pclient = (Client *)param; while (WAIT_OBJECT_0 == WaitForSingleObject(pclient->m_hEventRequest, INFINITE)) { while(!pclient->m_reqList.empty()) { if (!connected && !pclient->connect()) { logline(LOG::LEVEL_ERROR, "connect server failed. retry."); ::Sleep(CLT_CONNECT_INTERVAL); continue; } else { connected = true; logline(LOG::LEVEL_INFO, "connect server success."); } request_t pReq = pclient->m_reqList.front(); if(!pclient->sendReq(&pReq)) { connected = false; continue; } pclient->m_reqList.pop_front(); } } return 0; }
void help() { logline(); log("Commands: hook / log <address>, hook / log api <module> <function>"); log(" unhook <address>"); log(" call <address> <args>, call api <module> <function> <args>"); log(" hooks, quit / q / exit"); logline(); }
/* * Checks the input file if it contains valid ip addresses. */ int check_input_file_ip(void) { int error = 0; FILE *f; int ret = 0; regex_t regex_ip; char line[256]; /* Compile regex pattern */ if ((ret = regcomp(®ex_ip, "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", REG_EXTENDED)) != 0) { return -1; } /* Check if every line in the input file is a valid host */ f = fopen(params->inputfile, "r"); if (f != NULL) { while ((fgets(line, 255, f) != NULL) && (error == 0)) { chomp(line); ret = regexec(®ex_ip, line, 0, NULL, 0); if (ret == 0) { logline(LOG_DEBUG, " Work item %s is valid", line); } else if (ret == REG_NOMATCH) { logline(LOG_DEBUG, " Work item %s has an invalid format", line); error = 1; } else { logline(LOG_DEBUG, " Work item %s has an unknown problem. Return code was: %d", line, ret); error = 1; } } regfree(®ex_ip); fclose(f); if (error == 1) { return -2; } } else { /* File could not be opened */ return -3; } return 0; }
/* child will spin waiting to be killed by debugger or parent or someone */ void do_child(void) { pid_t doublechild; int ret; setprogname("CHILD"); logline("child pid %d. waiting for external termination...", getpid()); usleep(500000); doublechild = fork(); if (doublechild == 0) { exit(0); } else if (doublechild == -1) { err(1, "doublechild"); } else { ret = waitpid(doublechild, NULL, 0); if (ret == -1) err(1, "waitpid(%d) by parent failed", doublechild); } while (1) { sleep(60); } }
/* Wait for at least one new reply. Return when at least * min_replies slaves have already replied, or when the * given absolute time is passed. * The replies are returned in gtp_replies[0..reply_count-1] * slave_lock is held on entry and on return. */ void get_replies(double time_limit, int min_replies) { for (;;) { if (reply_count > 0) { struct timespec ts; double sec; ts.tv_nsec = (int)(modf(time_limit, &sec)*1000000000.0); ts.tv_sec = (int)sec; pthread_cond_timedwait(&reply_cond, &slave_lock, &ts); } else { pthread_cond_wait(&reply_cond, &slave_lock); } if (reply_count == 0) continue; if (reply_count >= min_replies || reply_count >= active_slaves) return; if (time_now() >= time_limit) break; } if (DEBUGL(1)) { char buf[1024]; snprintf(buf, sizeof(buf), "get_replies timeout %.3f >= %.3f, replies %d < min %d, active %d\n", time_now() - start_time, time_limit - start_time, reply_count, min_replies, active_slaves); logline(NULL, "? ", buf); } assert(reply_count > 0); }
int main(int argc, char **argv) { char *ename = basename(argv[0]); uint8_t msg[PCKT_LEN]; memset(msg, 0, sizeof msg); msg[0] = MODE_LOCK; // c**k blocked if(strcmp(ename, "lock") == 0) { msg[1] = LOCK_LOCKED; } else if(strcmp(ename, "unlock") == 0) { msg[1] = LOCK_UNLOCKED; } else { printf("have a nice day ;)\n"); return 0; } sendpkt(msg); time_t rightnow = time(NULL); struct tm *stamp = localtime(&rightnow); char timestamp[100]; // probably big enough... struct passwd *userentry = getpwuid(getuid()); strftime(timestamp, sizeof timestamp, "%a %F %T", stamp); logline("%s := Door %s by %s\n", timestamp, msg[1] == LOCK_LOCKED ? "locked" : "unlocked", userentry->pw_name); return 0; }
void Debug::Log(const char * fmt, ...) { char buffer[MAX_LINE_LENGTH]; va_list args; va_start(args,fmt); int charsWritten = vsnprintf_s(buffer, MAX_LINE_LENGTH, _TRUNCATE, fmt, args); va_end(args); std::string logline(buffer); if(charsWritten == -1) logline += "..."; int firstNewline = -1; while( (firstNewline = logline.find("\n")) != -1 ) { logLines.back().append(logline.substr(0,firstNewline)); logline = logline.substr(firstNewline + strlen("\n")); logLines.emplace_back(); } logLines.back().append(logline); if(logFile) { FILE * f; _wfopen_s(&f, logFile, L"a"); if(f) { fprintf_s(f, buffer); fclose(f); } } //#if windows build OutputDebugStringA(buffer); //#endif }
void cmd_retr(t_ftpserv *ftpserv, t_client *client, char *args) { int pid; logline(ftpserv, 1, "user ^ retr ^.\n", client->username, args); if ((pid = fork()) == -1) { send_msg2client(client, "451 fork error. Please try again later.\r\n"); return ; } if (pid == 0) { if (client->mode == MODE_ACTF) make_connect_socket(client); send_msg2client(client, "150 Opening data connection.\r\n"); if (client->mode == MODE_PASV) passiv_connect(ftpserv, client); do_retr(ftpserv, client, args); shutdown(client->data_fd, SHUT_RDWR); close(client->data_fd); if (client->mode == MODE_PASV) close(client->data_servfd); send_msg2client(client, "226 Transfer complete.\r\n"); } }
/* Get a free binary buffer, first invalidating it in the receive * queue if necessary. In practice all buffers should be used * before they are invalidated, if BUFFERS_PER_SLAVE is large enough. * slave_lock is held on both entry and exit of this function. */ static void * get_free_buf(struct slave_state *sstate) { int newest = (sstate->newest_buf + 1) & (BUFFERS_PER_SLAVE - 1); sstate->newest_buf = newest; void *buf = sstate->b[newest].buf; if (DEBUGVV(7)) { char b[1024]; snprintf(b, sizeof(b), "get free %d index %d buf=%p age %d qlength %d\n", newest, sstate->b[newest].queue_index, buf, queue_age, queue_length); logline(&sstate->client, "? ", b); } int index = sstate->b[newest].queue_index; if (index < 0) return buf; /* Invalidate the buffer if the calling thread still owns its previous * entry in the receive queue. The entry may have been overwritten by * another thread, but only after a new move which invalidates the * entire receive queue. */ if (receive_queue[index] && receive_queue[index]->owner == sstate->thread_id) { receive_queue[index] = NULL; } sstate->b[newest].queue_index = -1; return buf; }
bool Client::init() { if (!Sock::startup()) { return false; } m_pCl = new Cl(); if (m_pCl == NULL) { logline(LOG::LEVEL_ERROR, "create Cl failed."); return false; } #ifdef _DEBUG m_pCl->attachDbgCon(); #endif //m_hWaitEvent = CreateEvent(NULL, FALSE, FALSE, CLT_EVENTNAME_WAIT2WORK); //if (m_hWaitEvent == INVALID_HANDLE_VALUE) { // logline(LOG::LEVEL_ERROR, "create event failed.(error = %d)\n", GetLastError()); // return false; //} m_pthHandleUI = new Pth(handleUI); if (m_pthHandleUI == NULL) { return false; } m_pthHandleUI->startThread(this); m_pthHandleSvc = new Pth(handleSvc); if (m_pthHandleSvc == NULL) { return false; } m_pthHandleSvc->startThread(this); m_pFrame = new Frame(); if (m_pFrame == NULL) { logline(LOG::LEVEL_ERROR, "create mail frame failed."); return false; } m_pFrame->Create(NULL, CLT_MAINFRAME_TITLE, UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); m_pFrame->SetIcon(IDI_ICON); m_pFrame->ShowWindow(true); logline(LOG::LEVEL_INFO, "handleUI thread id = %d", m_pthHandleUI->getTid()); logline(LOG::LEVEL_INFO, "handleSvc thread id = %d", m_pthHandleSvc->getTid()); return true; }
void sbbs_t::logentry(const char *code, const char *entry) { char str[512]; now=time(NULL); sprintf(str,"Node %2d %s\r\n %s",cfg.node_num,timestr(now),entry); logline(code,str); }
/* Get a reply to one gtp command. Return the gtp command id, * or -1 if error. reply must have at least CMDS_SIZE bytes. * The ascii reply ends with an empty line; if the first line * contains "@size", a binary reply of size bytes follows the * empty line. @size is not standard gtp, it is only used * internally by Pachi for the genmoves command; it must be the * last parameter on the line. * *bin_size is the maximum size upon entry, actual size on return. * slave_lock is not held on either entry or exit of this function. */ static int get_reply(FILE *f, struct in_addr client, char *reply, void *bin_reply, int *bin_size) { double start = time_now(); int reply_id = -1; *reply = '\0'; if (!fgets(reply, CMDS_SIZE, f)) return -1; /* Check for binary reply. */ char *s = strchr(reply, '@'); int size = 0; if (s) size = atoi(s+1); assert(size <= *bin_size); *bin_size = size; if (DEBUGV(s, 2)) logline(&client, "<<", reply); if ((*reply == '=' || *reply == '?') && isdigit(reply[1])) reply_id = atoi(reply+1); /* Read the rest of the ascii reply */ char *line = reply + strlen(reply); while (fgets(line, reply + CMDS_SIZE - line, f) && *line != '\n') { if (DEBUGL(3)) logline(&client, "<<", line); line += strlen(line); } if (*line != '\n') return -1; /* Read the binary reply if any. */ int len; while (size && (len = fread(bin_reply, 1, size, f)) > 0) { bin_reply = (char *)bin_reply + len; size -= len; } if (*bin_size && DEBUGVV(2)) { char buf[1024]; snprintf(buf, sizeof(buf), "read reply %d+%d bytes in %.4fms\n", (int)strlen(reply), *bin_size, (time_now() - start)*1000); logline(&client, "= ", buf); } return size ? -1 : reply_id; }
/* Send the gtp command to_send and get a reply from the slave machine. * Write the reply in buf which must have at least CMDS_SIZE bytes. * If *bin_size > 0, send bin_buf after the gtp command. * Return any binary reply in bin_buf and set its size in bin_size. * bin_buf is private to the slave and need not be copied. * Return the gtp command id, or -1 if error. * slave_lock is held on both entry and exit of this function. */ static int send_command(char *to_send, void *bin_buf, int *bin_size, FILE *f, struct slave_state *sstate, char *buf) { assert(to_send && gtp_cmd && bin_buf && bin_size); strncpy(buf, to_send, CMDS_SIZE); bool resend = to_send != gtp_cmd; pthread_mutex_unlock(&slave_lock); if (DEBUGL(1) && resend) logline(&sstate->client, "? ", to_send == gtp_cmds ? "resend all\n" : "partial resend\n"); double start = time_now(); fputs(buf, f); if (*bin_size) fwrite(bin_buf, 1, *bin_size, f); fflush(f); if (DEBUGV(strchr(buf, '@'), 2)) { double ms = (time_now() - start) * 1000.0; if (!DEBUGL(3)) { char *s = strchr(buf, '\n'); if (s) s[1] = '\0'; } logline(&sstate->client, ">>", buf); if (*bin_size) { char b[1024]; snprintf(b, sizeof(b), "sent cmd %d+%d bytes in %.4fms\n", (int)strlen(buf), *bin_size, ms); logline(&sstate->client, "= ", b); } } /* Reuse the buffers for the reply. */ *bin_size = sstate->max_buf_size; int reply_id = get_reply(f, sstate->client, buf, bin_buf, bin_size); pthread_mutex_lock(&slave_lock); return reply_id; }
int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum) { char str[256]; int i,j; ushort nettype=NET_UNKNOWN; node_t node; user_t user; smbmsg_t newmsg; user.number=usernum; if(getuserdat(&cfg, &user)!=0) return(0); if((i=smb_copymsgmem(NULL,&newmsg,msg))!=SMB_SUCCESS) return(i); SAFECOPY(str,user.alias); smb_hfield_str(&newmsg,RECIPIENT,str); if(cfg.sys_misc&SM_FWDTONET && user.misc&NETMAIL && user.netmail[0]) { bprintf(text[UserNetMail],user.netmail); smb_hfield_netaddr(&newmsg,RECIPIENTNETADDR,user.netmail,&nettype); smb_hfield_bin(&newmsg,RECIPIENTNETTYPE,nettype); } else { sprintf(str,"%u",usernum); smb_hfield_str(&newmsg,RECIPIENTEXT,str); } j=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK); smb_freemsgmem(&newmsg); if(j!=SMB_SUCCESS) return(j); lncntr=0; bprintf(text[Emailing],user.alias,usernum); sprintf(str,"%s bulk-mailed %s #%d" ,useron.alias,user.alias,usernum); logline("E+",str); useron.emails++; logon_emails++; useron.etoday++; for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ getnodedat(i,&node,0); if(node.useron==usernum && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias); putnmsg(&cfg,i,str); break; } } if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ sprintf(str,text[UserSentYouMail],useron.alias); putsmsg(&cfg,usernum,str); } return(0); }
/* * Shuts down the server properly by freeing all allocated resources. */ void shutdown_server(int sig) { list_entry *cur = NULL; if ((sig == SIGINT) || (sig == SIGTERM)) { if (sig == SIGINT) logline(LOG_INFO, "Server shutdown requested per SIGINT. Performing cleanup ops now."); if (sig == SIGTERM) logline(LOG_INFO, "Server shutdown requested per SIGTERM. Performing cleanup ops now."); /* Close all socket connections immediately */ logline(LOG_INFO, "Closing socket connections..."); /* Iterate through client list and shutdown sockets */ cur = &list_start; while (cur != NULL) { /* Lock entry */ pthread_mutex_lock(cur->mutex); /* Send message to client */ if (cur->client_info != NULL) { close(cur->client_info->sockfd); } /* Unlock entry */ pthread_mutex_unlock(cur->mutex); /* Load next index */ cur = cur->next; } /* Close listener connection */ logline(LOG_INFO, "Shutting down listener..."); close(server_sockfd); /* Exit process */ logline(LOG_INFO, "Exiting. Byebye."); exit(0); } }
int test_all_permutations(void) { int p, w; bool has_failure = false; for (p = 0; p <= 5; p++) { for (w = 0; w <= 3; w++) { int testpid; int ret; testpid = fork(); if (testpid == 0) { logline("-------------------------------------------------------"); logline("*** Executing self-test: %s -p %d -w %d", getprogname(), p, w); test((parent_exit_t)p, (debugger_exit_t)w); _exit(1); /* never reached */ } else if (testpid == -1) { err(1, "failed to fork test pid"); } else { int stat_loc; ret = waitpid(testpid, &stat_loc, 0); if (ret == -1) err(1, "waitpid(%d) by test harness failed", testpid); logline("test process: %s", print_exit(testpid, stat_loc)); if (!WIFEXITED(stat_loc) || (0 != WEXITSTATUS(stat_loc))) { logline("FAILED TEST"); has_failure = true; } } } } if (has_failure) { logline("test failures found"); return 1; } return 0; }
/* Thread sending gtp commands to one slave machine, and * reading replies. If a slave machine dies, this thread waits * for a connection from another slave. * The large buffers are allocated only once we get a first * connection, to avoid wasting memory if max_slaves is too large. * We do not invalidate the received buffers if a slave disconnects; * they are still useful for other slaves. */ static void * slave_thread(void *arg) { struct slave_state sstate = default_sstate; sstate.thread_id = (long)arg; assert(sstate.slave_sock >= 0); char reply_buf[CMDS_SIZE]; bool resend = false; for (;;) { /* Wait for a connection from any slave. */ struct in_addr client; int conn = open_server_connection(sstate.slave_sock, &client); FILE *f = fdopen(conn, "r+"); if (DEBUGL(2)) { snprintf(reply_buf, sizeof(reply_buf), "new slave, id %d\n", sstate.thread_id); logline(&client, "= ", reply_buf); } if (!is_pachi_slave(f, &client)) continue; if (!resend) slave_state_alloc(&sstate); sstate.client = client; pthread_mutex_lock(&slave_lock); active_slaves++; slave_loop(f, reply_buf, &sstate, resend); assert(active_slaves > 0); active_slaves--; // Unblock main thread if it was waiting for this slave. pthread_cond_signal(&reply_cond); pthread_mutex_unlock(&slave_lock); resend = true; if (DEBUGL(2)) logline(&client, "= ", "lost slave\n"); fclose(f); } }
/* Clear the receive queue. The buffer pointers do not have to be cleared * here, this is done as each buffer is recycled. * slave_lock is held on both entry and exit of this function. */ void clear_receive_queue(void) { if (DEBUGL(3)) { char buf[1024]; snprintf(buf, sizeof(buf), "clear queue, old length %d age %d\n", queue_length, queue_age); logline(NULL, "? ", buf); } queue_length = 0; queue_age++; }
/* * Process a list of work items. */ void *proc_workitems(void *arg) { int ret = 0; workitem *wi_list; /* Cast input param to thread_params struct */ thread_params* t_params = (thread_params *)arg; wi_list = t_params->wi_list; logline(LOG_DEBUG, " Thread %d: Input params: reverse = %d, server = %s", t_params->thread_id, t_params->reverse, t_params->server); while (wi_list) { logline(LOG_DEBUG, " Thread %d: Processing workitem %s", t_params->thread_id, wi_list->wi); if (t_params->reverse) { ret = do_reverse_dns_lookup(t_params->server, wi_list->wi, &(t_params->result_list)); } else { ret = do_forward_dns_lookup(t_params->server, wi_list->wi, &(t_params->result_list)); } if (ret < 0) { if (ret == -2) { logline(LOG_ERROR, " Thread %d: DNS server temporarily not available. Skipping %s", t_params->thread_id, wi_list->wi); } else { logline(LOG_ERROR, " Thread %d: Error querying DNS server. Error code: %d", t_params->thread_id, ret); pthread_exit(&ret); } } wi_list = wi_list->next; } }
/*@null@*/ char * readline (const char *prompt){ char * ret; static char * (*func)(const char*); FN(func,char *,"readline",(const char *)); ret = (*func)(prompt); if(ret != NULL) logline(ret); return ret; }
bool sbbs_t::chksyspass() { char str[256],str2[256]; if(online==ON_REMOTE && !(cfg.sys_misc&SM_R_SYSOP)) { logline(LOG_NOTICE,"S!","Remote sysop access disabled"); return(false); } bputs(text[SystemPassword]); getstr(str,40,K_UPPER|K_NOECHO); CRLF; if(strcmp(cfg.sys_pass,str)) { if(cfg.sys_misc&SM_ECHO_PW) SAFEPRINTF3(str2,"%s #%u System password attempt: '%s'" ,useron.alias,useron.number,str); else SAFEPRINTF2(str2,"%s #%u System password verification failure" ,useron.alias,useron.number); logline(LOG_NOTICE,"S!",str2); return(false); } return(true); }
/* * Changes the nickname of an existing chat user. */ void change_nickname(char *oldnickname, char *newnickname) { struct list_entry *list_entry = NULL; client_info *ci_new = NULL; int idx = 0; logline(LOG_DEBUG, "change_nickname(): oldnickname = %s, newnickname = %s", oldnickname, newnickname); /* Load client_info element */ list_entry = llist_find_by_nickname(&list_start, oldnickname); /*Lock entry */ pthread_mutex_lock(list_entry->mutex); logline(LOG_DEBUG, "change_nickname(): client_info found. client_info->nickname = %s", list_entry->client_info->nickname); /* Update nickname */ strcpy(list_entry->client_info->nickname, newnickname); /* Unlock entry */ pthread_mutex_unlock(list_entry->mutex); }
/* Thread opening a connection on the given socket and copying input * from there to stderr. */ static void * proxy_thread(void *arg) { int proxy_sock = (long)arg; assert(proxy_sock >= 0); for (;;) { struct in_addr client; int conn = open_server_connection(proxy_sock, &client); FILE *f = fdopen(conn, "r"); char buf[BSIZE]; while (fgets(buf, BSIZE, f)) { logline(&client, "< ", buf); } fclose(f); } }
/* Minimimal check of slave identity. Close the file if error. */ static bool is_pachi_slave(FILE *f, struct in_addr *client) { char buf[1024]; fputs("name\n", f); if (!fgets(buf, sizeof(buf), f) || strncasecmp(buf, "= Pachi", 7) || !fgets(buf, sizeof(buf), f) || strcmp(buf, "\n")) { logline(client, "? ", "bad slave\n"); fclose(f); sleep(1); // avoid busy loop if error return false; } return true; }
void sbbs_t::change_user(void) { uint i; char str[256]; char tmp[128]; if(!chksyspass()) return; bputs(text[ChUserPrompt]); if(!getstr(str,LEN_ALIAS,K_UPPER)) return; if((i=finduser(str))==0) return; if(online==ON_REMOTE) { getuserrec(&cfg,i,U_LEVEL,2,str); if(atoi(str)>logon_ml) { getuserrec(&cfg,i,U_PASS,8,tmp); bputs(text[ChUserPwPrompt]); console|=CON_R_ECHOX; getstr(str,8,K_UPPER); console&=~(CON_R_ECHOX|CON_L_ECHOX); if(strcmp(str,tmp)) return; } } putmsgptrs(); putuserrec(&cfg,useron.number,U_CURSUB,0 ,cfg.sub[usrsub[curgrp][cursub[curgrp]]]->code); putuserrec(&cfg,useron.number,U_CURDIR,0 ,cfg.dir[usrdir[curlib][curdir[curlib]]]->code); useron.number=i; getuserdat(&cfg,&useron); getnodedat(cfg.node_num,&thisnode,1); thisnode.useron=useron.number; putnodedat(cfg.node_num,&thisnode); getmsgptrs(); if(REALSYSOP) sys_status&=~SS_TMPSYSOP; else sys_status|=SS_TMPSYSOP; sprintf(str,"Changed into %s #%u",useron.alias,useron.number); logline("S+",str); }
void ScriptLogger::Log(const char* fmt, char* args) { char* argStart = args; if(logFile) { FILE *f; _wfopen_s(&f, logFile, L"a"); if(f) { vfprintf_s(f, fmt, args); fclose(f); } } args = argStart; char buffer[MAX_LINE_LENGTH]; int charsWritten = vsnprintf_s(buffer, MAX_LINE_LENGTH, _TRUNCATE, fmt, args); std::string logline(buffer); if(charsWritten == -1) logline += "..."; int firstNewline = -1; while((firstNewline = logline.find("\n")) != -1) { logLines[currentLine].append(logline.substr(0, firstNewline)); logline = logline.substr(firstNewline + strlen("\n")); currentLine = (currentLine + 1 < numLines ? currentLine + 1 : 0); logLines[currentLine].clear(); } logLines[currentLine].append(logline.c_str()); args = argStart; vprintf(fmt, args); args = argStart; }
/* Insert a buffer in the receive queue. It should be the most * recent buffer allocated by the calling thread. * slave_lock is held on both entry and exit of this function. */ static void insert_buf(struct slave_state *sstate, void *buf, int size) { assert(queue_length < queue_max_length); int newest = sstate->newest_buf; assert(buf == sstate->b[newest].buf); /* Update the buffer if necessary before making it * available to other threads. */ if (sstate->insert_hook) sstate->insert_hook(buf, size); if (DEBUGVV(7)) { char b[1024]; snprintf(b, sizeof(b), "insert newest %d age %d rq[%d]->%p owner %d\n", newest, queue_age, queue_length, buf, sstate->thread_id); logline(&sstate->client, "? ", b); } receive_queue[queue_length] = &sstate->b[newest]; receive_queue[queue_length]->size = size; receive_queue[queue_length]->queue_index = queue_length; queue_length++; }
char sbbs_t::getkey(long mode) { char ch,coldkey,c=0,spin=sbbs_random(5); time_t last_telnet_cmd=0; if(!online || !input_thread_running) { YIELD(); // just in case someone is looping on getkey() when they shouldn't return(0); } sys_status&=~SS_ABORT; if((sys_status&SS_USERON || action==NODE_DFLT) && !(mode&(K_GETSTR|K_NOSPIN))) mode|=(useron.misc&SPIN); lncntr=0; timeout=time(NULL); if(mode&K_SPIN) outchar(' '); do { if(sys_status&SS_ABORT) { if(mode&K_SPIN) /* back space once if on spinning cursor */ backspace(); return(0); } if(mode&K_SPIN) { if(useron.misc&NO_EXASCII) { switch(c++) { case 0: outchar(BS); outchar('|'); break; case 1: outchar(BS); outchar('/'); break; case 2: outchar(BS); outchar('-'); break; case 3: outchar(BS); outchar('\\'); c=0; break; } } else { switch(spin) { case 0: switch(c++) { case 0: outchar(BS); outchar('³'); break; case 1: outchar(BS); outchar('/'); break; case 2: outchar(BS); outchar('Ä'); break; case 3: outchar(BS); outchar('\\'); c=0; break; } break; case 1: switch(c++) { case 0: outchar(BS); outchar('°'); break; case 1: outchar(BS); outchar('±'); break; case 2: outchar(BS); outchar('²'); break; case 3: outchar(BS); outchar('Û'); break; case 4: outchar(BS); outchar('²'); break; case 5: outchar(BS); outchar('±'); c=0; break; } break; case 2: switch(c++) { case 0: outchar(BS); outchar('-'); break; case 1: outchar(BS); outchar('='); break; case 2: outchar(BS); outchar('ð'); break; case 3: outchar(BS); outchar('='); c=0; break; } break; case 3: switch(c++) { case 0: outchar(BS); outchar('Ú'); break; case 1: outchar(BS); outchar('À'); break; case 2: outchar(BS); outchar('Ù'); break; case 3: outchar(BS); outchar('¿'); c=0; break; } break; case 4: switch(c++) { case 0: outchar(BS); outchar('Ü'); break; case 1: outchar(BS); outchar('Þ'); break; case 2: outchar(BS); outchar('ß'); break; case 3: outchar(BS); outchar('Ý'); c=0; break; } break; } } } ch=inkey(mode,mode&K_SPIN ? 250:1000); if(sys_status&SS_ABORT) return(0); now=time(NULL); if(ch) { if(mode&K_NUMBER && isprint(ch) && !isdigit(ch)) continue; if(mode&K_ALPHA && isprint(ch) && !isalpha(ch)) continue; if(mode&K_NOEXASC && ch&0x80) continue; if(mode&K_SPIN) backspace(); if(mode&K_COLD && ch>' ' && useron.misc&COLDKEYS) { if(mode&K_UPPER) outchar(toupper(ch)); else outchar(ch); while((coldkey=inkey(mode,1000))==0 && online && !(sys_status&SS_ABORT)) ; backspace(); if(coldkey==BS || coldkey==DEL) continue; if(coldkey>' ') ungetkey(coldkey); } if(mode&K_UPPER) return(toupper(ch)); return(ch); } if(sys_status&SS_USERON && !(sys_status&SS_LCHAT)) gettimeleft(); else if(online && now-answertime>SEC_LOGON && !(sys_status&SS_LCHAT)) { console&=~(CON_R_ECHOX|CON_L_ECHOX); console|=(CON_R_ECHO|CON_L_ECHO); bputs(text[TakenTooLongToLogon]); hangup(); } if(sys_status&SS_USERON && online && (timeleft/60)<(5-timeleft_warn) && !SYSOP && !(sys_status&SS_LCHAT)) { timeleft_warn=5-(timeleft/60); SAVELINE; attr(LIGHTGRAY); bprintf(text[OnlyXminutesLeft] ,((ushort)timeleft/60)+1,(timeleft/60) ? "s" : nulstr); RESTORELINE; } if(!(startup->options&BBS_OPT_NO_TELNET_GA) && now!=last_telnet_cmd && now-timeout>=60 && !((now-timeout)%60)) { // Let's make sure the socket is up // Sending will trigger a socket d/c detection send_telnet_cmd(TELNET_GA,0); last_telnet_cmd=now; } if(online==ON_REMOTE && !(console&CON_NO_INACT) && now-timeout>=cfg.sec_warn) { /* warning */ if(sys_status&SS_USERON && cfg.sec_warn!=cfg.sec_hangup) { SAVELINE; bputs(text[AreYouThere]); } else bputs("\7\7"); while(!inkey(K_NONE,100) && online && now-timeout>=cfg.sec_warn) { now=time(NULL); if(now-timeout>=cfg.sec_hangup) { if(online==ON_REMOTE) { console|=CON_R_ECHO; console&=~CON_R_ECHOX; } bputs(text[CallBackWhenYoureThere]); logline(nulstr,"Inactive"); hangup(); return(0); } } if(sys_status&SS_USERON && cfg.sec_warn!=cfg.sec_hangup) { bputs("\r\1n\1>"); RESTORELINE; } timeout=now; } } while(online); return(0); }
// writeLog() // // Write data to the HTTP log server // Log messages: // 1 : logged in // 2 : logged out // 3 : pedal dn // 4 : pedal up // 5 : software terminating normally // 6 : software terminating abnormally // 7 : Software error (i.e. Omni connection lost) // void ServerNForm::writeLog(QString log_message, QString log_level) { infoText->append( "Wrote to log: " + log_message +"." ); QTime t; t.start(); QDate d = QDate::currentDate(); QString surgeon_name(m_surgeon_name); QString time=t.toString("hh:mm:ss.zzz"); QString date; date=d.toString("dd-MMMM-yyyy"); QString logline(date + "\t" + time + "\t" + surgeon_name + "\t" + log_level + "\t" + log_message ); QUrl::encode(surgeon_name); QUrl::encode(log_message); QUrl::encode(time); // format log message: time, user, log_level, message QString B( "timestamp=" + time + "&user="******"&log_level=" + log_level + "&log_message=" + log_message ); QHttpRequestHeader header("POST", "/log_server/index.php"); header.setValue("Host", "brl.ee.washington.edu"); header.setContentType("application/x-www-form-urlencoded"); http.setHost("brl.ee.washington.edu"); http.request(header, B.utf8()); // TODO: Also write to a text file here QStringList lines; lines += logline.toLatin1(); QFile file( "logfile.txt" ); if ( file.open( IO_WriteOnly | IO_Append ) ) { QTextStream stream( &file ); for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) stream << *it << "\n"; file.close(); } }