Exemplo n.º 1
0
Arquivo: db_rw.c Projeto: chazu/btmux
static int get_list(FILE * f, dbref i, int new_strings)
{
	dbref atr;
	int c;
	char *buff;

	buff = alloc_lbuf("get_list");
	while (1) {
		switch (c = getc(f)) {
		case '>':				/*
								 * read # then string 
								 */
			atr = getref(f);
			if(atr > 0) {
				/*
				 * Store the attr 
				 */

				atr_add_raw(i, atr, (char *) getstring_noalloc(f,
															   new_strings));
			} else {
				/*
				 * Silently discard 
				 */

				getstring_noalloc(f, new_strings);
			}
			break;
		case '\n':				/*
								 * ignore newlines. They're due to v(r). 
								 */
			break;
		case '<':				/*
								 * end of list 
								 */
			free_lbuf(buff);
			c = getc(f);
			if(c != '\n') {
				ungetc(c, f);
				fprintf(stderr, "No line feed on object %d\n", i);
				return 1;
			}
			return 1;
		default:
			fprintf(stderr,
					"Bad character '%c' when getting attributes on object %d\n",
					c, i);
			/*
			 * We've found a bad spot.  I hope things aren't * *
			 * * * * * too bad. 
			 */

			(void) getstring_noalloc(f, new_strings);
		}
	}
}
Exemplo n.º 2
0
static ATTR *
attr_alias_read(PENNFILE *f, char *alias)
{
  char *tmp;
  ATTR *a;

  db_read_this_labeled_string(f, "name", &tmp);
  a = aname_find_exact(tmp);
  if (!a) {
    /* Oops */
    do_rawlog(LT_ERR, "Alias of non-existant attribute '%s' in db.", tmp);
    (void) getstring_noalloc(f);
    return NULL;
  }
  db_read_this_labeled_string(f, "alias", &tmp);
  strcpy(alias, tmp);

  return a;
}
Exemplo n.º 3
0
Arquivo: db_rw.c Projeto: chazu/btmux
dbref db_read(FILE * f, int *db_format, int *db_version, int *db_flags)
{
	dbref i, anum;
	char ch;
	const char *tstr;
	int header_gotten, size_gotten, nextattr_gotten;
	int read_attribs, read_name, read_zone, read_link, read_key, read_parent;
	int read_extflags, read_3flags, read_money, read_timestamps,
		read_new_strings;
	int read_powers, read_powers_player, read_powers_any;
	int deduce_version, deduce_name, deduce_zone, deduce_timestamps;
	int aflags, f1, f2, f3;
	BOOLEXP *tempbool;

	header_gotten = 0;
	size_gotten = 0;
	nextattr_gotten = 0;
	g_format = F_UNKNOWN;
	g_version = 0;
	g_flags = 0;
	read_attribs = 1;
	read_name = 1;
	read_zone = 0;
	read_link = 0;
	read_key = 1;
	read_parent = 0;
	read_money = 1;
	read_extflags = 0;
	read_3flags = 0;
	read_timestamps = 0;
	read_new_strings = 0;
	read_powers = 0;
	read_powers_player = 0;
	read_powers_any = 0;
	deduce_version = 1;
	deduce_zone = 1;
	deduce_name = 1;
	deduce_timestamps = 1;
	db_free();
	for(i = 0;; i++) {

		switch (ch = getc(f)) {
		case '-':				/* Misc tag */
			switch (ch = getc(f)) {
			case 'R':			/* Record number of players */
				mudstate.record_players = getref(f);
				break;
			default:
				(void) getstring_noalloc(f, 0);
			}
			break;
		case '+':				/*
								 * MUX and MUSH header 
								 */
			switch (ch = getc(f)) {	/*
									 * 2nd char selects 
									 * type 
									 */
			case 'X':			/*
								 * MUX VERSION 
								 */
				if(header_gotten) {
					fprintf(stderr,
							"\nDuplicate MUX version header entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
					break;
				}
				header_gotten = 1;
				deduce_version = 0;
				g_format = F_MUX;
				g_version = getref(f);

				/*
				 * Otherwise extract feature flags 
				 */

				if(g_version & V_GDBM) {
					read_attribs = 0;
					read_name = !(g_version & V_ATRNAME);
				}
				read_zone = (g_version & V_ZONE);
				read_link = (g_version & V_LINK);
				read_key = !(g_version & V_ATRKEY);
				read_parent = (g_version & V_PARENT);
				read_money = !(g_version & V_ATRMONEY);
				read_extflags = (g_version & V_XFLAGS);
				read_3flags = (g_version & V_3FLAGS);
				read_powers = (g_version & V_POWERS);
				read_new_strings = (g_version & V_QUOTED);
				g_flags = g_version & ~V_MASK;

				g_version &= V_MASK;
				deduce_name = 0;
				deduce_version = 0;
				deduce_zone = 0;
				break;
			case 'S':			/*
								 * SIZE 
								 */
				if(size_gotten) {
					fprintf(stderr,
							"\nDuplicate size entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
				} else {
					mudstate.min_size = getref(f);
				}
				size_gotten = 1;
				break;
			case 'A':			/*
								 * USER-NAMED ATTRIBUTE 
								 */
				anum = getref(f);
				tstr = getstring_noalloc(f, read_new_strings);
				if(isdigit(*tstr)) {
					aflags = 0;
					while (isdigit(*tstr))
						aflags = (aflags * 10) + (*tstr++ - '0');
					tstr++;		/*
								 * skip ':' 
								 */
				} else {
					aflags = mudconf.vattr_flags;
				}
				vattr_define((char *) tstr, anum, aflags);
				break;
			case 'F':			/*
								 * OPEN USER ATTRIBUTE SLOT 
								 */
				anum = getref(f);
				break;
			case 'N':			/*
								 * NEXT ATTR TO ALLOC WHEN NO
								 * FREELIST 
								 */
				if(nextattr_gotten) {
					fprintf(stderr,
							"\nDuplicate next free vattr entry at object %d, ignored.\n",
							i);
					tstr = getstring_noalloc(f, 0);
				} else {
					mudstate.attr_next = getref(f);
					nextattr_gotten = 1;
				}
				break;
			default:
				fprintf(stderr,
						"\nUnexpected character '%c' in MUX header near object #%d, ignored.\n",
						ch, i);
				tstr = getstring_noalloc(f, 0);
			}
			break;
		case '!':				/*
								 * MUX entry/MUSH entry/MUSE non-zoned entry 
								 */
			if(deduce_version) {
				g_format = F_MUX;
				g_version = 1;
				deduce_name = 0;
				deduce_zone = 0;
				deduce_version = 0;
			} else if(deduce_zone) {
				deduce_zone = 0;
				read_zone = 0;
			}
			i = getref(f);
			db_grow(i + 1);

			if(read_name) {
				tstr = getstring_noalloc(f, read_new_strings);
				if(deduce_name) {
					if(isdigit(*tstr)) {
						read_name = 0;
						s_Location(i, atoi(tstr));
					} else {
						s_Name(i, (char *) tstr);
						s_Location(i, getref(f));
					}
					deduce_name = 0;
				} else {
					s_Name(i, (char *) tstr);
					s_Location(i, getref(f));
				}
			} else {
				s_Location(i, getref(f));
			}

			/*
			 * ZONE on MUSE databases and some others 
			 */

			if(read_zone)
				s_Zone(i, getref(f));

			/*
			 * else
			 * * s_Zone(i, NOTHING); 
			 */

			/*
			 * CONTENTS and EXITS 
			 */

			s_Contents(i, getref(f));
			s_Exits(i, getref(f));

			/*
			 * LINK 
			 */

			if(read_link)
				s_Link(i, getref(f));
			else
				s_Link(i, NOTHING);

			/*
			 * NEXT 
			 */

			s_Next(i, getref(f));

			/*
			 * LOCK
			 */

			if(read_key) {
				tempbool = getboolexp(f);
				atr_add_raw(i, A_LOCK, unparse_boolexp_quiet(1, tempbool));
				free_boolexp(tempbool);
			}
			/*
			 * OWNER 
			 */

			s_Owner(i, getref(f));

			/*
			 * PARENT: PennMUSH uses this field for ZONE
			 * (which we  use as PARENT if we
			 * didn't already read in a  
			 * non-NOTHING parent. 
			 */

			if(read_parent) {
				s_Parent(i, getref(f));
			} else {
				s_Parent(i, NOTHING);
			}

			/*
			 * PENNIES 
			 */

			if(read_money)		/*
								 *  if not fix in
								 * unscraw_foreign  
								 */
				s_Pennies(i, getref(f));

			/*
			 * FLAGS 
			 */

			f1 = getref(f);
			if(read_extflags)
				f2 = getref(f);
			else
				f2 = 0;

			if(read_3flags)
				f3 = getref(f);
			else
				f3 = 0;

			s_Flags(i, f1);
			s_Flags2(i, f2);
			s_Flags3(i, f3);

			if(read_powers) {
				f1 = getref(f);
				f2 = getref(f);
				s_Powers(i, f1);
				s_Powers2(i, f2);
			}

			/*
			 * ATTRIBUTES 
			 */

			if(read_attribs) {
				if(!get_list(f, i, read_new_strings)) {
					fprintf(stderr,
							"\nError reading attrs for object #%d\n", i);
					return -1;
				}
			}
			/*
			 * check to see if it's a player 
			 */

			if(Typeof(i) == TYPE_PLAYER) {
				c_Connected(i);
			}
			break;
		case '*':				/*
								 * EOF marker 
								 */
			tstr = getstring_noalloc(f, 0);
			if(strcmp(tstr, "**END OF DUMP***")) {
				fprintf(stderr, "\nBad EOF marker at object #%d\n", i);
				return -1;
			} else {
				/*
				 * Fix up bizarro foreign DBs 
				 */

				*db_version = g_version;
				*db_format = g_format;
				*db_flags = g_flags;
				load_player_names();
				return mudstate.db_top;
			}
		default:
			fprintf(stderr, "\nIllegal character '%c' near object #%d\n",
					ch, i);
			return -1;
		}

	}

}
Exemplo n.º 4
0
Arquivo: db_rw.c Projeto: chazu/btmux
static BOOLEXP *getboolexp1(FILE * f)
{
	BOOLEXP *b;
	char *buff, *s;
	int c, d, anum;

	c = getc(f);
	switch (c) {
	case '\n':
		ungetc(c, f);
		return TRUE_BOOLEXP;
		/*
		 * break; 
		 */
	case EOF:
		abort();				/*
								 * unexpected EOF in boolexp 
								 */
		break;
	case '(':
		b = alloc_bool("getboolexp1.openparen");
		switch (c = getc(f)) {
		case NOT_TOKEN:
			b->type = BOOLEXP_NOT;
			b->sub1 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		case INDIR_TOKEN:
			b->type = BOOLEXP_INDIR;
			b->sub1 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		case IS_TOKEN:
			b->type = BOOLEXP_IS;
			b->sub1 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		case CARRY_TOKEN:
			b->type = BOOLEXP_CARRY;
			b->sub1 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		case OWNER_TOKEN:
			b->type = BOOLEXP_OWNER;
			b->sub1 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		default:
			ungetc(c, f);
			b->sub1 = getboolexp1(f);
			if((c = getc(f)) == '\n')
				c = getc(f);
			switch (c) {
			case AND_TOKEN:
				b->type = BOOLEXP_AND;
				break;
			case OR_TOKEN:
				b->type = BOOLEXP_OR;
				break;
			default:
				goto error;
			}
			b->sub2 = getboolexp1(f);
			if((d = getc(f)) == '\n')
				d = getc(f);
			if(d != ')')
				goto error;
			return b;
		}
	case '-':					/*
								 * obsolete NOTHING key, eat it 
								 */
		while ((c = getc(f)) != '\n')
			if(c == EOF)
				abort();		/*
								 * unexp EOF 
								 */
		ungetc(c, f);
		return TRUE_BOOLEXP;
		break;
	case '"':
		ungetc(c, f);
		buff = alloc_lbuf("getboolexp_quoted");
		StringCopy(buff, getstring_noalloc(f, 1));
		c = fgetc(f);
		if(c == EOF) {
			free_lbuf(buff);
			return TRUE_BOOLEXP;
		}

		b = alloc_bool("getboolexp1_quoted");
		anum = mkattr(buff);
		if(anum <= 0) {
			free_bool(b);
			free_lbuf(buff);
			goto error;
		}
		free_lbuf(buff);
		b->thing = anum;

		/*
		 * if last character is : then this is an attribute lock. A 
		 * last character of / means an eval lock 
		 */

		if((c == ':') || (c == '/')) {
			if(c == '/')
				b->type = BOOLEXP_EVAL;
			else
				b->type = BOOLEXP_ATR;
			buff = alloc_lbuf("getboolexp1.attr_lock");
			StringCopy(buff, getstring_noalloc(f, 1));
			b->sub1 = (BOOLEXP *) strsave(buff);
			free_lbuf(buff);
		}
		return b;
	default:					/*
								 * dbref or attribute 
								 */
		ungetc(c, f);
		b = alloc_bool("getboolexp1.default");
		b->type = BOOLEXP_CONST;
		b->thing = 0;

		/*
		 * This is either an attribute, eval, or constant lock.
		 * Constant locks are of the form <num>, while
		 * attribute * and * * * * eval locks are of the form
		 * <anam-or-anum>:<string> or
		 * <aname-or-anum>/<string> respectively. The
		 * characters <nl>, |, and & terminate the string. 
		 */

		if(isdigit(c)) {
			while (isdigit(c = getc(f))) {
				b->thing = b->thing * 10 + c - '0';
			}
		} else if(isalpha(c)) {
			buff = alloc_lbuf("getboolexp1.atr_name");
			for(s = buff;
				((c = getc(f)) != EOF) && (c != '\n') && (c != ':') &&
				(c != '/'); *s++ = c);
			if(c == EOF) {
				free_lbuf(buff);
				free_bool(b);
				goto error;
			}
			*s = '\0';

			/*
			 * Look the name up as an attribute.  If not found,
			 * create a new attribute. 
			 */

			anum = mkattr(buff);
			if(anum <= 0) {
				free_bool(b);
				free_lbuf(buff);
				goto error;
			}
			free_lbuf(buff);
			b->thing = anum;
		} else {
			free_bool(b);
			goto error;
		}

		/*
		 * if last character is : then this is an attribute lock. A 
		 * last character of / means an eval lock 
		 */

		if((c == ':') || (c == '/')) {
			if(c == '/')
				b->type = BOOLEXP_EVAL;
			else
				b->type = BOOLEXP_ATR;
			buff = alloc_lbuf("getboolexp1.attr_lock");
			for(s = buff;
				((c = getc(f)) != EOF) && (c != '\n') && (c != ')') &&
				(c != OR_TOKEN) && (c != AND_TOKEN); *s++ = c);
			if(c == EOF)
				goto error;
			*s++ = 0;
			b->sub1 = (BOOLEXP *) strsave(buff);
			free_lbuf(buff);
		}
		ungetc(c, f);
		return b;
	}

  error:
	abort();					/*
								 * bomb out 
								 */
	return TRUE_BOOLEXP;
}
Exemplo n.º 5
0
static ATTR *
attr_read(PENNFILE *f)
{
  ATTR *a;
  char *tmp;
  dbref d = GOD;
  privbits flags = 0;

  a = (ATTR *) mush_malloc(sizeof(ATTR), "ATTR");
  if (!a) {
    mush_panic("Not enough memory to add attribute in attr_read()!");
    return NULL;
  }
  AL_NAME(a) = NULL;
  a->data = NULL_CHUNK_REFERENCE;
  AL_FLAGS(a) = 0;
  AL_CREATOR(a) = GOD;
  a->next = NULL;

  db_read_this_labeled_string(f, "name", &tmp);

  if (!good_atr_name(tmp)) {
    do_rawlog(LT_ERR, "Invalid attribute name '%s' in db.", tmp);
    (void) getstring_noalloc(f);        /* flags */
    (void) getstring_noalloc(f);        /* creator */
    (void) getstring_noalloc(f);        /* data */
    free_standard_attr(a, 0);
    return NULL;
  }

  AL_NAME(a) = strdup(tmp);
  db_read_this_labeled_string(f, "flags", &tmp);
  if (tmp && *tmp && strcasecmp(tmp, "none")) {
    flags = list_to_privs(attr_privs_db, tmp, 0);
    if (!flags) {
      do_rawlog(LT_ERR, "Invalid attribute flags for '%s' in db.", AL_NAME(a));
      free((char *) AL_NAME(a));
      (void) getstring_noalloc(f);      /* creator */
      (void) getstring_noalloc(f);      /* data */
      free_standard_attr(a, 0);
      return NULL;
    }
  }
  AL_FLAGS(a) = flags;

  db_read_this_labeled_dbref(f, "creator", &d);
  AL_CREATOR(a) = d;

  db_read_this_labeled_string(f, "data", &tmp);
  if (!tmp || !*tmp || !(AL_FLAGS(a) & (AF_ENUM | AF_RLIMIT))) {
    a->data = NULL_CHUNK_REFERENCE;
  } else if (AL_FLAGS(a) & AF_ENUM) {
    /* Store string as it is */
    char *t = compress(tmp);
    a->data = chunk_create(t, strlen(t), 0);
    free(t);
  } else if (AL_FLAGS(a) & AF_RLIMIT) {
    /* Need to validate regexp */
    char *t;
    pcre *re;
    const char *errptr;
    int erroffset;

    re = pcre_compile(tmp, PCRE_CASELESS, &errptr, &erroffset, tables);
    if (!re) {
      do_rawlog(LT_ERR, "Invalid regexp in limit for attribute '%s' in db.",
                AL_NAME(a));
      free_standard_attr(a, 0);
      return NULL;
    }
    pcre_free(re);              /* don't need it, just needed to check it */

    t = compress(tmp);
    a->data = chunk_create(t, strlen(t), 0);
    free(t);
  }

  return a;
}