static void cmd_room_typing2 (char *room) { int r; SLOT_LIST *sl; SLOT *sp; int nobody = 1; if (room[0]) { r = atoi (room); if (r < 1 || r > 99) { writestr (cur_slot, "Incorrect room number.\n"); setproc (sendpub, MAXMSG, 0); return; } } else r = cur_slot->acct.chan; if (r != cur_slot->acct.chan && !channels[r].name && cur_slot->acct.level != TOPLEVEL) { writestr (cur_slot, "Sorry, you cannot look into that room.\n"); setproc (sendpub, MAXMSG, 0); return; } for (sl = channels[r].members; sl; sl = sl->next) { sp = sl->slot; if (sp == cur_slot || !sp->flags.stopped) continue; if ((squelched (cur_slot, sp) || reversed (sp, cur_slot)) && cur_slot->acct.level != TOPLEVEL) continue; if (nobody) { if (channels[r].name) sprintf (msg_buf, "Users currently typing in room %02d (%s):\n", r, channels[r].name); else sprintf (msg_buf, "Users currently typing in room %02d (unnamed):\n", r); writestr (cur_slot, msg_buf); nobody = 0; } print_typing (sp); } if (nobody) { if (channels[r].name) sprintf (msg_buf, "Nobody is typing in room %02d (%s).\n", r, channels[r].name); else sprintf (msg_buf, "Nobody is typing in room %02d (unnamed).\n", r); writestr (cur_slot, msg_buf); } setproc (sendpub, MAXMSG, 0); }
static void change_pw3 (char *pw) { if (!alloctemp (cur_slot, MAXPW +1)) { setproc (sendpub, MAXMSG, 0); return; } strcpy (cur_slot->temp, pw); writestr (cur_slot, "Enter password again to verify: "); setproc (change_pw4, MAXPW, READ_NOECHO); }
static void change_pw2 (char *pw) { int err; err = db_pwd_compare (cur_slot->acct.id, pw); if (err == DB_SUCCESS) { writestr (cur_slot, "Enter new password (up to 12 characters in length): "); setproc (change_pw3, MAXPW, READ_NOECHO); } else { if (err == DB_EPASSWORD) writestr (cur_slot, "Password incorrect.\n"); else writestr (cur_slot, "Password change failed.\n"); setproc (sendpub, MAXMSG, 0); } }
static void change_nl (void) { sprintf (msg_buf, "Newline character is \"%c\".\n" "Enter newline character: ", (int)cur_slot->acct.nlchar); writestr (cur_slot, msg_buf); setproc (change_nl2, 2, COMPL_NONE); }
static void setwidth (void) { sprintf (msg_buf, "Current screen width is %d.\n" "New value: ", cur_slot->acct.width); writestr (cur_slot, msg_buf); setproc (setwidth2, 4, COMPL_NONE); }
static void change_nl2 (char *ch) { if (ch[0]) { cur_slot->acct.nlchar = ch[0]; sprintf (msg_buf, "Newline character changed to \"%c\".\n", (int)cur_slot->acct.nlchar); writestr (cur_slot, msg_buf); } setproc (sendpub, MAXMSG, 0); }
void proc_id (char *id) { SLOT *sp = NULL; char *offline_id = NULL; int err = 0; if (!id[0]) { setproc (sendpub, MAXMSG, 0); return; } if (slots_f && isdigit(id[0])) { sp = slotbynumber (id); if (!sp) { sprintf (msg_buf, "No such active slot: %s.\n", id); err = 1; } } else { sp = slotbyname (id); if (!sp) { if (cur_slot->flags.extid) { if (id[0] != '_' && db_pwd_exists (id) == DB_SUCCESS) { offline_id = id; } else { sprintf (msg_buf, "No such user: \"%s\".\n", id); err = 1; } } else { sprintf (msg_buf, "No such user online: \"%s\".\n", id); err = 1; } } } if (err) { writestr (cur_slot, msg_buf); setproc (sendpub, MAXMSG, 0); } else cur_slot->dispid (sp, offline_id); }
static void change_pw4 (char *pw) { if (strcmp (pw, cur_slot->temp)) { writestr (cur_slot, "Passwords do not match.\n"); } else { if (db_pwd_change (cur_slot->acct.id, crypt(pw, salt)) == DB_SUCCESS) { writestr (cur_slot, "Password changed.\n"); operact (cur_slot, (SLOT *)NULL, "changed password"); } else writestr(cur_slot, "Password change failed.\n"); } freetemp (cur_slot); setproc (sendpub, MAXMSG, 0); }
static void handle2 (char *h) { if (h[0]) { if (!strcmp (h, "NONE")) h[0] = '\0'; /* Inform @'s and %'s of the handle change */ sprintf (msg_buf, " * %s/%s is now %s/%s", cur_slot->acct.id, cur_slot->acct.handle, cur_slot->acct.id, h); strcpy (cur_slot->acct.handle, h); write_user (&cur_slot->acct); write_channel (msg_buf, cur_slot->acct.chan, PA_MSG); } setproc (sendpub, MAXMSG, 0); }
static void cmd_beep2 (SLOT *dst_slot, char *id) { char beep_code[] = "\a"; if (!squelched (dst_slot, cur_slot) && !reversed (cur_slot, dst_slot)) { sprintf (msg_buf, " * You are being *beeped* by %s/%s", cur_slot->acct.id, cur_slot->acct.handle); if (dst_slot->acct.beeping) { writestr (dst_slot, beep_code); } else strcat (msg_buf, "\n * BEEEEEEEEEEEEEEEEP!!!"); writeaction (dst_slot, msg_buf); } writestr (cur_slot, "Beep sent.\n"); setproc (sendpub, MAXMSG, 0); }
static void setwidth2 (char *buf) { int i; if (buf[0]) { if ((i = atoi (buf)) >= MINWIDTH && i <= MAXWIDTH) { cur_slot->acct.width = i; writestr (cur_slot, "Screen width changed.\n"); } else { sprintf (msg_buf, "Value must be between %d and %d.\n", MINWIDTH, MAXWIDTH); writestr (cur_slot, msg_buf); return; } } setproc (sendpub, MAXMSG, 0); }
int main(int argc, char ** argv) { char line[1024]; char buf1[1024]; char buf2[1024]; int pid, newpid; char *sp1, *sp2; FILE *wlog = fopen("/dev/null", "w"); FILE *rlog = fopen("/dev/null", "w"); FILE *logfile; int opt; while ( (opt = getopt(argc, argv, "w:r:")) != -1 ) { switch (opt) { case 'w': fclose(wlog); wlog = fopen(optarg, "w"); break; case 'r': fclose(rlog); rlog = fopen(optarg, "w"); break; default: fprintf(stderr, "Usage: %s [-w wlog-file] " "[-r rlog-file]\n", argv[0]); return 1; } } if (fgets(line, 1024, stdin) && sscanf(line, "%d", &pid) == 1 ) { newproc(pid, getcwd((char *) NULL, 0) ); } else { fprintf(stderr, "fl_stparse: Can't init using first line " "of input!\n"); return 1; } do { if ( sscanf(line, "%d fork() = %d", &pid, &newpid) == 2 || sscanf(line, "%d vfork() = %d", &pid, &newpid) == 2 || sscanf(line, "%d <... fork resumed> ) = %d", &pid, &newpid) == 2 || sscanf(line, "%d <... vfork resumed> ) = %d", &pid, &newpid) == 2) { sp1 = getproc(pid)->cwd; sp2 = malloc( strlen(sp1) + 1); strcpy(sp2, sp1); newproc(newpid, sp2 ); continue; } if ( sscanf(line, "%d _exit(%d", &pid, &newpid) == 2 || sscanf(line, "%d exit_group(%d", &pid, &newpid) == 2 ) { freeproc(pid); continue; } if ( sscanf(line, "%d chdir(\"%[^\"]", &pid, buf1) == 2 ) { if (chdir(getproc(pid)->cwd) < 0 || chdir(buf1) < 0) { fprintf(stderr, "fl_stparse: Can't get proc %d's cwd! %s\n", pid, strerror(errno)); exit(1); } setproc(pid, getcwd((char *) NULL, 0) ); continue; } if ( sscanf(line, "%d open(\"%[^\"]\", %s", &pid, buf1, buf2) == 3 ) { if (strstr(buf2, "O_RDONLY") == NULL) logfile = wlog; else logfile = rlog; if (strstr(buf2, "O_DIRECTORY") != NULL) continue; if (buf1[0] == '/') { fprintf(logfile, "%d: %s\n", pid, buf1); } else { sp1 = getproc(pid)->cwd; if (!strcmp(sp1, "/")) sp1=""; fprintf(logfile, "%d: %s/%s\n", pid, sp1, buf1); } continue; } if ( sscanf(line, "%d mkdir(\"%[^\"]\", ", &pid, buf1) == 2 || sscanf(line, "%d utime(\"%[^\"]\", ", &pid, buf1) == 2 || sscanf(line, "%d link(\"%[^\"]\", \"%[^\"]\"", &pid, buf2, buf1) == 3 || sscanf(line, "%d symlink(\"%[^\"]\", \"%[^\"]\"", &pid, buf2, buf1) == 3 || sscanf(line, "%d rename(\"%[^\"]\", \"%[^\"]\"", &pid, buf2, buf1) == 3 ) { if (buf1[0] == '/') { fprintf(wlog, "%d: %s\n", pid, buf1); } else { sp1 = getproc(pid)->cwd; if (!strcmp(sp1, "/")) sp1=""; fprintf(wlog, "%d: %s/%s\n", pid, sp1, buf1); } continue; } } while (fgets(line, 1024, stdin) != NULL); return 0; }
void build_in_dht() { #ifdef DHT static bool running = false; static mutex mut; static dht::DhtRunner ht; static int port = 4443; if (!running) { running = true; int port = 4443; dout << "firing up DHT on port " << port << endl; // Launch a dht node on a new thread, using a // generated RSA key pair, and listen on port 4222. ht.run(port, dht::crypto::generateIdentity(), true); // Join the network through any running node, // here using a known bootstrap node. ht.bootstrap("127.0.0.1", "4444"); // put some data on the dht std::vector<uint8_t> some_data(5, 10); ht.put("unique_key", some_data); // put some data on the dht, signed with our generated private key ht.putSigned("unique_key_42", some_data); } auto ht_ = &ht; EEE; string bu = "http://idni.org/dht#put"; auto bui = dict.set(mkiri(pstr(bu))); builtins[bui].push_back( [bu, entry, ht_](Thing *dummy, Thing *x) mutable { setproc(bu); TRACE_ENTRY; dout <<"sssss" << endl; switch(entry){ case 0: x = getValue(x); if(is_node(*x)) { node n = dict[get_node(*x)]; string v = *n.value; string key,val; if (n._type == node::IRI) { if (has(mykb->first, v)) { key = "root_graph_" + v; stringstream ss; ss << mykb->first[v]; val = ss.str(); } else { string h = strhash(v); key = "root_iri_" + h; val = v; } } else if (n._type == node::LITERAL) { string h = strhash(v); key = "root_lit_" + h; val = v; } else { dout << "nope." << endl; DONE; } dout << "putting " << key << "=" << val << endl; ht_->put(key, val); } else dout << "nope." << endl; END; } }); bu = "http://idni.org/dht#dbg"; bui = dict.set(mkiri(pstr(bu))); builtins[bui].push_back( [bu, entry, ht_](Thing *dummy, Thing *x) mutable { setproc(bu); TRACE_ENTRY; switch(entry){ case 0: x = getValue(x); if(is_node(*x)) { node n = dict[get_node(*x)]; string v = *n.value; if (v == "on") { MSG("dht dbg on"); enableDhtLogging(*ht_); } else{ MSG("dht dbg off"); ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG); } } END; } }); bu = "http://idni.org/dht#setPort"; bui = dict.set(mkiri(pstr(bu))); builtins[bui].push_back( [bu, entry, ht_](Thing *dummy, Thing *x) mutable { setproc(bu); TRACE_ENTRY; switch(entry){ case 0: x = getValue(x); if(is_node(*x)) { node n = dict[get_node(*x)]; string v = *n.value; if (v == "on") { MSG("dht dbg on"); enableDhtLogging(*ht_); } else{ MSG("dht dbg off"); ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG); } } END; } }); // get data from the dht ht_->get("other_unique_key", [](const std::vector<std::shared_ptr<dht::Value>>& values) { // Callback called when values are found for (const auto& value : values) dout << "Found value: " << *value << std::endl; return true; // return false to stop the search }); #endif }
void cmd_room_typing (void) { writestr (cur_slot, "Room number [default is the current room]: "); setproc (cmd_room_typing2, 3, COMPL_NONE); }
static void handle (void) { writestr (cur_slot, "New nickname: "); setproc (handle2, MAXHANDLE, COMPL_NONE); }
void setproc_id (void (*dispatch)(SLOT *sp, char *id), int mode) { cur_slot->dispid = dispatch; cur_slot->flags.extid = mode; setproc (proc_id, MAXID, COMPL_STRICT); }
static void change_pw (void) { writestr (cur_slot, "Enter old password: "); setproc (change_pw2, MAXPW, READ_NOECHO); }