Esempio n. 1
0
int
fetch_propvals(dbref obj, const char *dir)
{
    PropPtr p, pptr;
    int cnt = 0;
    char buf[BUFFER_LEN];
    char name[BUFFER_LEN];

    p = first_prop_nofetch(obj, dir, &pptr, name, sizeof(name));
    while (p) {
        cnt = (cnt || propfetch(obj, p));
        if (PropDir(p) || (PropFlags(p) & PROP_DIRUNLOADED)) {
            strcpyn(buf, sizeof(buf), dir);
            strcatn(buf, sizeof(buf), name);
            strcatn(buf, sizeof(buf), "/");
            if (PropFlags(p) & PROP_DIRUNLOADED) {
                SetPFlags(p, (PropFlags(p) & ~PROP_DIRUNLOADED));
                getproperties(input_file, obj, buf);
            }
            fetch_propvals(obj, buf);
        }
        p = next_prop(pptr, p, name, sizeof(name));
    }
    return cnt;
}
Esempio n. 2
0
static void
unparse_boolexp1(dbref player, struct boolexp *b, boolexp_type outer_type, int fullname)
{
	if ((buftop - boolexp_buf) > (BUFFER_LEN / 2))
		return;
	if (b == TRUE_BOOLEXP) {
		strcpyn(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), "*UNLOCKED*");
		buftop += strlen(buftop);
	} else {
		switch (b->type) {
		case BOOLEXP_AND:
			if (outer_type == BOOLEXP_NOT) {
				*buftop++ = '(';
			}
			unparse_boolexp1(player, b->sub1, b->type, fullname);
			*buftop++ = AND_TOKEN;
			unparse_boolexp1(player, b->sub2, b->type, fullname);
			if (outer_type == BOOLEXP_NOT) {
				*buftop++ = ')';
			}
			break;
		case BOOLEXP_OR:
			if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
				*buftop++ = '(';
			}
			unparse_boolexp1(player, b->sub1, b->type, fullname);
			*buftop++ = OR_TOKEN;
			unparse_boolexp1(player, b->sub2, b->type, fullname);
			if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) {
				*buftop++ = ')';
			}
			break;
		case BOOLEXP_NOT:
			*buftop++ = '!';
			unparse_boolexp1(player, b->sub1, b->type, fullname);
			break;
		case BOOLEXP_CONST:
			if (fullname) {
				strcpyn(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), unparse_object(player, b->thing));
			} else {
				snprintf(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), "#%d", b->thing);
			}
			buftop += strlen(buftop);
			break;
		case BOOLEXP_PROP:
			strcpyn(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), PropName(b->prop_check));
			strcatn(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), ":");
			if (PropType(b->prop_check) == PROP_STRTYP)
				strcatn(buftop, sizeof(boolexp_buf) - (buftop - boolexp_buf), PropDataStr(b->prop_check));
			buftop += strlen(buftop);
			break;
		default:
			abort();			/* bad type */
			break;
		}
	}
}
Esempio n. 3
0
const char *
mfn_ltimestr(MFUNARGS)
{
	int tm = atol(argv[0]);
	int wk, dy, hr, mn;
	char buf2[BUFFER_LEN];

	wk = dy = hr = mn = 0;
	if (tm >= 86400 * 7) {
		wk = (tm / 86400) / 7;	/* Weeks */
		tm %= (86400 * 7);
	}
	if (tm >= 86400) {
		dy = tm / 86400;		/* Days */
		tm %= 86400;
	}
	if (tm >= 3600) {
		hr = tm / 3600;			/* Hours */
		tm %= 3600;
	}
	if (tm >= 60) {
		mn = tm / 60;			/* Minutes */
		tm %= 60;				/* Seconds */
	}

	*buf = '\0';
	if (wk) {
		snprintf(buf, BUFFER_LEN, "%d week%s", wk, (wk == 1) ? "" : "s");
	}
	if (dy) {
		snprintf(buf2, BUFFER_LEN, "%d day%s", dy, (dy == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (hr) {
		snprintf(buf2, BUFFER_LEN, "%d hour%s", hr, (hr == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (mn) {
		snprintf(buf2, BUFFER_LEN, "%d min%s", mn, (mn == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (tm || !*buf) {
		snprintf(buf2, BUFFER_LEN, "%d sec%s", tm, (tm == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	return buf;
}
Esempio n. 4
0
static int mixdir(char *d, int create)
{
  int err;
  struct stat buf;

  if (d != MIXDIR)
    strncpy(MIXDIR, d, PATHMAX);
  if (MIXDIR[strlen(MIXDIR) - 1] == DIRSEP)
    MIXDIR[strlen(MIXDIR) - 1] = '\0';
  err = stat(MIXDIR, &buf);
  if (err == -1) {
    if (create) {
#ifndef POSIX
      err = mkdir(MIXDIR);
#else /* end of not POSIX */
      err = mkdir(MIXDIR, S_IRWXU);
#endif /* else if POSIX */
      if (err == 0)
	errlog(NOTICE, "Creating directory %s.\n", MIXDIR);
    } else
      err = 1;
  } else if (!S_ISDIR(buf.st_mode))
    err = -1;
  if (err == 0)
    strcatn(MIXDIR, DIRSEPSTR, PATHMAX);
  return (err);
}
Esempio n. 5
0
File: wiz.c Progetto: hyena/fuzzball
int
blessprops_wildcard(dbref player, dbref thing, const char *dir, const char *wild, int blessp)
{
	char propname[BUFFER_LEN];
	char wld[BUFFER_LEN];
	char buf[BUFFER_LEN];
	char buf2[BUFFER_LEN];
	char *ptr, *wldcrd = wld;
	PropPtr propadr, pptr;
	int i, cnt = 0;
	int recurse = 0;

#ifdef GOD_PRIV
	if(tp_strict_god_priv && !God(player) && God(OWNER(thing))) {
		notify(player,"Only God may touch what is God's.");
		return 0;
	}
#endif

	strcpyn(wld, sizeof(wld), wild);
	i = strlen(wld);
	if (i && wld[i - 1] == PROPDIR_DELIMITER)
		strcatn(wld, sizeof(wld), "*");
	for (wldcrd = wld; *wldcrd == PROPDIR_DELIMITER; wldcrd++) ;
	if (!strcmp(wldcrd, "**"))
		recurse = 1;

	for (ptr = wldcrd; *ptr && *ptr != PROPDIR_DELIMITER; ptr++) ;
	if (*ptr)
		*ptr++ = '\0';

	propadr = first_prop(thing, (char *) dir, &pptr, propname, sizeof(propname));
	while (propadr) {
		if (equalstr(wldcrd, propname)) {
			snprintf(buf, sizeof(buf), "%s%c%s", dir, PROPDIR_DELIMITER, propname);
			if (!Prop_System(buf) && ((!Prop_Hidden(buf) && !(PropFlags(propadr) & PROP_SYSPERMS))
				|| Wizard(OWNER(player)))) {
				if (!*ptr || recurse) {
					cnt++;
					if (blessp) {
						set_property_flags(thing, buf, PROP_BLESSED);
						snprintf(buf2, sizeof(buf2), "Blessed %s", buf);
					} else {
						clear_property_flags(thing, buf, PROP_BLESSED);
						snprintf(buf2, sizeof(buf2), "Unblessed %s", buf);
					}
					notify(player, buf2);
				}
				if (recurse)
					ptr = "**";
				cnt += blessprops_wildcard(player, thing, buf, ptr, blessp);
			}
		}
		propadr = next_prop(pptr, propadr, propname, sizeof(propname));
	}
	return cnt;
}
Esempio n. 6
0
void *
test_fun(void *parm)
{
    int process_id = get_process_id();
    int thread_id = ((struct parm *)parm)->id;
    int count = ((struct parm *)parm)->count;
    char *file_type = ((struct parm *)parm)->file_type;
    char file_path[MAX_FILE_PATH] = TEST_FILE_PREFIX;
    strcat(file_path, "test");
    strcat(file_path, file_type);
    strcat(file_path, "/");
    strcat(file_path, file_type);
    strcat(file_path, "_");
    
    int fds[count];
    char *buff[count];
    size_t sizes[count];

    printf("slave %d thread %d start to open file!\n", process_id, thread_id);
    int i;
    for(i = 0; i < count; i++) {
        char file[MAX_FILE_PATH];
        strcpy(file, file_path);
        strcatn(file, i);
        /* 需要在#include <fcntl.h>之前#define _GNU_SOURCE,NFS无对齐限制 */
        if((fds[i] = open(file, O_RDONLY | O_DIRECT | O_SYNC)) == -1) {
            printf("slave %d thread %d open failed!\n", process_id, thread_id);
            return (void *)-2;
        }
        sizes[i] = lseek(fds[i], 0, SEEK_END);
        lseek(fds[i], 0, SEEK_SET);
        buff[i] = (char *)malloc(sizes[i]);
        memset(buff[i], 0, sizes[i]);
    }

    struct timeval start, end;
    
    printf("slave %d thread %d start to read file from disk!\n", process_id, thread_id);
    gettimeofday(&start, NULL);
    for(i = 0; i < count; i++) {
        if (sizes[i] != read(fds[i], buff[i], sizes[i])) {
            printf("slave %d thread %d disk read error!\n", process_id, thread_id);
            return (void *)-3;
        }
    }
    gettimeofday(&end, NULL);
    double timeuse;
    timeuse = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec;
    timeuse /= 1000;
    printf("use %lf microseconds to read %d %s files from disk\n",timeuse, count, file_type);
    for(i = 0; i < count; i++) {
        close(fds[i]);
    }
    printf("slave %d thread %d end!\n", process_id, thread_id);
    return (void *)0;
}
Esempio n. 7
0
void askfilename(char *path)
{
  char line[PATHMAX];

  printw("\rFile name: ");
  echo();
  wgetnstr(stdscr, path, PATHMAX);
  noecho();
  printw("\r");
  if (path[0] == '~') {
    char *h;

    if ((h = getenv("HOME")) != NULL) {
      strncpy(line, h, PATHMAX);
      strcatn(line, "/", PATHMAX);
      strcatn(line, path + 1, PATHMAX);
      strncpy(path, line, PATHMAX);
    }
  }
}
Esempio n. 8
0
const char *
mfn_mklist(MFUNARGS)
{
	int i, len, tlen;
	int outcount = 0;

	tlen = 0;
	*buf = '\0';
	for (i = 0; i < argc; i++) {
		len = strlen(argv[i]);
		if (tlen + len + 2 < BUFFER_LEN) {
			if (outcount++)
				strcatn(buf, BUFFER_LEN, "\r");
			strcatn(buf, BUFFER_LEN, argv[i]);
			tlen += len;
		} else {
			ABORT_MPI("MKLIST", "Max string length exceeded.");
		}
	}
	return buf;
}
Esempio n. 9
0
const char *
mfn_online(MFUNARGS)
{
	int list_limit = MAX_MFUN_LIST_LEN;
	int count = pcount();
	char buf2[BUFFER_LEN];

	if (!(mesgtyp & MPI_ISBLESSED))
		ABORT_MPI("ONLINE", "Permission denied.");
	*buf = '\0';
	while (count && list_limit--) {
		if (*buf)
			strcatn(buf, BUFFER_LEN, "\r");
		ref2str(pdbref(count), buf2, sizeof(buf2));
		if ((strlen(buf) + strlen(buf2)) >= (BUFFER_LEN - 3))
			break;
		strcatn(buf, BUFFER_LEN, buf2);
		count--;
	}
	return buf;
}
Esempio n. 10
0
/* 初始化log文件 */
int
init_logger(char *path, int thread_num)
{
    int i;
    char path_buf[MAX_PATH_LENGTH];
    strcpy(path_buf, path);
    char *ptr = path_buf + strlen(path_buf);
    if (ptr[-1] != '/') {
        *ptr++ = '/';               /* 添加/ */
        *ptr = 0;
    }

    /* 构建相应的文件名 */
    int pid;
    if ((pid = get_process_id()) == 0) {
        strcat(path_buf, "master");
    } else {
        strcat(path_buf, "slave");
        strcatn(path_buf, pid);
    }
    
    strcat(path_buf, "thread");
    
    ptr = path_buf + strlen(path_buf);
    for (i = 0; i < thread_num; i++) {
        int pow = 1;
        int j = i / 10;
        while(j) {
            pow++;
            j /= 10;
        }
        j = i;
        ptr[pow--] = '\0';
        while (pow >= 0) {
            ptr[pow--] = '0' + (j % 10);
            j /= 10;
        }
        /* 打开文件,如不存在,则创建,目录之前应存在 */
        if (!(log_file[i] = fopen(strcat(path_buf, ".log"), "a"))) {
            return -1;
        }
    }

    /* 初始化每线程变量log id */
    return pthread_key_create(&log_id, NULL);
}
Esempio n. 11
0
File: lpd.c Progetto: dank101/3BSD
main(argc, argv)
{
	register char *p1, *p2;
	register int df;
	register FILE *dp;
	struct stat stb;

	signal(SIGHUP, SIG_IGN);
	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGTERM, SIG_IGN);
/*
 * Close all files, open root as 0, 1, 2
 * to assure standard environment
 */
	for (df=0; df<=15; df++)
		close(df);
	open("/", 0);
	dup(0);
	dup(0);
	if (stat("/usr/spool/lpd/lock", &stb) >= 0)
		exit(0);
	if ((df=creat("/usr/spool/lpd/lock", 0)) < 0)
		exit(0);
	close(df);
	if (fork())
		exit(0);
again:
	dp = fopen("/usr/spool/lpd", "r");
	do {
		if (fread(&dbuf, sizeof dbuf, 1, dp) != 1) {
			feedpage();
			unlink("/usr/spool/lpd/lock");
			exit(0);
		}
	} while (dbuf.d_ino==0 || dbuf.d_name[0]!='d' || dbuf.d_name[1]!='f');
	fclose(dp);
	strcpy(dfname, "/usr/spool/lpd/");
	strcatn(dfname, dbuf.d_name, DIRSIZ);
	if (trysend(dfname) == 0)
		goto again;
	sleep(waittm);
	goto again;
}
Esempio n. 12
0
void
prim_ftostrc(PRIM_PROTOTYPE)
{
	CHECKOP(1);
	oper1 = POP();
	if (oper1->type == PROG_INTEGER) {
		oper1->type = PROG_FLOAT;
		oper1->data.fnumber = oper1->data.number;
	}
	if (oper1->type != PROG_FLOAT)
		abort_interp("Non-float argument. (1)");
	snprintf(buf,sizeof(buf), "%.15g", oper1->data.fnumber);
	if (!strchr(buf, '.') && !strchr(buf, 'e') && !strchr(buf, 'n')) {
		strcatn(buf, sizeof(buf), ".0");
	}

	CLEAR(oper1);
	PushString(buf);
}
Esempio n. 13
0
/**
 * Return a string containing information about a given break point number
 *
 * Breakpoints are numbered from 0 onwards, but are displayed to the user
 * as starting from 1.
 *
 * @private
 * @param fr the current frame
 * @param brk the break point number to get information for
 * @return the string containing break point information
 */
static char *
unparse_breakpoint(struct frame *fr, int brk)
{
    static char buf[BUFFER_LEN];
    char buf2[BUFFER_LEN];
    dbref ref;

    snprintf(buf, sizeof(buf), "%2d) break", brk + 1);

    if (fr->brkpt.line[brk] != -1) {
        snprintf(buf2, sizeof(buf2), " in line %d", fr->brkpt.line[brk]);
        strcatn(buf, sizeof(buf), buf2);
    }

    if (fr->brkpt.pc[brk] != NULL) {
        ref = fr->brkpt.prog[brk];
        snprintf(buf2, sizeof(buf2), " at %s",
                 unparse_sysreturn(&ref, fr->brkpt.pc[brk] + 1));
        strcatn(buf, sizeof(buf), buf2);
    }

    if (fr->brkpt.linecount[brk] != -2) {
        snprintf(buf2, sizeof(buf2),
                 " after %d line(s)", fr->brkpt.linecount[brk]);
        strcatn(buf, sizeof(buf), buf2);
    }

    if (fr->brkpt.pccount[brk] != -2) {
        snprintf(buf2, sizeof(buf2),
                 " after %d instruction(s)", fr->brkpt.pccount[brk]);
        strcatn(buf, sizeof(buf), buf2);
    }

    if (fr->brkpt.prog[brk] != NOTHING) {
        snprintf(buf2, sizeof(buf2), " in %s(#%d)", NAME(fr->brkpt.prog[brk]),
                 fr->brkpt.prog[brk]);
        strcatn(buf, sizeof(buf), buf2);
    }

    if (fr->brkpt.level[brk] != -1) {
        snprintf(buf2, sizeof(buf2), " on call level %d", fr->brkpt.level[brk]);
        strcatn(buf, sizeof(buf), buf2);
    }

    return buf;
}
Esempio n. 14
0
void whoami(char *addr, char *defaultname)
{
  char *p = NULL;

#if defined(HAVE_GETDOMAINNAME) || (defined(HAVE_GETHOSTNAME) && ! defined(HAVE_UNAME))
  char line[LINELEN];

#endif /* defined(HAVE_GETDOMAINNAME) || [...] */
#ifdef HAVE_UNAME
  struct utsname uts;

#endif /* HAVE_UNAME */
#ifdef POSIX
  p = getlogin();
#endif /* POSIX */
  if (p == NULL)
    strcpy(addr, defaultname);
  else
    strncpy(addr, p, LINELEN);

  strcatn(addr, "@", LINELEN);
#ifdef HAVE_UNAME
  if (uname(&uts) != -1)
    strcatn(addr, uts.nodename, LINELEN);
#elif defined(HAVE_GETHOSTNAME) /* end of HAVE_UNAME */
  if (gethostname(line, LINELEN) == 0)
    strcatn(addr, line, LINELEN);
#endif /* defined(HAVE_GETHOSTNAME) */
  if (addr[strlen(addr) - 1] == '@')
    strcatn(addr, SHORTNAME, LINELEN);

  if (strchr(strchr(addr, '@'), '.') == NULL) {
#ifdef HAVE_GETDOMAINNAME
    if (getdomainname(line, LINELEN) == 0 && !streq(line, "(none)")) {
      strcatn(addr, ".", LINELEN);
      strcatn(addr, line, LINELEN);
    }
#endif /* HAVE_GETDOMAINNAME */
  }
}
Esempio n. 15
0
void
gui_ctrl_process_layout(McpMesg * msg, int layout)
{
	char buf[32];

	buf[0] = '\0';
	if ((layout & GUI_N))
		strcatn(buf, sizeof(buf), "n");

	if ((layout & GUI_S))
		strcatn(buf, sizeof(buf), "s");

	if ((layout & GUI_E))
		strcatn(buf, sizeof(buf), "e");

	if ((layout & GUI_W))
		strcatn(buf, sizeof(buf), "w");

	if (strcmp(buf, ""))
		mcp_mesg_arg_append(msg, "sticky", buf);


	snprintf(buf, sizeof(buf), "%d", GET_COLSKIP(layout));
	if (strcmp(buf, "0"))
		mcp_mesg_arg_append(msg, "colskip", buf);


	snprintf(buf, sizeof(buf), "%d", GET_COLSPAN(layout));
	if (strcmp(buf, "1"))
		mcp_mesg_arg_append(msg, "colspan", buf);


	snprintf(buf, sizeof(buf), "%d", GET_ROWSPAN(layout));
	if (strcmp(buf, "1"))
		mcp_mesg_arg_append(msg, "rowspan", buf);


	snprintf(buf, sizeof(buf), "%d", GET_LEFTPAD(layout));
	if (strcmp(buf, "0"))
		mcp_mesg_arg_append(msg, "leftpad", buf);


	snprintf(buf, sizeof(buf), "%d", GET_TOPPAD(layout));
	if (strcmp(buf, "0"))
		mcp_mesg_arg_append(msg, "toppad", buf);


	if ((layout & GUI_NONL))
		mcp_mesg_arg_append(msg, "newline", "0");

	if ((layout & GUI_HEXP))
		mcp_mesg_arg_append(msg, "hweight", "1");

	if ((layout & GUI_VEXP))
		mcp_mesg_arg_append(msg, "vweight", "1");

	if ((layout & GUI_REPORT))
		mcp_mesg_arg_append(msg, "report", "1");

	if ((layout & GUI_REQUIRED))
		mcp_mesg_arg_append(msg, "required", "1");
}
Esempio n. 16
0
void
listenqueue(int descr, dbref player, dbref where, dbref trigger, dbref what, dbref xclude,
			const char *propname, const char *toparg, int mlev, int mt, int mpi_p)
{
	const char *tmpchar;
	const char *pname, *sep, *ptr;
	dbref the_prog = NOTHING;
	char buf[BUFFER_LEN];
	char exbuf[BUFFER_LEN];
	char *ptr2;

	if (!(FLAGS(what) & LISTENER) && !(FLAGS(OWNER(what)) & ZOMBIE))
		return;

	the_prog = NOTHING;
	tmpchar = NULL;

	/* queue up program referred to by the given property */
	if (((the_prog = get_property_dbref(what, propname)) != NOTHING) ||
		(tmpchar = get_property_class(what, propname))) {

		if (tmpchar) {
			sep = tmpchar;
			while (*sep) {
				if (*sep == '\\') {
					sep++;
				} else if (*sep == '=') {
					break;
				}
				if (*sep)
					sep++;
			}
			if (*sep == '=') {
				for (ptr = tmpchar, ptr2 = buf; ptr < sep; *ptr2++ = *ptr++) ;
				*ptr2 = '\0';
				strcpyn(exbuf, sizeof(exbuf), toparg);
				if (!equalstr(buf, exbuf)) {
					tmpchar = NULL;
				} else {
					tmpchar = ++sep;
				}
			}
		}

		if ((tmpchar && *tmpchar) || the_prog != NOTHING) {
			if (tmpchar) {
				if (*tmpchar == '&') {
					the_prog = AMBIGUOUS;
				} else if (*tmpchar == NUMBER_TOKEN && number(tmpchar + 1)) {
					the_prog = (dbref) atoi(++tmpchar);
				} else if (*tmpchar == REGISTERED_TOKEN) {
					the_prog = find_registered_obj(what, tmpchar);
				} else if (number(tmpchar)) {
					the_prog = (dbref) atoi(tmpchar);
				} else {
					the_prog = NOTHING;
				}
			} else {
				if (the_prog == AMBIGUOUS)
					the_prog = NOTHING;
			}
			if (the_prog != AMBIGUOUS) {
				if (the_prog < 0 || the_prog >= db_top) {
					the_prog = NOTHING;
				} else if (Typeof(the_prog) != TYPE_PROGRAM) {
					the_prog = NOTHING;
				} else if (OWNER(the_prog) != OWNER(player) && !(FLAGS(the_prog) & LINK_OK)) {
					the_prog = NOTHING;
				} else if (MLevel(the_prog) < mlev) {
					the_prog = NOTHING;
				} else if (MLevel(OWNER(the_prog)) < mlev) {
					the_prog = NOTHING;
				} else if (the_prog == xclude) {
					the_prog = NOTHING;
				}
			}
			if (the_prog == AMBIGUOUS) {
				if (mpi_p) {
					add_mpi_event(1, descr, player, where, trigger, tmpchar + 1,
								  (mt ? "Listen" : "Olisten"), toparg, 1, (mt == 0),
								  Prop_Blessed(what, propname));
				}
			} else if (the_prog != NOTHING) {
				add_muf_queue_event(descr, player, where, trigger, the_prog, toparg,
									"(_Listen)", 1);
			}
		}
	}
	strcpyn(buf, sizeof(buf), propname);
	if (is_propdir(what, buf)) {
		strcatn(buf, sizeof(buf), "/");
		while ((pname = next_prop_name(what, exbuf, sizeof(exbuf), buf))) {
			*buf = '\0';
			strcatn(buf, sizeof(buf), pname);
			listenqueue(descr, player, where, trigger, what, xclude, buf,
						toparg, mlev, mt, mpi_p);
		}
	}
}
Esempio n. 17
0
void
propqueue(int descr, dbref player, dbref where, dbref trigger, dbref what, dbref xclude,
		  const char *propname, const char *toparg, int mlev, int mt)
{
	const char *tmpchar;
	const char *pname;
	dbref the_prog;
	char buf[BUFFER_LEN];
	char exbuf[BUFFER_LEN];

	the_prog = NOTHING;
	tmpchar = NULL;

	/* queue up program referred to by the given property */
	if (((the_prog = get_property_dbref(what, propname)) != NOTHING) ||
		(tmpchar = get_property_class(what, propname))) {

		if ((tmpchar && *tmpchar) || the_prog != NOTHING) {
			if (tmpchar) {
				if (*tmpchar == '&') {
					the_prog = AMBIGUOUS;
				} else if (*tmpchar == NUMBER_TOKEN && number(tmpchar + 1)) {
					the_prog = (dbref) atoi(++tmpchar);
				} else if (*tmpchar == REGISTERED_TOKEN) {
					the_prog = find_registered_obj(what, tmpchar);
				} else if (number(tmpchar)) {
					the_prog = (dbref) atoi(tmpchar);
				} else {
					the_prog = NOTHING;
				}
			} else {
				if (the_prog == AMBIGUOUS)
					the_prog = NOTHING;
			}
			if (the_prog != AMBIGUOUS) {
				if (the_prog < 0 || the_prog >= db_top) {
					the_prog = NOTHING;
				} else if (Typeof(the_prog) != TYPE_PROGRAM) {
					the_prog = NOTHING;
				} else if ((OWNER(the_prog) != OWNER(player)) && !(FLAGS(the_prog) & LINK_OK)) {
					the_prog = NOTHING;
				} else if (MLevel(the_prog) < mlev) {
					the_prog = NOTHING;
				} else if (MLevel(OWNER(the_prog)) < mlev) {
					the_prog = NOTHING;
				} else if (the_prog == xclude) {
					the_prog = NOTHING;
				}
			}
			if (propq_level < 8) {
				propq_level++;
				if (the_prog == AMBIGUOUS) {
					char cbuf[BUFFER_LEN];
					int ival;

					strcpyn(match_args, sizeof(match_args), "");
					strcpyn(match_cmdname, sizeof(match_cmdname), toparg);
					ival = (mt == 0) ? MPI_ISPUBLIC : MPI_ISPRIVATE;
					if (Prop_Blessed(what, propname))
						ival |= MPI_ISBLESSED;
					do_parse_mesg(descr, player, what, tmpchar + 1, "(MPIqueue)", cbuf, sizeof(cbuf), ival);
					if (*cbuf) {
						if (mt) {
							notify_filtered(player, player, cbuf, 1);
						} else {
							char bbuf[BUFFER_LEN];
							dbref plyr;

							snprintf(bbuf, sizeof(bbuf), ">> %.4000s",
									pronoun_substitute(descr, player, cbuf));
							plyr = DBFETCH(where)->contents;
							while (plyr != NOTHING) {
								if (Typeof(plyr) == TYPE_PLAYER && plyr != player)
									notify_filtered(player, plyr, bbuf, 0);
								plyr = DBFETCH(plyr)->next;
							}
						}
					}
				} else if (the_prog != NOTHING) {
					struct frame *tmpfr;

					strcpyn(match_args, sizeof(match_args), toparg ? toparg : "");
					strcpyn(match_cmdname, sizeof(match_cmdname), "Queued event.");
					tmpfr = interp(descr, player, where, the_prog, trigger,
								   BACKGROUND, STD_HARDUID, 0);
					if (tmpfr) {
						interp_loop(player, the_prog, tmpfr, 0);
					}
				}
				propq_level--;
			} else {
				notify_nolisten(player, "Propqueue stopped to prevent infinite loop.", 1);
			}
		}
	}
	strcpyn(buf, sizeof(buf), propname);
	if (is_propdir(what, buf)) {
		strcatn(buf, sizeof(buf), "/");
		while ((pname = next_prop_name(what, exbuf, sizeof(exbuf), buf))) {
			strcpyn(buf, sizeof(buf), pname);
			propqueue(descr, player, where, trigger, what, xclude, buf, toparg, mlev, mt);
		}
	}
}
Esempio n. 18
0
void menu_nym(char *nnym)
{
  char nym[maxnym][LINELEN];
  char pending[maxnym][LINELEN];
  int c, i, num = 0, numpending = 0, select = -1;
  int edit = 0;
  BUFFER *nymlist;
  int s;
  int pass = 0;
  char reliability[9]; /* When printing information about a chain,
			  this variable stores the reliability. */

  nymlist = buf_new();

  strcpy(nym[0], NONANON);
  strcatn(nym[0], " (", sizeof(nym[0]));
  strcatn(nym[0], NAME, sizeof(nym[0]));
  strcatn(nym[0], ")", sizeof(nym[0]));

  strcpy(nym[1], ANON);
  num = 2;
  if (nymlist_read(nymlist) == -1) {
    user_delpass();
    mix_status("");
  } else
    pass = 1;
  while (nymlist_get(nymlist, nym[num], NULL, NULL, NULL, NULL, NULL, &s) >= 0) {
    if (s == NYM_OK) {
      if (num < maxnym)
	num++;
    } else if (s == NYM_WAITING) {
      if (numpending < maxnym)
	strncpy(pending[numpending++], nym[num], LINELEN);
    }
  }
  buf_free(nymlist);

nymselect:
  clear();
  standout();
  printw("Select nym:\n\n");
  standend();
#ifdef USE_PGP
  if (pass)
    printw("c)reate new nym\ne)dit nym\nd)elete nym\n\n");
  else
    printw("[nym passphrase is invalid]\n\n");
#endif /* USE_PGP */
  for (i = 0; i < num; i++)
    printw("%d) %s\n", i, nym[i]);
  if (numpending > 0) {
    printw("\n\nWaiting for confirmation: ");
    for (i = 0; i < numpending; i++)
      printw("%s ", pending[i]);
    printw("\n");
  }
select:
  if (select != -1)
    printw("\r%d", select);
  else
    printw("\r          \r");
  refresh();
  c = getch();
  if (c == erasechar())
    c = KEY_BACKSPACE;
  if (c >= '0' && c <= '9') {
    if (select == -1)
      select = c - '0';
    else
      select = 10 * select + c - '0';
    if (edit ? select == 0 || select >= num + numpending - 1 : select >= num) {
      beep();
      select = -1;
    }
    refresh();
    goto select;
  } else
    switch (c) {
    case KEY_BACKSPACE:
      select /= 10;
      if (select < 1)
	select = -1;
      goto select;
    case 'q':
      if (edit) {
	edit = 0;
	select = -1;
	goto nymselect;
      }
      break;
#ifdef USE_PGP
    case 'e':
      if (pass) {
	if (edit || num + numpending < 3) {
	  edit = 0;
	  select = -1;
	  goto nymselect;
	} else {
	  clear();
	  standout();
	  printw("Edit nym:\n\n");
	  standend();
	  for (i = 2; i < num + numpending; i++)
	    printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
	  printw("\n");
	  select = -1;
	  edit = NYM_MODIFY;
	  goto select;
	}
      }
      break;
    case 'd':
      if (pass) {
	if (edit || num + numpending < 3) {
	  edit = 0;
	  select = -1;
	  goto nymselect;
	} else {
	  clear();
	  standout();
	  printw("Delete nym:\n\n");
	  standend();
	  for (i = 2; i < num + numpending; i++)
	    printw("%d) %s\n", i - 1, i < num ? nym[i] : pending[i - num]);
	  printw("\n");
	  select = -1;
	  edit = NYM_DELETE;
	  goto select;
	}
      }
      break;
    case '\r':
    case '\n':
      if (select == -1 || (edit && select == 0)) {
	beep();
	edit = 0;
	select = -1;
	goto nymselect;
      }
      if (!edit) {
	strncpy(nnym, nym[select], LINELEN);
	return;
      }
      /* fallthru */
    case 'c':
      if (pass) {
	char nymserv[LINELEN] = "*";
	char replyblock[5][CHAINMAX], dest[10][LINELEN];
	int latent[5], desttype[5];
	char mdest[LINELEN], pdest[LINELEN] = "alt.anonymous.messages",
	psub[LINELEN] = "";
	int deflatent = 0, defdesttype = MSG_MAIL;
	char alias[LINELEN] = "";
	BUFFER *name, *opt;
	char sendchain[CHAINMAX];
	int sendnumcopies = 1, rnum = 1;
	int i;
	char line[LINELEN];
	int acksend = 0, signsend = 0, fixedsize = 0, disable = 0,
	    fingerkey = 1;

	name = buf_new();
	opt = buf_new();
	strncpy(sendchain, CHAIN, CHAINMAX);
	strncpy(mdest, ADDRESS, LINELEN);
	if (edit)
	  strncpy(alias, select + 1 < num ? nym[select + 1] :
		  pending[select + 1 - num], LINELEN);
	if (edit == NYM_MODIFY) {
	  nymlist_getnym(alias, NULL, NULL, opt, name, NULL);
	  acksend = bufifind(opt, "+acksend");
	  signsend = bufifind(opt, "+signsend");
	  fixedsize = bufifind(opt, "+fixedsize");
	  disable = bufifind(opt, "+disable");
	  fingerkey = bufifind(opt, "+fingerkey");
	  rnum = -1;
	}
      newnym:
	if (!edit) {
	  clear();
	  standout();
	  printw("Create a nym:");
	  standend();

	  mvprintw(3, 0, "Alias address: ");
	  echo();
	  wgetnstr(stdscr, alias, LINELEN);
	  noecho();
	  if (alias[0] == '\0')
	    goto end;
	  for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
	  alias[i] = '\0';
	  if (i == 0)
	    goto newnym;
	  mvprintw(4, 0, "Pseudonym: ");
	  echo();
	  wgetnstr(stdscr, line, LINELEN);
	  noecho();
	  buf_sets(name, line);
	  menu_chain(nymserv, 2, 0);
	}
	if (edit != NYM_DELETE) {
	  for (i = 0; i < 5; i++) {
	    desttype[i] = defdesttype;
	    latent[i] = deflatent;
	    dest[i][0] = '\0';
	    strcpy(replyblock[i], "*,*,*,*");
	  }
	  if (rnum != -1) {
	    menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
			    replyblock[0]);
	    desttype[0] = defdesttype;
	    latent[0] = deflatent;
	    strncpy(dest[0], desttype[0] == MSG_POST ? pdest : mdest,
		    LINELEN);
	  }
	}
      redraw:
	clear();
	standout();
	switch (edit) {
	case NYM_DELETE:
	  printw("Delete nym:");
	  break;
	case NYM_MODIFY:
	  printw("Edit nym:");
	  break;
	default:
	  printw("Create a nym:");
	  break;
	}
	standend();
      loop:
	{
	  if (!edit) {
	    cl(2, 0);
	    printw("Nym: a)lias address: %s", alias);
	    cl(3, 0);
	    printw("     nym s)erver: %s", nymserv);
	  }
	  if (edit != NYM_DELETE) {
	    cl(4, 0);
	    printw("     p)seudonym: %s", name->data);
	    if (edit)
	      mvprintw(6, 0, "Nym modification:");
	    else
	      mvprintw(6, 0, "Nym creation:");
	  }
	  cl(7, 0);
	  chain_reliability(sendchain, 0, reliability); /* chaintype 0=mix */
	  printw("     c)hain to nym server: %-30s (reliability: %s)", sendchain, reliability);
	  cl(8, 0);
	  printw("     n)umber of redundant copies: %d", sendnumcopies);
	  if (edit != NYM_DELETE) {
	    mvprintw(10, 0, "Configuration:\n");
	    printw("     A)cknowledge sending: %s\n", acksend ? "yes" : "no");
	    printw("     S)erver signatures: %s\n", signsend ? "yes" : "no");
	    printw("     F)ixed size replies: %s\n", fixedsize ? "yes" :
		   "no");
	    printw("     D)isable: %s\n", disable ? "yes" : "no");
	    printw("     Finger K)ey: %s\n", fingerkey ? "yes" : "no");
	    mvprintw(17, 0, "Reply chains:");
	    cl(18, 0);
	    if (rnum == -1)
	      printw("     create new r)eply block");
	    else {
 	      printw("     number of r)eply chains: %2d                                     reliability", rnum);
	      for (i = 0; i < rnum; i++) {
		cl(i + 19, 0);
 		chain_reliability(replyblock[i], 1, reliability); /* 1=ek */
 		printw("     %d) %30s %-31s [%s]", i + 1,
  		       desttype[i] == MSG_NULL ?
 		       "(cover traffic)" : dest[i], replyblock[i],
 		       reliability);
	      }
	    }
	  }
	  move(LINES - 1, COLS - 1);
	  refresh();
	  c = getch();
	  if (edit != NYM_DELETE && c >= '1' && c <= '9' && c - '1' < rnum) {
	    menu_replychain(&defdesttype, &deflatent, mdest, pdest, psub,
			    replyblock[c - '1']);
	    desttype[c - '1'] = defdesttype;
	    latent[c - '1'] = deflatent;
	    strncpy(dest[c - '1'],
		    desttype[c - '1'] == MSG_POST ? pdest : mdest, LINELEN);
	    goto redraw;
	  }
	  switch (c) {
	  case 'A':
	    acksend = !acksend;
	    goto redraw;
	  case 'S':
	    signsend = !signsend;
	    goto redraw;
	  case 'F':
	    fixedsize = !fixedsize;
	    goto redraw;
	  case 'D':
	    disable = !disable;
	    goto redraw;
	  case 'K':
	    fingerkey = !fingerkey;
	    goto redraw;
	  case 'q':
	    edit = 0;
	    select = -1;
	    goto nymselect;
	  case '\014':
	    goto redraw;
	  case 'a':
	    cl(2, 0);
	    printw("Nym: a)lias address: ");
	    echo();
	    wgetnstr(stdscr, alias, LINELEN);
	    noecho();
	    for (i = 0; alias[i] > ' ' && alias[i] != '@'; i++) ;
	    alias[i] = '\0';
	    if (i == 0)
	      goto nymselect;
	    goto redraw;
	  case 'p':
	    cl(4, 0);
	    printw("     p)seudonym: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    if (line[0] != '\0')
	      buf_sets(name, line);
	    goto redraw;
	  case 'c':
	    menu_chain(sendchain, 0, 0);
	    goto redraw;
	  case 'n':
	    cl(8, 0);
	    printw("     n)umber of redundant copies: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    sendnumcopies = strtol(line, NULL, 10);
	    if (sendnumcopies < 1 || sendnumcopies > 10)
	      sendnumcopies = 1;
	    goto redraw;
	  case 'r':
	    cl(18, 0);
	    printw("     number of r)eply chains: ");
	    echo();
	    wgetnstr(stdscr, line, LINELEN);
	    noecho();
	    i = rnum;
	    rnum = strtol(line, NULL, 10);
	    if (rnum < 1)
	      rnum = 1;
	    if (rnum > 5)
	      rnum = 5;
	    for (; i < rnum; i++)
	      if (dest[i][0] == '\0') {
		desttype[i] = defdesttype;
		latent[i] = deflatent;
		strncpy(dest[i], defdesttype == MSG_POST ? pdest :
			mdest, LINELEN);
	      }
	    goto redraw;
	  case 's':
	    menu_chain(nymserv, 2, 0);
	    goto redraw;
	  case '\n':
	  case '\r':
	    {
	      BUFFER *chains;
	      int err;

	      if (rnum == -1)
		chains = NULL;
	      else {
		chains = buf_new();
		for (i = 0; i < rnum; i++)
		  if (replyblock[i][0] != '\0') {
		    if (desttype[i] == MSG_POST)
		      buf_appendf(chains, "Subject: %s\n", psub);
		    if (desttype[i] == MSG_MAIL)
		      buf_appends(chains, "To: ");
		    else if (desttype[i] == MSG_POST)
		      buf_appends(chains, "Newsgroups: ");
		    else
		      buf_appends(chains, "Null:");
		    buf_appendf(chains, "%s\n", dest[i]);
		    buf_appendf(chains, "Chain: %s\n", replyblock[i]);
		    buf_appendf(chains, "Latency: %d\n\n", latent[i]);
		  }
	      }
	    create:
	      clear();
	      buf_setf(opt,
		       " %cacksend %csignsend +cryptrecv %cfixedsize %cdisable %cfingerkey",
		       acksend ? '+' : '-',
		       signsend ? '+' : '-',
		       fixedsize ? '+' : '-',
		       disable ? '+' : '-',
		       fingerkey ? '+' : '-');
	      if (edit) {
		mix_status("Preparing nymserver configuration message...");
		err = nym_config(edit, alias, NULL,
				 name, sendchain, sendnumcopies,
				 chains, opt);
	      } else {
		mix_status("Preparing nym creation request...");
		err = nym_config(edit, alias, nymserv, name,
				 sendchain, sendnumcopies, chains,
				 opt);
	      }
	      if (err == -3) {
		beep();
		mix_status("Bad passphrase!");
		getch();
		goto create;
	      }
	      if (err != 0) {
		mix_genericerror();
		beep();
		refresh();
	      } else {
		if (edit)
		  mix_status("Nymserver configuration message completed.");
		else
		  mix_status("Nym creation request completed.");
	      }
	      if (chains)
		buf_free(chains);
	      goto end;
	    }
	  default:
	    beep();
	    goto loop;
	  }
	}
      end:
	buf_free(name);
	buf_free(opt);
	return;
      }
#endif /* USE_PGP */
    default:
      beep();
      goto select;
    }
}
Esempio n. 19
0
const char *
mfn_ltimestr(MFUNARGS)
{
	int tm = atol(argv[0]);
	int yr, mm, wk, dy, hr, mn;
	char buf2[BUFFER_LEN];

	yr = mm = wk = dy = hr = mn = 0;
	if (tm >= 31556736) {
		yr = tm / 31556736;	        /* Years */
		tm %= 31556736;
	}
	if (tm >= 2621376) {
		mm = tm / 2621376;	        /* Months */
		tm %= 2621376;
	}
	if (tm >= 604800) {
		wk = tm / 604800;	        /* Weeks */
		tm %= 604800;
	}
	if (tm >= 86400) {
		dy = tm / 86400;		/* Days */
		tm %= 86400;
	}
	if (tm >= 3600) {
		hr = tm / 3600;			/* Hours */
		tm %= 3600;
	}
	if (tm >= 60) {
		mn = tm / 60;			/* Minutes */
		tm %= 60;			/* Seconds */
	}

	*buf = '\0';
	if (yr) {
		snprintf(buf, BUFFER_LEN, "%d year%s", yr, (yr == 1) ? "" : "s");
	}
	if (mm) {
		snprintf(buf2, BUFFER_LEN, "%d month%s", mm, (mm == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (wk) {
		snprintf(buf2, BUFFER_LEN, "%d week%s", wk, (wk == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (dy) {
		snprintf(buf2, BUFFER_LEN, "%d day%s", dy, (dy == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (hr) {
		snprintf(buf2, BUFFER_LEN, "%d hour%s", hr, (hr == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (mn) {
		snprintf(buf2, BUFFER_LEN, "%d min%s", mn, (mn == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	if (tm || !*buf) {
		snprintf(buf2, BUFFER_LEN, "%d sec%s", tm, (tm == 1) ? "" : "s");
		if (*buf) {
			strcatn(buf, BUFFER_LEN, ", ");
		}
		strcatn(buf, BUFFER_LEN, buf2);
	}
	return buf;
}
Esempio n. 20
0
File: mcp.c Progetto: hyena/fuzzball
int
mcp_frame_output_mesg(McpFrame * mfr, McpMesg * msg)
{
	char outbuf[BUFFER_LEN * 2];
	int bufrem = sizeof(outbuf);
	char mesgname[128];
	char datatag[32];
	McpArg *anarg = NULL;
	int mlineflag = 0;
	char *p;
	char *out;
	int flushcount = 8;

	if (!mfr->enabled && strcmp_nocase(msg->package, MCP_INIT_PKG)) {
		return EMCP_NOMCP;
	}

	/* Create the message name from the package and message subnames */
	if (msg->mesgname && *msg->mesgname) {
		snprintf(mesgname, sizeof(mesgname), "%s-%s", msg->package, msg->mesgname);
	} else {
		snprintf(mesgname, sizeof(mesgname), "%s", msg->package);
	}

	strcpyn(outbuf, sizeof(outbuf), MCP_MESG_PREFIX);
	strcatn(outbuf, sizeof(outbuf), mesgname);
	if (strcmp_nocase(mesgname, MCP_INIT_PKG)) {
		McpVer nullver = { 0, 0 };

		strcatn(outbuf, sizeof(outbuf), " ");
		strcatn(outbuf, sizeof(outbuf), mfr->authkey);
		if (strcmp_nocase(msg->package, MCP_NEGOTIATE_PKG)) {
			McpVer ver = mcp_frame_package_supported(mfr, msg->package);

			if (!mcp_version_compare(ver, nullver)) {
				return EMCP_NOPACKAGE;
			}
		}
	}

	/* If the argument lines contain newlines, split them into separate lines. */
	for (anarg = msg->args; anarg; anarg = anarg->next) {
		if (anarg->value) {
			McpArgPart *ap = anarg->value;

			while (ap) {
				p = ap->value;
				while (*p) {
					if (*p == '\n' || *p == '\r') {
						McpArgPart *nu = (McpArgPart *) malloc(sizeof(McpArgPart));

						nu->next = ap->next;
						ap->next = nu;
						*p++ = '\0';
						nu->value = string_dup(p);
						ap->value = (char *) realloc(ap->value, strlen(ap->value) + 1);
						ap = nu;
						p = nu->value;
					} else {
						p++;
					}
				}
				ap = ap->next;
			}
		}
	}

	/* Build the initial message string */
	out = outbuf;
	bufrem = outbuf + sizeof(outbuf) - out;
	for (anarg = msg->args; anarg; anarg = anarg->next) {
		out += strlen(out);
		bufrem = outbuf + sizeof(outbuf) - out;
		if (!anarg->value) {
			anarg->was_shown = 1;
			snprintf(out, bufrem, " %s: %s", anarg->name, MCP_ARG_EMPTY);
			out += strlen(out);
			bufrem = outbuf + sizeof(outbuf) - out;
		} else {
			int totlen = strlen(anarg->value->value) + strlen(anarg->name) + 5;

			if (anarg->value->next || totlen > ((BUFFER_LEN - (out - outbuf)) / 2)) {
				/* Value is multi-line or too long.  Send on separate line(s). */
				mlineflag = 1;
				anarg->was_shown = 0;
				snprintf(out, bufrem, " %s*: %s", anarg->name, MCP_ARG_EMPTY);
			} else {
				anarg->was_shown = 1;
				snprintf(out, bufrem, " %s: ", anarg->name);
				out += strlen(out);
				bufrem = outbuf + sizeof(outbuf) - out;

				msgarg_escape(out, bufrem, anarg->value->value);
				out += strlen(out);
				bufrem = outbuf + sizeof(outbuf) - out;
			}
			out += strlen(out);
			bufrem = outbuf + sizeof(outbuf) - out;
		}
	}

	/* If the message is multi-line, make sure it has a _data-tag field. */
	if (mlineflag) {
		snprintf(datatag, sizeof(datatag), "%.8lX", (unsigned long)(RANDOM() ^ RANDOM()));
		snprintf(out, bufrem, " %s: %s", MCP_DATATAG, datatag);
		out += strlen(out);
		bufrem = outbuf + sizeof(outbuf) - out;
	}

	/* Send the initial line. */
	SendText(mfr, outbuf);
	SendText(mfr, "\r\n");

	if (mlineflag) {
		/* Start sending arguments whose values weren't already sent. */
		/* This is usually just multi-line argument values. */
		for (anarg = msg->args; anarg; anarg = anarg->next) {
			if (!anarg->was_shown) {
				McpArgPart *ap = anarg->value;

				while (ap) {
					*outbuf = '\0';
					snprintf(outbuf, sizeof(outbuf), "%s* %s %s: %s", MCP_MESG_PREFIX, datatag, anarg->name, ap->value);
					SendText(mfr, outbuf);
					SendText(mfr, "\r\n");
					if (!--flushcount) {
						FlushText(mfr);
						flushcount = 8;
					}
					ap = ap->next;
				}
			}
		}

		/* Let the other side know we're done sending multi-line arg vals. */
		snprintf(outbuf, sizeof(outbuf), "%s: %s", MCP_MESG_PREFIX, datatag);
		SendText(mfr, outbuf);
		SendText(mfr, "\r\n");
	}

	return EMCP_SUCCESS;
}
Esempio n. 21
0
/******** HOOK ********/
char *
mesg_parse(int descr, dbref player, dbref what, dbref perms,
    const char *inbuf, char *outbuf, int maxchars, int mesgtyp)
{
	char wbuf[BUFFER_LEN];
	char buf[BUFFER_LEN];
	char buf2[BUFFER_LEN];
	char dbuf[BUFFER_LEN];
	char ebuf[BUFFER_LEN];
	char cmdbuf[MAX_MFUN_NAME_LEN + 1];
	const char *ptr;
	char *dptr;
	int p, q, s;
	int i;
	char *argv[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
	int argc = 0;
	int showtextflag = 0;
	int literalflag = 0;

	mesg_rec_cnt++;
	if (mesg_rec_cnt > 26) {
		char *zptr = get_mvar("how");
		snprintf(dbuf, sizeof(dbuf), "%s Recursion limit exceeded.", zptr);
		notify_nolisten(player, dbuf, 1);
		mesg_rec_cnt--;
		outbuf[0] = '\0';
		return NULL;
	}
	if (Typeof(player) == TYPE_GARBAGE) {
		mesg_rec_cnt--;
		outbuf[0] = '\0';
		return NULL;
	}
	if (Typeof(what) == TYPE_GARBAGE) {
		notify_nolisten(player, "MPI Error: Garbage trigger.", 1);
		mesg_rec_cnt--;
		outbuf[0] = '\0';
		return NULL;
	}
	strcpyn(wbuf, sizeof(wbuf), inbuf);
	for (p = q = 0; wbuf[p] && (p < maxchars - 1) && q < (maxchars - 1); p++) {
		if (wbuf[p] == '\\') {
			p++;
			showtextflag = 1;
			if (wbuf[p] == 'r') {
				outbuf[q++] = '\r';
			} else if (wbuf[p] == '[') {
				outbuf[q++] = ESCAPE_CHAR;
			} else {
				outbuf[q++] = wbuf[p];
			}
		} else if (wbuf[p] == MFUN_LITCHAR) {
			literalflag = (!literalflag);
		} else if (!literalflag && wbuf[p] == MFUN_LEADCHAR) {
			if (wbuf[p + 1] == MFUN_LEADCHAR) {
				showtextflag = 1;
				outbuf[q++] = wbuf[p++];
				ptr = "";
			} else {
				ptr = wbuf + (++p);
				s = 0;
				while (wbuf[p] && wbuf[p] != MFUN_LEADCHAR &&
					   !isspace(wbuf[p]) && wbuf[p] != MFUN_ARGSTART &&
					   wbuf[p] != MFUN_ARGEND && s < MAX_MFUN_NAME_LEN) {
					p++;
					s++;
				}
				if (s < MAX_MFUN_NAME_LEN &&
					(wbuf[p] == MFUN_ARGSTART || wbuf[p] == MFUN_ARGEND)) {
					int varflag;

					strncpy(cmdbuf, ptr, s);
					cmdbuf[s] = '\0';

					varflag = 0;
					if (*cmdbuf == '&') {
						s = find_mfn("sublist");
						varflag = 1;
					} else if (*cmdbuf) {
						s = find_mfn(cmdbuf);
					} else {
						s = 0;
					}
					if (s) {
						s--;
						if (++mesg_instr_cnt > tp_mpi_max_commands) {
							char *zptr = get_mvar("how");

							snprintf(dbuf, sizeof(dbuf), "%s %c%s%c: Instruction limit exceeded.",
									zptr, MFUN_LEADCHAR,
									(varflag ? cmdbuf : mfun_list[s].name), MFUN_ARGEND);
							notify_nolisten(player, dbuf, 1);
							mesg_rec_cnt--;
							outbuf[0] = '\0';
							return NULL;
						}
						for (i = 0; i < argc; i++) {
							free(argv[i]);
							argv[i] = NULL;
						}
						if (wbuf[p] == MFUN_ARGEND) {
							argc = 0;
						} else {
							argc = mfun_list[s].maxargs;
							if (argc < 0) {
								argc = mesg_args((wbuf + p + 1), (sizeof(wbuf) - p - 1),
												 &argv[(varflag ? 1 : 0)],
												 MFUN_LEADCHAR, MFUN_ARGSEP,
												 MFUN_ARGEND, MFUN_LITCHAR,
												 (-argc) + (varflag ? 1 : 0));
							} else {
								argc = mesg_args((wbuf + p + 1), (sizeof(wbuf) - p - 1),
												 &argv[(varflag ? 1 : 0)],
												 MFUN_LEADCHAR, MFUN_ARGSEP,
												 MFUN_ARGEND, MFUN_LITCHAR, (varflag ? 8 : 9));
							}
							if (argc == -1) {
								char *zptr = get_mvar("how");

								snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: End brace not found.",
										zptr, MFUN_LEADCHAR, cmdbuf, MFUN_ARGEND);
								notify_nolisten(player, ebuf, 1);
								for (i = 0; i < argc; i++) {
									free(argv[i + (varflag? 1 : 0)]);
								}
								mesg_rec_cnt--;
								outbuf[0] = '\0';
								return NULL;
							}
						}
						if (varflag) {
							char *zptr;

							zptr = get_mvar(cmdbuf + 1);
							if (!zptr) {
								zptr = get_mvar("how");
								snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: Unrecognized variable.",
										zptr, MFUN_LEADCHAR, cmdbuf, MFUN_ARGEND);
								notify_nolisten(player, ebuf, 1);
								for (i = 0; i < argc; i++) {
									if (argv[i + (varflag? 1 : 0)]) {
										free(argv[i + (varflag? 1 : 0)]);
									}
								}
								mesg_rec_cnt--;
								outbuf[0] = '\0';
								return NULL;
							}
							if (argv[0]) {
								free(argv[0]);
								argv[0] = NULL;
							}
							argv[0] = string_dup(zptr);
							argc++;
						}
						if (mesgtyp & MPI_ISDEBUG) {
							char *zptr = get_mvar("how");

							snprintf(dbuf, sizeof(dbuf), "%s %*s%c%s%c", zptr,
									(mesg_rec_cnt * 2 - 4), "", MFUN_LEADCHAR,
									(varflag ? cmdbuf : mfun_list[s].name), MFUN_ARGSTART);
							for (i = (varflag ? 1 : 0); i < argc; i++) {
								if (i) {
									const char tbuf[] = { MFUN_ARGSEP, '\0' };
									strcatn(dbuf, sizeof(dbuf), tbuf);
								}
								cr2slash(ebuf, sizeof(ebuf)/8, argv[i]);
								strcatn(dbuf, sizeof(dbuf), "`");
								strcatn(dbuf, sizeof(dbuf), ebuf);
								if (strlen(ebuf) >= (sizeof(ebuf)/8)-2) {
									strcatn(dbuf, sizeof(dbuf), "...");
								}
								strcatn(dbuf, sizeof(dbuf), "`");
							}
							{
								const char tbuf[] = { MFUN_ARGEND, '\0' };
								strcatn(dbuf, sizeof(dbuf), tbuf);
							}
							notify_nolisten(player, dbuf, 1);
						}
						if (mfun_list[s].stripp) {
							for (i = (varflag ? 1 : 0); i < argc; i++) {
								stripspaces(buf, sizeof(buf), argv[i]);
								/*
								 * stripspaces() can only shorten a string.
								 * The argv[i] buffer will therefore always
								 * be large enough.
								 */
								strcpyn(argv[i], strlen(buf)+1, buf);
							}
						}
						if (mfun_list[s].parsep) {
							for (i = (varflag ? 1 : 0); i < argc; i++) {
								ptr = MesgParse(argv[i], buf, sizeof(buf));
								if (!ptr) {
									char *zptr = get_mvar("how");

									snprintf(dbuf, sizeof(dbuf), "%s %c%s%c (arg %d)", zptr,
											MFUN_LEADCHAR,
											(varflag ? cmdbuf : mfun_list[s].name),
											MFUN_ARGEND, i + 1);
									notify_nolisten(player, dbuf, 1);
									for (i = 0; i < argc; i++) {
										free(argv[i]);
									}
									mesg_rec_cnt--;
									outbuf[0] = '\0';
									return NULL;
								}
								argv[i] = (char*)realloc(argv[i], strlen(buf) + 1);
								strcpyn(argv[i], strlen(buf)+1, buf);
							}
						}
						if (mesgtyp & MPI_ISDEBUG) {
							char *zptr = get_mvar("how");

							snprintf(dbuf, sizeof(dbuf), "%.512s %*s%c%.512s%c", zptr,
									(mesg_rec_cnt * 2 - 4), "", MFUN_LEADCHAR,
									(varflag ? cmdbuf : mfun_list[s].name), MFUN_ARGSTART);
							for (i = (varflag ? 1 : 0); i < argc; i++) {
								if (i) {
									const char tbuf[] = { MFUN_ARGSEP, '\0' };
									strcatn(dbuf, sizeof(dbuf), tbuf);
								}
								cr2slash(ebuf, sizeof(ebuf)/8, argv[i]);
								strcatn(dbuf, sizeof(dbuf), "`");
								strcatn(dbuf, sizeof(dbuf), ebuf);
								if (strlen(ebuf) >= (sizeof(ebuf)/8)-2) {
									strcatn(dbuf, sizeof(dbuf), "...");
								}
								strcatn(dbuf, sizeof(dbuf), "`");
							}
							{
								const char tbuf[] = { MFUN_ARGEND, '\0' };
								strcatn(dbuf, sizeof(dbuf), tbuf);
							}
						}
						if (argc < mfun_list[s].minargs) {
							char *zptr = get_mvar("how");

							snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: Too few arguments",
									zptr, MFUN_LEADCHAR,
									(varflag ? cmdbuf : mfun_list[s].name), MFUN_ARGEND);
							notify_nolisten(player, ebuf, 1);
							for (i = 0; i < argc; i++) {
								free(argv[i]);
							}
							mesg_rec_cnt--;
							outbuf[0] = '\0';
							return NULL;
						} else if (mfun_list[s].maxargs > 0 && argc > mfun_list[s].maxargs) {
							char *zptr = get_mvar("how");

							snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: Too many arguments",
									zptr, MFUN_LEADCHAR,
									(varflag ? cmdbuf : mfun_list[s].name), MFUN_ARGEND);
							notify_nolisten(player, ebuf, 1);
							for (i = 0; i < argc; i++) {
								free(argv[i]);
							}
							mesg_rec_cnt--;
							outbuf[0] = '\0';
							return NULL;
						} else {
							ptr = mfun_list[s].mfn(descr, player, what, perms,
							    argc, argv, buf, sizeof(buf), mesgtyp);
							if (!ptr) {
								outbuf[q] = '\0';
								for (i = 0; i < argc; i++) {
									free(argv[i]);
								}
								mesg_rec_cnt--;
								outbuf[0] = '\0';
								return NULL;
							}
							if (mfun_list[s].postp) {
								dptr = MesgParse(ptr, buf, sizeof(buf));
								if (!dptr) {
									char *zptr = get_mvar("how");

									snprintf(ebuf, sizeof(ebuf), "%s %c%s%c (returned string)",
											zptr, MFUN_LEADCHAR,
											(varflag ? cmdbuf : mfun_list[s].name),
											MFUN_ARGEND);
									notify_nolisten(player, ebuf, 1);
									for (i = 0; i < argc; i++) {
										free(argv[i]);
									}
									mesg_rec_cnt--;
									outbuf[0] = '\0';
									return NULL;
								}
								ptr = dptr;
							}
						}
						if (mesgtyp & MPI_ISDEBUG) {
							strcatn(dbuf, sizeof(dbuf), " = `");
							cr2slash(ebuf, sizeof(ebuf)/8, ptr);
							strcatn(dbuf, sizeof(dbuf), ebuf);
							if (strlen(ebuf) >= (sizeof(ebuf)/8)-2) {
								strcatn(dbuf, sizeof(dbuf), "...");
							}
							strcatn(dbuf, sizeof(dbuf), "`");
							notify_nolisten(player, dbuf, 1);
						}
					} else if (msg_is_macro(player, what, perms, cmdbuf, mesgtyp)) {
						for (i = 0; i < argc; i++) {
							free(argv[i]);
							argv[i] = NULL;
						}
						if (wbuf[p] == MFUN_ARGEND) {
							argc = 0;
							p++;
						} else {
							p++;
							argc = mesg_args(wbuf + p, (sizeof(wbuf) - p), argv, MFUN_LEADCHAR,
											 MFUN_ARGSEP, MFUN_ARGEND, MFUN_LITCHAR, 9);
							if (argc == -1) {
								char *zptr = get_mvar("how");

								snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: End brace not found.",
										zptr, MFUN_LEADCHAR, cmdbuf, MFUN_ARGEND);
								notify_nolisten(player, ebuf, 1);
								for (i = 0; i < argc; i++) {
									free(argv[i]);
								}
								mesg_rec_cnt--;
								outbuf[0] = '\0';
								return NULL;
							}
						}
						msg_unparse_macro(player, what, perms, cmdbuf, argc,
										  argv, (wbuf + p), (BUFFER_LEN - p),
										  mesgtyp);
						p--;
						ptr = NULL;
					} else {
						/* unknown function */
						char *zptr = get_mvar("how");

						snprintf(ebuf, sizeof(ebuf), "%s %c%s%c: Unrecognized function.",
								zptr, MFUN_LEADCHAR, cmdbuf, MFUN_ARGEND);
						notify_nolisten(player, ebuf, 1);
						for (i = 0; i < argc; i++) {
							free(argv[i]);
						}
						mesg_rec_cnt--;
						outbuf[0] = '\0';
						return NULL;
					}
				} else {
					showtextflag = 1;
					ptr--;
					i = s + 1;
					while (ptr && *ptr && i-- && q < (maxchars - 1)) {
						outbuf[q++] = *(ptr++);
					}
					outbuf[q] = '\0';
					p = (int) (ptr - wbuf) - 1;
					ptr = "";	/* unknown substitution type */
				}
				while (ptr && *ptr && q < (maxchars - 1)) {
					outbuf[q++] = *(ptr++);
				}
			}
		} else {
			outbuf[q++] = wbuf[p];
			showtextflag = 1;
		}
	}
	outbuf[q] = '\0';
	if ((mesgtyp & MPI_ISDEBUG) && showtextflag) {
		char *zptr = get_mvar("how");

		snprintf(dbuf, sizeof(dbuf), "%s %*s`%.512s`",
		        zptr, (mesg_rec_cnt * 2 - 4), "",
				cr2slash(buf2, sizeof(buf2), outbuf));
		notify_nolisten(player, dbuf, 1);
	}
	for (i = 0; i < argc; i++) {
		free(argv[i]);
	}
	mesg_rec_cnt--;
	outbuf[maxchars - 1] = '\0';
	return (outbuf);
}
Esempio n. 22
0
void
do_info(dbref player, const char *topic, const char *seg)
{
	char *buf;
	int f;
	int cols;
	int buflen = 80;

#ifdef DIR_AVALIBLE
	DIR *df;
	struct dirent *dp;
#endif
#ifdef WIN32
	HANDLE  hFind;
	BOOL    bMore;
	WIN32_FIND_DATA finddata;
	char    *dirname;
	int dirnamelen = 0;
#endif

	if (*topic) {
		if (!show_subfile(player, INFO_DIR, topic, seg, TRUE)) {
			notify(player, NO_INFO_MSG);
		}
	} else {
#ifdef DIR_AVALIBLE
		buf = (char *) calloc(1, buflen);
		(void) strcpyn(buf, buflen, "    ");
		f = 0;
		cols = 0;
		if ((df = (DIR *) opendir(INFO_DIR))) {
			while ((dp = readdir(df))) {

				if (*(dp->d_name) != '.') {
					if (!f)
						notify(player, "Available information files are:");
					if ((cols++ > 2) || ((strlen(buf) + strlen(dp->d_name)) > 63)) {
						notify(player, buf);
						strcpyn(buf, buflen, "    ");
						cols = 0;
					}
					strcatn(buf, buflen, dp->d_name);
					strcatn(buf, buflen, " ");
					f = strlen(buf);
					while ((f % 20) != 4)
						buf[f++] = ' ';
					buf[f] = '\0';
				}
			}
			closedir(df);
		}
		if (f)
			notify(player, buf);
		else
			notify(player, "No information files are available.");
		free(buf);
#elif WIN32
		buf = (char *) calloc(1,buflen);
		(void) strcpyn(buf, buflen, "    ");
		f = 0;
		cols = 0;

		dirnamelen = strlen(INFO_DIR) + 4;
		dirname = (char *) malloc(dirnamelen);
		strcpyn(dirname, dirnamelen, INFO_DIR);
		strcatn(dirname, dirnamelen, "*.*");
		hFind = FindFirstFile(dirname,&finddata);
		bMore = (hFind != (HANDLE) -1);

		free(dirname);

		while (bMore) {
			if (!(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
				if (!f)
					notify(player, "Available information files are:");
				if ((cols++ > 2) || ((strlen(buf) + strlen(finddata.cFileName)) > 63)) {
					notify(player,buf);
					(void) strcpyn(buf, buflen, "    ");
					cols = 0;
				}
			    strcatn(buf, buflen, finddata.cFileName);
			    strcatn(buf, buflen, " ");
				f = strlen(buf);
				while((f %20) != 4)
					buf[f++] = ' ';
				buf[f] = '\0';
			}
			bMore = FindNextFile(hFind, &finddata);
		}
		
		if (f)
			notify(player, buf);
		else
			notify(player, "There are no information files available.");

		free(buf);
#else							/* !DIR_AVALIBLE && !WIN32 */
		notify(player, "Index not available on this system.");
#endif							/* !DIR_AVALIBLE && !WIN32 */
	}
}
Esempio n. 23
0
/**
 * This is for showing line listings in "instruction" format.
 *
 * This returns a single line of code's primitives.  It uses a static buffer,
 * so be careful with it.  Not multi-threaded.
 *
 * @param program the program to show listings for
 * @param pc the program counter where the listing starts
 * @param maxprims the maximum primitives
 * @param markpc do a special mark when listing the 'pc' line
 * @return pointer to static buffer containing primitives
 */
char *
show_line_prims(dbref program, struct inst *pc, int maxprims, int markpc)
{
    static char buf[BUFFER_LEN];
    static char buf2[BUFFER_LEN];
    int maxback;
    int thisline = pc->line;
    struct inst *code, *end, *linestart, *lineend;

    code = PROGRAM_CODE(program);
    end = code + PROGRAM_SIZ(program);
    buf[0] = '\0';

    /*
     * This code is to determine the end of the line.  There can be multiple
     * primitives on the same line.  This series of loops finds the end
     * of the line, so we can iterate over the primitives between start and
     * end to form our return string.
     */
    for (linestart = pc, maxback = maxprims; linestart > code &&
         linestart->line == thisline && linestart->type != PROG_FUNCTION &&
         --maxback; --linestart) ;

    if (linestart->line < thisline)
        ++linestart;

    for (lineend = pc + 1, maxback = maxprims; lineend < end &&
         lineend->line == thisline && lineend->type != PROG_FUNCTION &&
         --maxback; ++lineend) ;

    if (lineend >= end || lineend->line > thisline || lineend->type == PROG_FUNCTION)
        --lineend;

    if (lineend - linestart >= maxprims) {
        if (pc - (maxprims - 1) / 2 > linestart)
            linestart = pc - (maxprims - 1) / 2;

        if (linestart + maxprims - 1 < lineend)
            lineend = linestart + maxprims - 1;
    }

    if (linestart > code && (linestart - 1)->line == thisline)
        strcpyn(buf, sizeof(buf), "...");

    /*
     * We're in the right position; loop from linestart til lineend,
     * putting together text versions of the instructions.
     */ 
    while (linestart <= lineend) {
        if (strlen(buf) < BUFFER_LEN / 2) {
            if (*buf)
                strcatn(buf, sizeof(buf), " ");

            if (pc == linestart && markpc) {
                strcatn(buf, sizeof(buf), " {{");
                strcatn(buf, sizeof(buf),
                        insttotext(NULL, 0, linestart, buf2, sizeof(buf2), 30,
                                   program, 1));
                strcatn(buf, sizeof(buf), "}} ");
            } else {
                strcatn(buf, sizeof(buf),
                        insttotext(NULL, 0, linestart, buf2, sizeof(buf2), 30,
                                   program, 1));
            }
        } else {
            break;
        }

        linestart++;
    }

    if (lineend < end && (lineend + 1)->line == thisline)
        strcatn(buf, sizeof(buf), " ...");

    return buf;
}
Esempio n. 24
0
int
show_subfile(dbref player, const char *dir, const char *topic, const char *seg, int partial)
{
	char buf[256];
	struct stat st;

#ifdef DIR_AVALIBLE
	DIR *df;
	struct dirent *dp;
#endif

#ifdef WIN32
	char   *dirname;
	int dirnamelen = 0;
	HANDLE  hFind;
	BOOL    bMore;
	WIN32_FIND_DATA finddata;
#endif

	if (!topic || !*topic)
		return 0;

	if ((*topic == '.') || (*topic == '~') || (index(topic, '/'))) {
		return 0;
	}
	if (strlen(topic) > 63)
		return 0;


#ifdef DIR_AVALIBLE
	/* TO DO: (1) exact match, or (2) partial match, but unique */
	*buf = 0;

	if ((df = (DIR *) opendir(dir))) {
		while ((dp = readdir(df))) {
			if ((partial && string_prefix(dp->d_name, topic)) ||
				(!partial && !string_compare(dp->d_name, topic))
					) {
				snprintf(buf, sizeof(buf), "%s/%s", dir, dp->d_name);
				break;
			}
		}
		closedir(df);
	}

	if (!*buf) {
		return 0;				/* no such file or directory */
	}
#elif WIN32
	/* TO DO: (1) exact match, or (2) partial match, but unique */
	*buf = 0;

	dirnamelen = strlen(dir) + 5;
	dirname = (char *) malloc(dirnamelen);
	strcpyn(dirname, dirnamelen, dir);
	strcatn(dirname, dirnamelen, "/*.*");
	hFind = FindFirstFile(dirname,&finddata);
	bMore = (hFind != (HANDLE) -1);

	free(dirname);

	while (bMore) {
		if (!(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
			if ((partial && string_prefix(finddata.cFileName, topic)) ||
				(!partial && !string_compare(finddata.cFileName,topic))
				)
			{
				snprintf(buf, sizeof(buf), "%s/%s", dir, finddata.cFileName);
				break;
			}
		}
		bMore = FindNextFile(hFind, &finddata);
	}
#else                           /* !DIR_AVAILABLE && !WIN32 */
	snprintf(buf, sizeof(buf), "%s/%s", dir, topic);
#endif 

	if (stat(buf, &st)) {
		return 0;
	} else {
		spit_file_segment(player, buf, seg);
		return 1;
	}
}
Esempio n. 25
0
void
mcppkg_help_request(McpFrame * mfr, McpMesg * msg, McpVer ver, void *context)
{
	FILE *f;
	const char* file;
	char buf[BUFFER_LEN];
	char topic[BUFFER_LEN];
	char *p;
	int arglen, found;
	McpVer supp = mcp_frame_package_supported(mfr, "org-fuzzball-help");
	McpMesg omsg;

	if (supp.verminor == 0 && supp.vermajor == 0) {
		notify(mcpframe_to_user(mfr), "MCP: org-fuzzball-help not supported.");
		return;
	}

	if (!string_compare(msg->mesgname, "request")) {
		char *onwhat;
		char *valtype;

		onwhat = mcp_mesg_arg_getline(msg, "topic", 0);
		valtype = mcp_mesg_arg_getline(msg, "type", 0);

		*topic = '\0';
		strcpyn(topic, sizeof(topic), onwhat);
		if (*onwhat) {
			strcatn(topic, sizeof(topic), "|");
		}

		if (!string_compare(valtype, "man")) {
			file = MAN_FILE;
		} else if (!string_compare(valtype, "mpi")) {
			file = MPI_FILE;
		} else if (!string_compare(valtype, "help")) {
			file = HELP_FILE;
		} else if (!string_compare(valtype, "news")) {
			file = NEWS_FILE;
		} else {
			snprintf(buf, sizeof(buf), "Sorry, %s is not a valid help type.", valtype);
			mcp_mesg_init(&omsg, "org-fuzzball-help", "error");
			mcp_mesg_arg_append(&omsg, "text", buf);
			mcp_mesg_arg_append(&omsg, "topic", onwhat);
			mcp_frame_output_mesg(mfr, &omsg);
			mcp_mesg_clear(&omsg);
			return;
		}

		if ((f = fopen(file, "rb")) == NULL) {
			snprintf(buf, sizeof(buf), "Sorry, %s is missing.  Management has been notified.", file);
			fprintf(stderr, "help: No file %s!\n", file);
			mcp_mesg_init(&omsg, "org-fuzzball-help", "error");
			mcp_mesg_arg_append(&omsg, "text", buf);
			mcp_mesg_arg_append(&omsg, "topic", onwhat);
			mcp_frame_output_mesg(mfr, &omsg);
			mcp_mesg_clear(&omsg);
		} else {
			if (*topic) {
				arglen = strlen(topic);
				do {
					do {
						if (!(fgets(buf, sizeof buf, f))) {
							snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat);
							fclose(f);
							mcp_mesg_init(&omsg, "org-fuzzball-help", "error");
							mcp_mesg_arg_append(&omsg, "text", buf);
							mcp_mesg_arg_append(&omsg, "topic", onwhat);
							mcp_frame_output_mesg(mfr, &omsg);
							mcp_mesg_clear(&omsg);
							return;
						}
					} while (*buf != '~');
					do {
						if (!(fgets(buf, sizeof buf, f))) {
							snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat);
							fclose(f);
							mcp_mesg_init(&omsg, "org-fuzzball-help", "error");
							mcp_mesg_arg_append(&omsg, "text", buf);
							mcp_mesg_arg_append(&omsg, "topic", onwhat);
							mcp_frame_output_mesg(mfr, &omsg);
							mcp_mesg_clear(&omsg);
							return;
						}
					} while (*buf == '~');
					p = buf;
					found = 0;
					buf[strlen(buf) - 1] = '|';
					while (*p && !found) {
						if (strncasecmp(p, topic, arglen)) {
							while (*p && (*p != '|'))
								p++;
							if (*p)
								p++;
						} else {
							found = 1;
						}
					}
				} while (!found);
			}
			mcp_mesg_init(&omsg, "org-fuzzball-help", "entry");
			mcp_mesg_arg_append(&omsg, "topic", onwhat);
			while (fgets(buf, sizeof buf, f)) {
				if (*buf == '~')
					break;
				for (p = buf; *p; p++) {
					if (*p == '\n' || *p == '\r') {
						*p = '\0';
						break;
					}
				}
				if (!*buf) {
					strcpyn(buf, sizeof(buf), "  ");
				}
				mcp_mesg_arg_append(&omsg, "text", buf);
			}
			fclose(f);
			mcp_frame_output_mesg(mfr, &omsg);
			mcp_mesg_clear(&omsg);
		}
	}
}
Esempio n. 26
0
void
index_file(dbref player, const char *onwhat, const char *file)
{
	FILE *f;
	char buf[BUFFER_LEN];
	char topic[BUFFER_LEN];
	char *p;
	int arglen, found;

	*topic = '\0';
	strcpyn(topic, sizeof(topic), onwhat);
	if (*onwhat) {
		strcatn(topic, sizeof(topic), "|");
	}

	if ((f = fopen(file, "rb")) == NULL) {
		snprintf(buf, sizeof(buf), "Sorry, %s is missing.  Management has been notified.", file);
		notify(player, buf);
		fprintf(stderr, "help: No file %s!\n", file);
	} else {
		if (*topic) {
			arglen = strlen(topic);
			do {
				do {
					if (!(fgets(buf, sizeof buf, f))) {
						snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat);
						notify(player, buf);
						fclose(f);
						return;
					}
				} while (*buf != '~');
				do {
					if (!(fgets(buf, sizeof buf, f))) {
						snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat);
						notify(player, buf);
						fclose(f);
						return;
					}
				} while (*buf == '~');
				p = buf;
				found = 0;
				buf[strlen(buf) - 1] = '|';
				while (*p && !found) {
					if (strncasecmp(p, topic, arglen)) {
						while (*p && (*p != '|'))
							p++;
						if (*p)
							p++;
					} else {
						found = 1;
					}
				}
			} while (!found);
		}
		while (fgets(buf, sizeof buf, f)) {
			if (*buf == '~')
				break;
			for (p = buf; *p; p++) {
				if (*p == '\n' || *p == '\r') {
					*p = '\0';
					break;
				}
			}
			if (*buf) {
				notify(player, buf);
			} else {
				notify(player, "  ");
			}
		}
		fclose(f);
	}
}
Esempio n. 27
0
int mix_config(void)
{
  char *d;
  FILE *f;
  char line[PATHMAX];
  int err = -1;
#ifdef POSIX
  struct passwd *pw;
#endif /* POSIX */
  struct stat buf;
#ifdef HAVE_UNAME
  struct utsname uts;
#endif /* HAVE_UNAME */
#ifdef WIN32
  HKEY regsw, reg, regpgp;
  DWORD type, len;
  int rkey = 0;
#endif /* WIN32 */

  mix_setdefaults();

#ifdef POSIX
  pw = getpwuid(getuid());
#endif /* POSIX */

 /* find our base directory
  *
  * first match wins.
  *
  *  - what the MIXPATH environment variable points to, if it is set.
  *  - On WIN32, HKEY_CURRENT_USER\Software\Mixmaster\MixDir, if it exists
  *  - whatever is compiled in with -DSPOOL
  *  - On Win32 %APPDATA%\Mixmaster
  *  - on POSIX, ~/Mix  (or ~/<HOMEMIXDIR>)
  *  - the current working directory
  */

  if (err == -1 && (d = getenv("MIXPATH")) != NULL)
    err = mixdir(d, 1);

#ifdef WIN32
  RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &regsw);
  len=sizeof(line);
  if (err == -1 &&
      RegOpenKeyEx(regsw, "Mixmaster", 0, KEY_QUERY_VALUE, &reg) == 0) {
    if (RegQueryValueEx(reg, "MixDir", 0, &type, line, &len) == 0)
      err = mixdir(line, 1);
    RegCloseKey(reg);
  }
#endif /* WIN32 */

#ifdef SPOOL
  if (err == -1 && strlen(SPOOL) > 0)
    err = mixdir(SPOOL, 0);
#endif /* SPOOL */

#ifdef WIN32
    if (err == -1) {
      LPMALLOC lpmalloc;
      ITEMIDLIST *itemidlist;
      if (SUCCEEDED(SHGetMalloc(&lpmalloc)))
      {
	SHGetSpecialFolderLocation(0,CSIDL_APPDATA,&itemidlist);
	SHGetPathFromIDList(itemidlist,line);
	lpmalloc->lpVtbl->Free(lpmalloc,&itemidlist);
	lpmalloc->lpVtbl->Release(lpmalloc);

	strcatn(line, "\\Mixmaster", PATHMAX);
	err = mixdir(line, 1);

      }
    }
#endif /* WIN32 */

#ifdef POSIX
  if (err == -1 && pw != NULL) {
    strncpy(line, pw->pw_dir, PATHMAX);
    line[PATHMAX-1] = '\0';
    if (line[strlen(line) - 1] != DIRSEP)
      strcatn(line, DIRSEPSTR, PATHMAX);
    strcatn(line, HOMEMIXDIR, PATHMAX);
    err = mixdir(line, 1);
  }
#endif /* POSIX */

  if (err == -1) {
    getcwd(MIXDIR, PATHMAX);
    mixdir(MIXDIR, 0);
  }

#ifdef GLOBALMIXCONF
  f = mix_openfile(GLOBALMIXCONF, "r");
  if (f != NULL) {
    while (fgets(line, LINELEN, f) != NULL)
      if (line[0] > ' ' && line[0] != '#')
	mix_configline(line);
    fclose(f);
  }
#endif /* GLOBALMIXCONF */
  f = mix_openfile(MIXCONF, "r");
  if (f != NULL) {
    while (fgets(line, LINELEN, f) != NULL)
      if (line[0] > ' ' && line[0] != '#')
	mix_configline(line);
    fclose(f);
  }

  mixfile(POOLDIR, POOL); /* set POOLDIR after reading POOL from cfg file */
  if (POOLDIR[strlen(POOLDIR) - 1] == DIRSEP)
    POOLDIR[strlen(POOLDIR) - 1] = '\0';
  if (stat(POOLDIR, &buf) != 0)
    if
#ifndef POSIX
      (mkdir(POOLDIR) != 0)
#else /* end of not POSIX */
      (mkdir(POOLDIR, S_IRWXU) == -1)
#endif /* else if POSIX */
      strncpy(POOLDIR, MIXDIR, PATHMAX);

  if (IDEXP > 0 && IDEXP < 5 * SECONDSPERDAY)
    IDEXP = 5 * SECONDSPERDAY;
  if (MAXRANDHOPS > 20)
    MAXRANDHOPS = 20;
  if (INDUMMYP > INDUMMYMAXP)
    INDUMMYP = INDUMMYMAXP;
  if (OUTDUMMYP > OUTDUMMYMAXP)
    OUTDUMMYP = OUTDUMMYMAXP;

  if (strchr(SHORTNAME, '.'))
    *strchr(SHORTNAME, '.') = '\0';
  if (strchr(SHORTNAME, ' '))
    *strchr(SHORTNAME, ' ') = '\0';
#ifdef HAVE_UNAME
  if (SHORTNAME[0] == '\0' && uname(&uts) != -1)
    strncpy(SHORTNAME, uts.nodename, LINELEN);
#elif defined(HAVE_GETHOSTNAME) /* end of HAVE_UNAME */
  if (SHORTNAME[0] == '\0')
    gethostname(SHORTNAME, LINELEN);
#endif /* defined(HAVE_GETHOSTNAME) */
  if (SHORTNAME[0] == '\0')
    strcpy(SHORTNAME, "unknown");

  if (ADDRESS[0] == '\0')
    whoami(ADDRESS, "user");

#ifdef HAVE_GECOS
  if (NAME[0] == '\0' && pw != NULL)
    strcatn(NAME, pw->pw_gecos, sizeof(NAME));
#endif /* HAVE_GECOS */

  if (REMAILERADDR[0] == '\0')
    strncpy(REMAILERADDR, ADDRESS, LINELEN);

  if (COMPLAINTS[0] == '\0')
    strncpy(COMPLAINTS, REMAILERADDR, LINELEN);

  if (strchr(REMAILERNAME, '@') == NULL) {
    strcatn(REMAILERNAME, " <", LINELEN);
    strcatn(REMAILERNAME, REMAILERADDR, LINELEN);
    strcatn(REMAILERNAME, ">", LINELEN);
  }
  if (strchr(ANONNAME, '@') == NULL && ANONADDR[0] != '\0') {
    strcatn(ANONNAME, " <", LINELEN);
    strcatn(ANONNAME, ANONADDR, LINELEN);
    strcatn(ANONNAME, ">", LINELEN);
  }
  if (strchr(ANONNAME, '@') == NULL) {
    strcatn(ANONNAME, " <", LINELEN);
    strcatn(ANONNAME, REMAILERADDR, LINELEN);
    strcatn(ANONNAME, ">", LINELEN);
  }
#ifndef USE_PGP
  if (TYPE1[0] == '\0')
    PGP = 0;
#endif /* not USE_PGP */

#ifdef WIN32
  if (RegOpenKeyEx(regsw, "PGP", 0, KEY_ALL_ACCESS, &regpgp) == 0)
    rkey++;
  if (rkey && RegOpenKeyEx(regpgp, "PGPlib", 0, KEY_QUERY_VALUE, &reg) == 0)
    rkey++;
  if (PGPPUBRING[0] == '\0' && rkey == 2) {
    len = PATHMAX;
    RegQueryValueEx(reg, "PubRing", 0, &type, PGPPUBRING, &len);
  }
  if (PGPSECRING[0] == '\0' && rkey == 2) {
    len = PATHMAX;
    RegQueryValueEx(reg, "SecRing", 0, &type, PGPSECRING, &len);
  }
  if (rkey == 2)
    RegCloseKey(reg);
  if (rkey)
    RegCloseKey(regpgp);
  RegCloseKey(regsw);
#endif /* WIN32 */

  if (PGPPUBRING[0] == '\0') {
    char *d;

    if ((d = getenv("HOME")) != NULL) {
      strcpy(PGPPUBRING, d);
      strcatn(PGPPUBRING, "/.pgp/", PATHMAX);
    }
    strcatn(PGPPUBRING, "pubring.pkr", PATHMAX);
    if (stat(PGPPUBRING, &buf) == -1)
      strcpy(strrchr(PGPPUBRING, '.'), ".pgp");
  }
  if (PGPSECRING[0] == '\0') {
    char *d;

    if ((d = getenv("HOME")) != NULL) {
      strcpy(PGPSECRING, d);
      strcatn(PGPSECRING, "/.pgp/", PATHMAX);
    }
    strcatn(PGPSECRING, "secring.skr", PATHMAX);
    if (stat(PGPSECRING, &buf) == -1)
      strcpy(strrchr(PGPSECRING, '.'), ".pgp");
  }
  if (streq(NEWS, "mail-to-news"))
    strncpy(NEWS, MAILtoNEWS, sizeof(NEWS));

  if (f == NULL) {
#ifndef GLOBALMIXCONF
    /* Only write the config file in non systemwide installation */
    f = mix_openfile(MIXCONF, "w");
    if (f == NULL)
      errlog(WARNING, "Can't open %s%s!\n", MIXDIR, MIXCONF);
    else {
      fprintf(f, "# mix.cfg - mixmaster configuration file\n");
      fprintf(f, "NAME	        %s\n", NAME);
      fprintf(f, "ADDRESS	        %s\n", ADDRESS);
      fprintf(f, "\n# edit to set up a remailer:\n");
      fprintf(f, "REMAIL          n\n");
      fprintf(f, "SHORTNAME	%s\n", SHORTNAME);
      fprintf(f, "REMAILERADDR	%s\n", REMAILERADDR);
      fprintf(f, "COMPLAINTS	%s\n", COMPLAINTS);
      fclose(f);
    }
#endif /* not GLOBALMIXCONF */
    REMAIL = 0;
  }

  if (ENTEREDPASSPHRASE[0] != '\0') {
    strncpy(PASSPHRASE, ENTEREDPASSPHRASE, LINELEN);
    PASSPHRASE[LINELEN-1] = 0;
  };

  return (0);
}
Esempio n. 28
0
int t1_rlist(REMAILER remailer[], int badchains[MAXREM][MAXREM])
{
  FILE *list, *excl;
  int i, listed = 0;
  int n = 0;
  char line[2 * LINELEN], l2[LINELEN], name[LINELEN], *flags;
  BUFFER *starex;

  starex = buf_new();
  excl = mix_openfile(STAREX, "r");
  if (excl != NULL) {
    buf_read(starex, excl);
    fclose(excl);
  }

  list = mix_openfile(TYPE1LIST, "r");
  if (list == NULL) {
    buf_free(starex);
    return (-1);
  }

  while (fgets(line, sizeof(line), list) != NULL && n < MAXREM) {
    if (strleft(line, "$remailer") &&
	strchr(line, '<') && strchr(line, '>') &&
	strchr(line, '{') && strchr(line, '{') + 4 < strchr(line, '}')) {
      if (line[strlen(line) - 1] == '\n')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] == '\r')
	line[strlen(line) - 1] = '\0';
      while (line[strlen(line) - 1] == ' ')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] != ';'
	  && fgets(l2, sizeof(l2), list) != NULL)
	strcatn(line, l2, LINELEN);
      flags = strchr(line, '>');
      strncpy(name, strchr(line, '{') + 2,
	      strchr(line, '}') - strchr(line, '{') - 3);
      name[strchr(line, '}') - strchr(line, '{') - 3] = '\0';
      name[20] = '\0';

      for (i = 1; i <= n; i++)
	if (streq(name, remailer[i].name))
	  break;
      if (i > n) {
	/* not in mix list */
	n++;
	strcpy(remailer[i].name, name);
	strncpy(remailer[i].addr, strchr(line, '<') + 1,
		strchr(line, '>') - strchr(line, '<'));
	remailer[i].addr[strchr(line, '>') - strchr(line, '<') - 1]
	  = '\0';
	remailer[i].flags.mix = 0;
	remailer[i].flags.post = strifind(flags, " post");
      }
      remailer[i].flags.cpunk = strfind(flags, " cpunk");
      remailer[i].flags.pgp = strfind(flags, " pgp");
      remailer[i].flags.pgponly = strfind(flags, " pgponly");
      remailer[i].flags.latent = strfind(flags, " latent");
      remailer[i].flags.middle = strfind(flags, " middle");
      remailer[i].flags.ek = strfind(flags, " ek");
      remailer[i].flags.esub = strfind(flags, " esub");
      remailer[i].flags.hsub = strfind(flags, " hsub");
      remailer[i].flags.newnym = strfind(flags, " newnym");
      remailer[i].flags.nym = strfind(flags, " nym");
      remailer[i].info[1].reliability = 0;
      remailer[i].info[1].latency = 0;
      remailer[i].info[1].history[0] = '\0';
      remailer[i].flags.star_ex = bufifind(starex, name);
   }
    if (strleft(line,
		"-----------------------------------------------------------------------"))
      break;
  }
  n++;				/* ?? */
  while (fgets(line, sizeof(line), list) != NULL) {
    if (strlen(line) >= 72 && strlen(line) <= 73)
      for (i = 1; i < n; i++)
	if (strleft(line, remailer[i].name) &&
	    line[strlen(remailer[i].name)] == ' ') {
	  strncpy(remailer[i].info[1].history, line + 42, 12);
	  remailer[i].info[1].history[12] = '\0';
	  remailer[i].info[1].reliability = 10000 * N(line[64])
	    + 1000 * N(line[65]) + 100 * N(line[66])
	    + 10 * N(line[68]) + N(line[69]);
	  remailer[i].info[1].latency = 36000 * N(line[55])
	    + 3600 * N(line[56]) + 600 * N(line[58])
	    + 60 * N(line[59]) + 10 * N(line[61])
	    + N(line[62]);
	  listed++;
	}
  }
  fclose(list);
  parse_badchains(badchains, TYPE1LIST, "Broken type-I remailer chains", remailer, n);
  if (listed < 4)		/* we have no valid reliability info */
    for (i = 1; i < n; i++)
      remailer[i].info[1].reliability = 10000;

#ifdef USE_PGP
  pgp_rlist(remailer, n);
#endif /* USE_PGP */
  buf_free(starex);
  return (n);
}