void skipproperties(FILE * f, dbref obj) { char buf[BUFFER_LEN * 3]; int islisten = 0; /* get rid of first line */ fgets(buf, sizeof(buf), f); fgets(buf, sizeof(buf), f); while (strcmp(buf, "*End*\n")) { if (!islisten) { if (string_prefix(buf, "_listen")) islisten = 1; if (string_prefix(buf, "~listen")) islisten = 1; if (string_prefix(buf, "~olisten")) islisten = 1; } fgets(buf, sizeof(buf), f); } if (islisten) { FLAGS(obj) |= LISTENER; } else { FLAGS(obj) &= ~LISTENER; } }
const char * mfn_lunion(MFUNARGS) { int iter_limit = MAX_MFUN_LIST_LEN; char *ptr, *ptr2, *p; int len; int outlen, nextlen; *buf = '\0'; outlen = 0; ptr = argv[0]; while (*ptr) { for (ptr2 = ptr; *ptr2 && *ptr2 != '\r'; ptr2++); if (*ptr2) *(ptr2++) = '\0'; len = strlen(ptr); p = buf; do { if (string_prefix(p, ptr) && (!p[len] || p[len] == '\r')) break; while (*p && *p != '\r') p++; if (*p) p++; } while (*p); if (!*p) { nextlen = strlen(ptr); if (outlen + nextlen > BUFFER_LEN - 3) break; if (outlen) strcat((buf+(outlen++)), "\r"); strcat((buf+outlen), ptr); outlen += nextlen; } ptr = ptr2; if (!(--iter_limit)) ABORT_MPI("LUNION","Iteration limit exceeded"); } ptr = argv[1]; while (*ptr) { for (ptr2 = ptr; *ptr2 && *ptr2 != '\r'; ptr2++); if (*ptr2) *(ptr2++) = '\0'; len = strlen(ptr); p = buf; do { if (string_prefix(p, ptr) && (!p[len] || p[len] == '\r')) break; while (*p && *p != '\r') p++; if (*p) p++; } while (*p); if (!*p) { nextlen = strlen(ptr); if (outlen + nextlen > BUFFER_LEN - 3) break; if (outlen) strcat((buf+(outlen++)), "\r"); strcat((buf+outlen), ptr); outlen += nextlen; } ptr = ptr2; if (!(--iter_limit)) ABORT_MPI("LUNION","Iteration limit exceeded"); } return buf; }
static help_indx * help_find_entry(help_file *help_dat, const char *the_topic) { help_indx *entry = NULL; if (help_dat->entries < 10) { /* Just do a linear search for small files */ size_t n; for (n = 0; n < help_dat->entries; n++) { if (string_prefix(help_dat->indx[n].topic, the_topic)) { entry = &help_dat->indx[n]; break; } } } else { /* Binary search of the index */ int left = 0; int cmp; int right = help_dat->entries - 1; while (1) { int n = (left + right) / 2; if (left > right) break; cmp = strcasecmp(the_topic, help_dat->indx[n].topic); if (cmp == 0) { entry = &help_dat->indx[n]; break; } else if (cmp < 0) { /* We need to catch the first prefix */ if (string_prefix(help_dat->indx[n].topic, the_topic)) { int m; for (m = n - 1; m >= 0; m--) { if (!string_prefix(help_dat->indx[m].topic, the_topic)) break; } entry = &help_dat->indx[m + 1]; break; } if (left == right) break; right = n - 1; } else { /* cmp > 0 */ if (left == right) break; left = n + 1; } } } return entry; }
int image_type_from_data(char *data, int size) { if ( size > 2 ) { unsigned short beshort = data[0]<<8|data[1]; switch(beshort) { case 0xffd8: return IMG_IS_JPEG; default: break; } } if ( string_prefix(data, size, 0, "#define ") ) return IMG_IS_XBM; /* X11 bitmap (.BM) file */ if ( string_prefix(data, size, 0, "/* Format_version=1, Width=") ) return IMG_IS_SUNICON; /* Old SUN Icon files */ if ( string_prefix(data, size, 0, "/* XPM */") ) return IMG_IS_XPM; /* XPM Image file */ if ( string_prefix(data, size, 0, "GIG8") ) return IMG_IS_GIF; /* GIF Image files */ if ( data[0] == 'P' && data[1] >= '1' && data[1] <= '7' ) return IMG_IS_PNM; /* BPMPLUS images */ if ( string_prefix(data, size, 0, "\x89PNG\x0d\x0a\x1a\x0a") ) return IMG_IS_PNG; /* PNG's (Not GIF) images */ if ( string_prefix(data, size, 0, "BM") ) return IMG_IS_BMP; /* Windows BMP files */ if ( string_prefix(data, size, 0, "IC") ) return IMG_IS_ICO; /* Windows ICO files */ if ( string_prefix(data, size, 0, "CI") ) return IMG_IS_ICO; /* Windows ICO (color) files */ return IMG_IS_UNKNOWN; /* Don't know */ }
int safeputprop(dbref obj, dbref perms, char *buf, char *val, int mesgtyp) { char *ptr; if (!buf) return 0; while (*buf == PROPDIR_DELIMITER) buf++; if (!*buf) return 0; /* disallow CR's and :'s in prop names. */ for (ptr = buf; *ptr; ptr++) if (*ptr == '\r' || *ptr == PROP_DELIMITER) return 0; if (Prop_System(buf)) return 0; if (!(mesgtyp & MPI_ISBLESSED)) { if (Prop_Hidden(buf)) return 0; if (Prop_SeeOnly(buf)) return 0; if (string_prefix(buf, "_msgmacs/")) return 0; } if (val == NULL) { remove_property(obj, buf, 0); } else { add_property(obj, buf, val, 0); } return 1; }
int prop_write_perms(dbref player, dbref obj, const char *name, int mlev) { if (Prop_System(name)) return 0; if (mlev < 3) { if (!permissions(player, obj)) { if (Prop_Private(name)) return 0; if (Prop_ReadOnly(name)) return 0; if (!string_compare(name, "sex")) return 0; } if (string_prefix(name, "_msgmacs/")) return 0; } if (mlev < 4) { if (Prop_SeeOnly(name)) return 0; if (Prop_Hidden(name)) return 0; } return 1; }
/** Return a list of all available locks * \param buff the buffer * \param bp a pointer to the current position in the buffer. * \param name if not NULL, only show locks with this prefix */ void list_locks(char *buff, char **bp, const char *name) { lock_list **locks, *lk; bool first = 1; int nlocks = 0, n; locks = mush_calloc(htab_locks.entries, sizeof(lock_list), "lock.list"); for (lk = hash_firstentry(&htab_locks); lk; lk = hash_nextentry(&htab_locks)) { /* Skip those that don't match */ if (name && !string_prefix(lk->type, name)) continue; locks[nlocks++] = lk; } qsort(locks, nlocks, sizeof lk, lock_compare); for (n = 0; n < nlocks; n += 1) { if (first) { first = 0; } else { safe_chr(' ', buff, bp); } safe_str(strupper(locks[n]->type), buff, bp); } mush_free(locks, "lock.list"); }
const char * mfn_instr(MFUNARGS) { char *ptr; if (!*argv[1]) ABORT_MPI("INSTR","Can't search for a null string"); for (ptr = argv[0]; *ptr && !string_prefix(ptr, argv[1]); ptr++); if (!*ptr) return "0"; sprintf(buf, "%d", (int)(ptr - argv[0] + 1)); return buf; }
const char * mfn_lmember(MFUNARGS) { /* {lmember:list,item,delim} */ int i = 1; char *ptr = argv[0]; int len; int len2 = strlen(argv[1]); if (argc < 3) strcpy(argv[2], "\r"); if (!*argv[2]) ABORT_MPI("LMEMBER","List delimiter cannot be a null string"); len = strlen(argv[2]); while (*ptr && !(string_prefix(ptr, argv[1]) && (!ptr[len2] || string_prefix(ptr+len2, argv[2])))) { while (*ptr && !string_prefix(ptr, argv[2])) ptr++; if (*ptr) ptr += len; i++; } if (!*ptr) return "0"; sprintf(buf, "%d", i); return buf; }
const char * mfn_lcommon(MFUNARGS) { int iter_limit = MAX_MFUN_LIST_LEN; char *ptr, *ptr2, *p, *q; int len; ptr = argv[1]; *buf = '\0'; while (*ptr) { for (ptr2 = ptr; *ptr2 && *ptr2 != '\r'; ptr2++); if (*ptr2) *(ptr2++) = '\0'; len = strlen(ptr); p = argv[0]; do { if (string_prefix(p, ptr) && (!p[len] || p[len] == '\r')) break; while (*p && *p != '\r') p++; if (*p) p++; } while (*p); q = buf; do { if (string_prefix(q, ptr) && (!q[len] || q[len] == '\r')) break; while (*q && *q != '\r') q++; if (*q) q++; } while (*q); if (*p && !*q) { if (*buf) strcat(buf, "\r"); strcat(buf, ptr); } ptr = ptr2; if (!(--iter_limit)) ABORT_MPI("LCOMMON","Iteration limit exceeded"); } return buf; }
const char *string_match(const char *src, const char *sub) { if ((*sub != '\0') && (src)) { while (*src) { if (string_prefix(src, sub)) return src; /* else scan to beginning of next word */ while (*src && isalnum((int)*src)) src++; while (*src && !isalnum((int)*src)) src++; } } return 0; }
const char * mfn_otell(MFUNARGS) { char buf2[BUFFER_LEN]; char *ptr, *ptr2; dbref obj = getloc(player); dbref eobj = player; dbref thing; if (argc > 1) obj = mesg_dbref_local(descr, player, what, perms, argv[1], mesgtyp); if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME) ABORT_MPI("OTELL", "Match failed."); if (obj == PERMDENIED) ABORT_MPI("OTELL", "Permission denied."); if ((mesgtyp & MPI_ISLISTENER) && (Typeof(what) != TYPE_ROOM)) ABORT_MPI("OTELL", "Permission denied."); if (argc > 2) eobj = mesg_dbref_raw(descr, player, what, perms, argv[2]); strcpyn(buf2, sizeof(buf2), argv[0]); for (ptr = buf2; *ptr; ptr = ptr2) { ptr2 = index(ptr, '\r'); if (ptr2) { *ptr2 = '\0'; } else { ptr2 = ptr + strlen(ptr); } if (((OWNER(what) == OWNER(obj) || isancestor(what, obj)) && (Typeof(what) == TYPE_ROOM || (Typeof(what) == TYPE_EXIT && Typeof(getloc(what)) == TYPE_ROOM))) || string_prefix(argv[0], NAME(player))) { strcpyn(buf, buflen, ptr); } else { snprintf(buf, BUFFER_LEN, "%.16s%s%.4078s", NAME(player), ((*argv[0] == '\'' || isspace(*argv[0])) ? "" : " "), ptr); } thing = DBFETCH(obj)->contents; while (thing != NOTHING) { if (thing != eobj) { notify_from_echo(player, thing, buf, 0); } thing = DBFETCH(thing)->next; } } return argv[0]; }
/** Check to see that the lock type is a valid type. * If it's not in our lock table, it's not valid, * unless it begins with 'user:'******'t allow '|' in lock names because it * will confuse our db-reading routines. * * Might destructively modify name. * * \param player the enactor, for notification. * \param thing object on which to check the lock. * \param name name of lock type. * \return lock type, or NULL. */ static lock_type check_lock_type(dbref player, dbref thing, lock_type name) { lock_type ll; char *sp; /* Special-case for basic locks. */ if (!name || !*name) return Basic_Lock; /* Normal locks. */ ll = match_lock(name); if (ll != NULL) return ll; /* If the lock is set, it's allowed, whether it exists normally or not. */ if (getlock(thing, name) != TRUE_BOOLEXP) return name; /* Check to see if it's a well-formed user-defined lock. */ sp = strchr(name, ':'); if (!sp) { notify(player, T("Unknown lock type.")); return NULL; } *sp++ = '\0'; if (!string_prefix("User", name)) { notify(player, T("Unknown lock type.")); return NULL; } if (strchr(sp, '|')) { notify(player, T("The character \'|\' may not be used in lock names.")); return NULL; } if (!good_atr_name(sp)) { notify(player, T("That is not a valid lock name.")); return NULL; } return sp; }
/** Check to see that the lock type is a valid type. * If it's not in our lock table, it's not valid, * unless it begins with 'user:'******'t allow '|' in lock names because it * will confuse our db-reading routines. * * * \param player the enactor, for notification. * \param thing object on which to check the lock. * \param name name of lock type. * \return lock type, or NULL. */ static lock_type check_lock_type(dbref player, dbref thing, lock_type name) { lock_type ll; char user_name[BUFFER_LEN]; char *colon; /* Special-case for basic locks. */ if (!name || !*name) return Basic_Lock; /* Normal locks. */ ll = match_lock(name); if (ll != NULL) return ll; /* If the lock is set, it's allowed, whether it exists normally or not. */ if (getlock(thing, name) != TRUE_BOOLEXP) return name; /* Check to see if it's a well-formed user-defined lock. */ if (!string_prefix(name, "User:"******"Unknown lock type.")); return NULL; } if (strchr(name, '|')) { notify(player, T("The character \'|\' may not be used in lock names.")); return NULL; } colon = strchr(name, ':') + 1; mush_strncpy(user_name, colon, BUFFER_LEN); if (!good_atr_name(user_name)) { notify(player, T("That is not a valid lock name.")); return NULL; } return colon; }
const char * mfn_tell(MFUNARGS) { char buf2[BUFFER_LEN]; char *ptr, *ptr2; dbref obj = player; if (argc > 1) obj = mesg_dbref_local(descr, player, what, perms, argv[1], mesgtyp); if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME) ABORT_MPI("TELL", "Match failed."); if (obj == PERMDENIED) ABORT_MPI("TELL", "Permission denied."); if ((mesgtyp & MPI_ISLISTENER) && (Typeof(what) != TYPE_ROOM)) ABORT_MPI("TELL", "Permission denied."); *buf = '\0'; strcpyn(buf2, sizeof(buf2), argv[0]); for (ptr = buf2; (ptr != NULL) && *ptr != '\0'; ptr = ptr2) { ptr2 = index(ptr, '\r'); if (ptr2 != NULL) { *ptr2++ = '\0'; } else { ptr2 = ptr + strlen(ptr); } if (Typeof(what) == TYPE_ROOM || OWNER(what) == obj || player == obj || (Typeof(what) == TYPE_EXIT && Typeof(getloc(what)) == TYPE_ROOM) || string_prefix(argv[0], NAME(player))) { snprintf(buf, BUFFER_LEN, "%s%.4093s", ((obj == OWNER(perms) || obj == player) ? "" : "> "), ptr); } else { snprintf(buf, BUFFER_LEN, "%s%.16s%s%.4078s", ((obj == OWNER(perms) || obj == player) ? "" : "> "), NAME(player), ((*argv[0] == '\'' || isspace(*argv[0])) ? "" : " "), ptr); } notify_from_echo(player, obj, buf, 1); } return argv[0]; }
/** Return a list of all available locks * \param buff the buffer * \param bp a pointer to the current position in the buffer */ void list_locks(char *buff, char **bp, const char *name) { char rbuff[BUFFER_LEN]; char *rp; int first = 1; const lock_list *ptr; rp = rbuff; for (ptr = lock_types; ptr->type != NULL; ptr++) { /* Skip those that don't match */ if (name && !string_prefix(ptr->type, name)) continue; if (first) { first = 0; } else { safe_chr(' ', rbuff, &rp); } safe_str(ptr->type, rbuff, &rp); } *rp = '\0'; /* We strupper it for consistency with the other * @list/foo and list(foo)s. */ safe_str(strupper(rbuff), buff, bp); }
void process_command(int descr, dbref player, char *command) { char *arg1; char *arg2; char *full_command, *commandline=command, *commandstuff; char *p; /* utility */ char pbuf[BUFFER_LEN]; char xbuf[BUFFER_LEN]; char ybuf[BUFFER_LEN]; const char *path; struct frame *tmpfr; if (command == 0) abort(); /* robustify player */ if (player < 0 || player >= db_top || (Typeof(player) != TYPE_PLAYER && Typeof(player) != TYPE_THING)) { log_status("process_command: bad player %d\n", player); return; } if ((tp_log_commands || (tp_log_guests && Guest(OWNER(player)))) && (!(FLAGS(player)&(INTERACTIVE | READMODE)))) { log_command("%s%s%s%s(%d) in %s(%d):%s %s\n", Mage(OWNER(player)) ? "WIZ: " : "", (Typeof(player) != TYPE_PLAYER) ? NAME(player) : "", (Typeof(player) != TYPE_PLAYER) ? " by " : "", NAME(OWNER(player)), (int) player, NAME(DBFETCH(player)->location), (int) DBFETCH(player)->location, (FLAGS(player) & INTERACTIVE) ? " [interactive]" : " ", command); } if (FLAGS(player) & INTERACTIVE) { interactive(descr, player, command); return; } /* eat leading whitespace */ while (*command && isspace(*command)) command++; commandstuff = command; /* check for single-character commands */ if (*command == SAY_TOKEN || *command == '\'') { sprintf(pbuf, "say %s", command + 1); command = &pbuf[0]; } else if (*command == POSE_TOKEN || *command == ';') { sprintf(pbuf, "pose %s", command + 1); command = &pbuf[0]; } else if ((*command == '|' || (*commandstuff++ == '\\' && *commandstuff == '\\') ) && can_move(descr, player, "spoof", 0)) { if(*command = '\\') sprintf(pbuf, "spoof %s", command + 2); else sprintf(pbuf, "spoof %s", command + 1); command = &pbuf[0]; } /* if player is a wizard, and uses overide token to start line...*/ /* ... then do NOT run actions, but run the command they specify. */ if (!strcmp(command, WHO_COMMAND)) { char xxbuf[BUFFER_LEN]; strcpy(xxbuf, "@"); strcat(xxbuf, WHO_COMMAND); strcat(xxbuf, " "); strcat(xxbuf, command + sizeof(WHO_COMMAND) - 1); if (can_move(descr, player, xxbuf, 5)) { do_move(descr, player, xxbuf, 5); } else { pdump_who_users(descr, command + sizeof(WHO_COMMAND) - 1); } return; } if (!( *command == OVERIDE_TOKEN && TMage(player) )) { if( can_move(descr, player, command, 0) ) { do_move(descr, player, command, 0); /* command is exact match for exit */ *match_args = 0; *match_cmdname = 0; return; } } if (*command == OVERIDE_TOKEN && TMage(player)) command++; full_command = strcpy(xbuf, command); for (; *full_command && !isspace(*full_command); full_command++); if (*full_command) full_command++; /* find arg1 -- move over command word */ command = strcpy(ybuf, command); for (arg1 = command; *arg1 && !isspace(*arg1); arg1++); /* truncate command */ if (*arg1) *arg1++ = '\0'; /* remember command for programs */ strcpy(match_cmdname, command); /* move over spaces */ while (*arg1 && isspace(*arg1)) arg1++; /* find end of arg1, start of arg2 */ for (arg2 = arg1; *arg2 && *arg2 != ARG_DELIMITER; arg2++); /* truncate arg1 */ for (p = arg2 - 1; p >= arg1 && isspace(*p); p--) *p = '\0'; /* go past delimiter if present */ if (*arg2) *arg2++ = '\0'; while (*arg2 && isspace(*arg2)) arg2++; strcpy(match_cmdname, command); strcpy(match_args, full_command); switch (command[0]) { case '@': switch (command[1]) { case 'a': case 'A': /* @action, @attach */ switch (command[2]) { case 'c': case 'C': Matched("@action"); do_action(descr, player, arg1, arg2); break; case 'r': case 'R': if (string_compare(command, "@armageddon")) goto bad; do_armageddon(player, full_command); break; case 't': case 'T': Matched("@attach"); do_attach(descr, player, arg1, arg2); break; case 'n': case 'N': Matched("@ansidescribe"); do_ansidescribe(descr, player, arg1, arg2); break; default: goto bad; } break; case 'b': case 'B': Matched("@boot"); do_boot(player, arg1); break; case 'c': case 'C': /* chown, contents, create */ switch (command[2]) { case 'h': case 'H': switch (command[3]) { case 'l': case 'L': Matched("@chlock"); do_chlock(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("@chown"); do_chown(descr, player, arg1, arg2); break; default: goto bad; } break; case 'o': case 'O': switch (command[4]) { case 'l': case 'L': Matched("@conlock"); do_conlock(descr, player, arg1, arg2); break; case 't': case 'T': Matched("@contents"); do_contents(descr, player, arg1, arg2); break; default: goto bad; } break; case 'r': case 'R': if (string_compare(command, "@credits")) { Matched("@create"); do_create(player, arg1, arg2); } else { do_credits(player); } break; default: goto bad; } break; case 'd': case 'D': /* describe, dequeue, dig, or dump */ switch (command[2]) { case 'b': case 'B': Matched("@dbginfo"); do_serverdebug(descr, player, arg1, arg2); break; case 'e': case 'E': #ifdef DELTADUMPS if(command[3] == 'l' || command[3] == 'L') { Matched("@delta"); do_delta(player); } else #endif { if( (command[3] == 's' || command[3] == 'S') && (command[4] == 't' || command[4] == 'T') ) { Matched("@destroy"); do_recycle(descr, player, arg1); } else { Matched("@describe"); do_describe(descr, player, arg1, arg2); } } break; case 'i': case 'I': Matched("@dig"); do_dig(descr, player, arg1, arg2); break; #ifdef DELTADUMPS case 'l': case 'L': Matched("@dlt"); do_delta(player); break; #endif case 'o': case 'O': Matched("@doing"); if (!tp_who_doing) goto bad; do_doing(descr, player, arg1, arg2); break; case 'r': case 'R': Matched("@drop"); do_drop_message(descr, player, arg1, arg2); break; case 'u': case 'U': Matched("@dump"); do_dump(player, full_command); break; default: goto bad; } break; case 'e': case 'E': switch (command[2]) { case 'd': case 'D': Matched("@edit"); do_edit(descr, player, arg1); break; case 'n': case 'N': Matched("@entrances"); do_entrances(descr, player, arg1, arg2); break; case 'x': case 'X': Matched("@examine"); sane_dump_object(player, arg1); break; default: goto bad; } break; case 'f': case 'F': /* fail, find, force, or frob */ switch (command[2]) { case 'a': case 'A': Matched("@fail"); do_fail(descr, player, arg1, arg2); break; case 'i': case 'I': if(command[3] == 'x' || command[3] == 'X') { Matched("@fixwizbits"); do_fixw(player, full_command); } else { Matched("@find"); do_find(player, arg1, arg2); } break; case 'l': case 'L': Matched("@flock"); do_flock(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("@force"); do_force(descr, player, arg1, arg2); break; case 'r': case 'R': if (string_compare(command, "@frob")) goto bad; do_frob(descr, player, arg1, arg2); break; default: goto bad; } break; case 'h': case 'H': switch (command[2]) { case 'T': case 't': Matched("@htmldescribe"); do_htmldescribe(descr, player, arg1, arg2); break; default: Matched("@hopper"); do_hopper(player, arg1); break; } break; case 'i': case 'I': switch(command[2]) { case 'h': case 'H': Matched("@ihtmldescribe"); do_ihtmldescribe(descr, player, arg1, arg2); break; case 'a': case 'A': Matched("@iansidescribe"); do_iansidescribe(descr, player, arg1, arg2); break; default: Matched("@idescribe"); do_idescribe(descr, player, arg1, arg2); break; } break; case 'k': case 'K': Matched("@kill"); do_dequeue(descr, player, arg1); break; case 'l': case 'L': /* lock or link */ switch (command[2]) { case 'i': case 'I': switch (command[3]) { case 'n': case 'N': Matched("@link"); do_link(descr, player, arg1, arg2); break; case 's': case 'S': Matched("@list"); match_and_list(descr, player, arg1, arg2, 1); break; default: goto bad; } break; case 'o': case 'O': Matched("@lock"); do_lock(descr, player, arg1, arg2); break; default: goto bad; } break; case 'm': case 'M': switch (command[2]) { case 'e': case 'E': Matched("@memory"); do_memory(player); break; case 'c': case 'C': switch (command[4]) { case '2': Matched("@mcp2muf"); match_and_list(descr, player, arg1, arg2, 0); break; default: Matched("@mcp"); do_prog(descr, player, arg1, 1); break; } default: goto bad; } break; case 'n': case 'N': /* @name or @newpassword */ switch (command[2]) { case 'a': case 'A': Matched("@name"); do_name(descr, player, arg1, arg2); break; case 'e': case 'E': if (string_compare(command, "@newpassword")) goto bad; do_newpassword(player, arg1, arg2); break; default: goto bad; } break; case 'o': case 'O': switch (command[2]) { case 'd': case 'D': Matched("@odrop"); do_odrop(descr, player, arg1, arg2); break; case 'e': case 'E': Matched("@oecho"); do_oecho(descr, player, arg1, arg2); break; case 'f': case 'F': Matched("@ofail"); do_ofail(descr, player, arg1, arg2); break; case 'p': case 'P': Matched("@open"); do_open(descr, player, arg1, arg2); break; case 's': case 'S': Matched("@osuccess"); do_osuccess(descr, player, arg1, arg2); break; case 'w': case 'W': Matched("@owned"); do_owned(player, arg1, arg2); break; default: goto bad; } break; case 'p': case 'P': switch (command[2]) { case 'a': case 'A': Matched("@password"); do_password(player, arg1, arg2); break; case 'c': case 'C': Matched("@pcreate"); do_pcreate(player, arg1, arg2); break; case 'e': case 'E': Matched("@pecho"); do_pecho(descr, player, arg1, arg2); break; case 'r': case 'R': if (string_prefix("@program", command)) { do_prog(descr, player, arg1, 0); break; } else if (string_prefix("@proginfo", command)) { do_proginfo(player, arg1); break; } else { Matched("@propset"); do_propset(descr, player, arg1, arg2); break; } case 's': case 'S': Matched("@ps"); list_events(player); break; case 'u': case 'U': Matched("@purge"); do_purge(descr, player, arg1, arg2); break; default: goto bad; } break; case 'r': case 'R': switch (command[3]) { case 'c': case 'C': Matched("@recycle"); do_recycle(descr, player, arg1); break; case 's': case 'S': if (!string_compare(command, "@restart")) { do_restart(player, full_command); } else if (!string_compare(command, "@restrict")) { do_restrict(player, arg1); } else { goto bad; } break; default: goto bad; } break; case 's': case 'S': /* set, shutdown, success */ switch (command[2]) { case 'a': case 'A': if (!string_compare(command, "@sanity")) { sanity(player); } else if (!string_compare(command, "@sanchange")) { sanechange(player, full_command); } else if (!string_compare(command, "@sanfix")) { sanfix(player); } else { goto bad; } break; case 'e': case 'E': Matched("@set"); do_set(descr, player, arg1, arg2); break; case 'h': case 'H': if (!string_compare(command, "@shout")) { do_wall(player, full_command); break; } if (string_compare(command, "@shutdown")) goto bad; do_shutdown(player, arg1); break; case 't': case 'T': Matched("@stats"); do_stats(player, arg1); break; case 'u': case 'U': Matched("@success"); do_success(descr, player, arg1, arg2); break; case 'w': case 'W': Matched("@sweep"); do_sweep(descr, player, arg1); break; default: goto bad; } break; case 't': case 'T': switch (command[2]) { case 'e': case 'E': Matched("@teleport"); do_teleport(descr, player, arg1, arg2); break; case 'o': case 'O': if (string_compare(command, "@toad")) goto bad; do_frob(descr, player, arg1, arg2); break; case 'r': case 'R': Matched("@trace"); do_trace(descr, player, arg1, atoi(arg2)); break; case 'u': case 'U': Matched("@tune"); do_tune(player, arg1, arg2); break; default: goto bad; } break; case 'u': case 'U': switch (command[2]) { case 'N': case 'n': if (string_prefix(command, "@unlink")) { do_unlink(descr, player, arg1); } else if (string_prefix(command, "@unlock")) { do_unlock(descr, player, arg1); } else if (string_prefix(command, "@uncompile")) { do_uncompile(player); } else { goto bad; } break; #ifndef NO_USAGE_COMMAND case 'S': case 's': Matched("@usage"); do_usage(player); break; #endif default: goto bad; break; } break; case 'v': case 'V': Matched("@version"); anotify_nolisten2(player, CRIMSON "ProtoMUCK " PROTOBASE PURPLE " (" RED VERSION WHITE " -- " AQUA NEONVER PURPLE ")" ); break; case 'w': case 'W': if (string_compare(command, "@wall")) goto bad; do_wall(player, full_command); break; default: goto bad; } break; case '&': do_mush_set(descr, player, arg1, arg2, command); break; case 'd': case 'D': switch (command[1]) { case 'b': case 'B': Matched("dboot"); do_dboot(player, arg1); break; case 'i': case 'I': Matched("dinfo"); do_dinfo(player, arg1); break; case 'r': case 'R': Matched("drop"); do_drop(descr, player, arg1, arg2); break; case 'w': case 'W': Matched("dwall"); do_dwall(player, arg1, arg2); break; default: goto bad; } break; case 'e': case 'E': switch (command[1]) { case 'm': case 'M': Matched("emote"); do_pose(descr, player, full_command); break; case 'x': case 'X': case '\0': Matched("examine"); do_examine(descr, player, arg1, arg2); break; default: goto bad; } break; case 'g': case 'G': /* get, give, go, or gripe */ switch (command[1]) { case 'e': case 'E': Matched("get"); do_get(descr, player, arg1, arg2); break; case 'i': case 'I': Matched("give"); do_give(descr, player, arg1, atoi(arg2)); break; case 'o': case 'O': Matched("goto"); do_move(descr, player, arg1, 0); break; case 'r': case 'R': if(command[2]=='i' || command[2]=='I') { if (string_compare(command, "gripe")) goto bad; do_gripe(player, full_command); break; } default: goto bad; } break; case 'h': case 'H': switch (command[1]) { case 'a': case 'A': Matched("hand"); do_drop(descr, player, arg1, arg2); break; case 'e': case 'E': Matched("help"); do_help(player, arg1, arg2); break; default: goto bad; } break; case 'i': case 'I': if (string_compare(command, "info")) { Matched("inventory"); do_inventory(player); } else { do_info(player, arg1, arg2); } break; case 'l': case 'L': if (string_prefix("look", command)) { do_look_at(descr, player, arg1, arg2); break; } else { Matched("leave"); do_leave(descr, player); break; } case 'm': case 'M': if (string_prefix(command, "move")) { do_move(descr, player, arg1, 0); break; } else if (!string_compare(command, "motd")) { do_motd(player, full_command); break; } else if (!string_compare(command, "mpi")) { do_mpihelp(player, arg1, arg2); break; } else { if (string_compare(command, "man")) goto bad; do_man(player, arg1, arg2); } break; case 'n': case 'N': /* news */ Matched("news"); do_news(player, arg1, arg2); break; case 'p': case 'P': switch (command[1]) { case 'a': case 'A': case '\0': Matched("page"); do_page(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("pose"); do_pose(descr, player, full_command); break; case 'u': case 'U': Matched("put"); do_drop(descr, player, arg1, arg2); break; default: goto bad; } break; case 'r': case 'R': switch (command[1]) { case 'e': case 'E': if(command[2] == 'q' || command[2] == 'Q'){ Matched("request"); request(player, NULL, commandline); } else { Matched("read"); /* undocumented alias for look */ do_look_at(descr, player, arg1, arg2); } break; default: goto bad; } break; case 's': case 'S': /* say, "score" */ switch (command[1]) { case 'a': case 'A': Matched("say"); do_say(descr, player, full_command); break; case 'c': case 'C': case '\0': if( command[1] && (command[2] == 'a' || command[2] == 'A' )) { Matched("scan"); do_sweep(descr, player, arg1); } else { Matched("score"); do_score(player, 1); } break; default: goto bad; } break; case 't': case 'T': switch (command[1]) { case 'a': case 'A': Matched("take"); do_get(descr, player, arg1, arg2); break; case 'h': case 'H': Matched("throw"); do_drop(descr, player, arg1, arg2); break; default: goto bad; } break; case 'w': case 'W': switch (command[1]){ case 'c': case 'C': Matched("wc"); do_wizchat(player, full_command); break; case 'i': case 'I': Matched("wizchat"); do_wizchat(player, arg1); break; case 'h': case 'H': case '\0': Matched("whisper"); do_whisper(descr, player, arg1, arg2); break; default: goto bad; } break; default: bad: if ( Typeof(tp_huh_command) == TYPE_PROGRAM && !(player == -1)) { tmpfr = interp(descr, player, DBFETCH(player)->location, tp_huh_command, (dbref)-4, FOREGROUND, STD_REGUID); if (!tmpfr) goto bad2; (void) interp_loop(player, tp_huh_command, tmpfr, 0); } else { bad2: anotify_fmt(player, CINFO "%s",tp_huh_mesg); if (tp_log_failed_commands && !controls(player, DBFETCH(player)->location)) { log_status("HUH from %s(%d) in %s(%d)[%s]: %s %s\n", NAME(player), player, NAME(DBFETCH(player)->location), DBFETCH(player)->location, NAME(OWNER(DBFETCH(player)->location)), command, full_command); } } break; } }
void set_property_nofetch(dbref player, const char *type, int flags, PTYPE value) { PropPtr p; char buf[BUFFER_LEN]; char *n, *w; /* Make sure that we are passed a valid property name */ if (!type) return; /* if (tp_db_readonly) return; *//* Why did we remove this? */ while (*type == PROPDIR_DELIMITER) type++; if ((!(FLAGS(player) & LISTENER)) && (string_prefix(type, "_listen") || string_prefix(type, "~listen") || string_prefix(type, "@listen") || string_prefix(type, "_olisten") || string_prefix(type, "~olisten") || string_prefix(type, "@olisten") || string_prefix(type, "_alisten") || string_prefix(type, "~alisten") || string_prefix(type, "@alisten") || string_prefix(type, "_aolisten") || string_prefix(type, "~aolisten") || string_prefix(type, "@aolisten"))) { FLAGS(player) |= LISTENER; } if ((!(FLAG2(player) & F2COMMAND)) && (string_prefix(type, "_command") || string_prefix(type, "~command") || string_prefix(type, "@command") || string_prefix(type, "_ocommand") || string_prefix(type, "~ocommand") || string_prefix(type, "@ocommand"))) { FLAG2(player) |= F2COMMAND; } w = strcpy(buf, type); /* truncate propnames with a ':' in them at the ':' */ n = index(buf, PROP_DELIMITER); if (n) *n = '\0'; if (!*buf) return; p = propdir_new_elem(&(DBFETCH(player)->properties), w); /* free up any old values */ clear_propnode(p); SetPFlagsRaw(p, flags); if (PropFlags(p) & PROP_ISUNLOADED) { SetPDataVal(p, (int) value); return; } switch (PropType(p)) { case PROP_STRTYP: if (!value || !*((char *) value)) { SetPType(p, PROP_DIRTYP); SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); } else { /* char *cptr = (char *) value; while (cptr) { if (*cptr == '\n') *cptr = '\r'; ++cptr; } */ SetPDataStr(p, alloc_compressed((char *) value)); #ifdef COMPRESS SetPFlagsRaw(p, (flags | PROP_COMPRESSED)); #endif } break; case PROP_INTTYP: SetPDataVal(p, (int) value); if (!value) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(player, type); } break; case PROP_FLTTYP: SetPDataFVal(p, strtod(value, NULL)); if (strtod(value, NULL) == 0) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) { remove_property_nofetch(player, type); } } break; case PROP_REFTYP: if (((dbref) value) == NOTHING) { SetPType(p, PROP_DIRTYP); SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); } else { SetPDataRef(p, (dbref) value); } break; case PROP_LOKTYP: SetPDataLok(p, (struct boolexp *) value); /* * if ((struct boolexp *)value == TRUE_BOOLEXP) { * SetPType(p, PROP_DIRTYP); * SetPDataVal(p, 0); * if (!PropDir(p)) * remove_property_nofetch(player, type); * } else { * SetPDataLok(p, (struct boolexp *)value); * } */ break; case PROP_DIRTYP: SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); break; } }
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; } }
void process_command(int descr, dbref player, char *command) { char *arg1; char *arg2; char *full_command; char *p; /* utility */ char pbuf[BUFFER_LEN]; char xbuf[BUFFER_LEN]; char ybuf[BUFFER_LEN]; struct timeval starttime; struct timeval endtime; double totaltime; if (command == 0) abort(); /* robustify player */ if (player < 0 || player >= db_top || (Typeof(player) != TYPE_PLAYER && Typeof(player) != TYPE_THING)) { log_status("process_command: bad player %d", player); return; } if ((tp_log_commands || Wizard(OWNER(player)))) { if (!(FLAGS(player) & (INTERACTIVE | READMODE))) { if (!*command) { return; } log_command("%s: %s", whowhere(player), command); } else { if (tp_log_interactive) { log_command("%s: %s%s", whowhere(player), (FLAGS(player) & (READMODE)) ? "[READ] " : "[INTERP] ", command); } } } if (FLAGS(player) & INTERACTIVE) { interactive(descr, player, command); return; } /* eat leading whitespace */ while (*command && isspace(*command)) command++; /* Disable null command once past READ line */ if (!*command) return; /* check for single-character commands */ if (!tp_enable_prefix) { if (*command == SAY_TOKEN) { snprintf(pbuf, sizeof(pbuf), "say %s", command + 1); command = &pbuf[0]; } else if (*command == POSE_TOKEN) { snprintf(pbuf, sizeof(pbuf), "pose %s", command + 1); command = &pbuf[0]; } else if (*command == EXIT_DELIMITER) { snprintf(pbuf, sizeof(pbuf), "delimiter %s", command + 1); command = &pbuf[0]; } } /* profile how long command takes. */ gettimeofday(&starttime, NULL); /* if player is a wizard, and uses overide token to start line... */ /* ... then do NOT run actions, but run the command they specify. */ if (!(TrueWizard(OWNER(player)) && (*command == OVERIDE_TOKEN))) { if (can_move(descr, player, command, 0)) { do_move(descr, player, command, 0); /* command is exact match for exit */ *match_args = 0; *match_cmdname = 0; } else { if (tp_enable_prefix) { if (*command == SAY_TOKEN) { snprintf(pbuf, sizeof(pbuf), "say %s", command + 1); command = &pbuf[0]; } else if (*command == POSE_TOKEN) { snprintf(pbuf, sizeof(pbuf), "pose %s", command + 1); command = &pbuf[0]; } else if (*command == EXIT_DELIMITER) { snprintf(pbuf, sizeof(pbuf), "delimiter %s", command + 1); command = &pbuf[0]; } else { goto bad_pre_command; } if (can_move(descr, player, command, 0)) { do_move(descr, player, command, 0); /* command is exact match for exit */ *match_args = 0; *match_cmdname = 0; } else { goto bad_pre_command; } } else { goto bad_pre_command; } } } else { bad_pre_command: if (TrueWizard(OWNER(player)) && (*command == OVERIDE_TOKEN)) command++; full_command = strcpyn(xbuf, sizeof(xbuf), command); for (; *full_command && !isspace(*full_command); full_command++) ; if (*full_command) full_command++; /* find arg1 -- move over command word */ command = strcpyn(ybuf, sizeof(ybuf), command); for (arg1 = command; *arg1 && !isspace(*arg1); arg1++) ; /* truncate command */ if (*arg1) *arg1++ = '\0'; /* remember command for programs */ strcpyn(match_args, sizeof(match_args), full_command); strcpyn(match_cmdname, sizeof(match_cmdname), command); /* move over spaces */ while (*arg1 && isspace(*arg1)) arg1++; /* find end of arg1, start of arg2 */ for (arg2 = arg1; *arg2 && *arg2 != ARG_DELIMITER; arg2++) ; /* truncate arg1 */ for (p = arg2 - 1; p >= arg1 && isspace(*p); p--) *p = '\0'; /* go past delimiter if present */ if (*arg2) *arg2++ = '\0'; while (*arg2 && isspace(*arg2)) arg2++; switch (command[0]) { case '@': switch (command[1]) { case 'a': case 'A': /* @action, @armageddon, @attach */ switch (command[2]) { case 'c': case 'C': Matched("@action"); NOGUEST("@action", player); BUILDERONLY("@action", player); do_action(descr, player, arg1, arg2); break; case 'r': case 'R': if (strcmp(command, "@armageddon")) goto bad; /* WIZARDONLY("@armageddon", player); PLAYERONLY("@armageddon", player); */ do_armageddon(player, full_command); break; case 't': case 'T': Matched("@attach"); NOGUEST("@attach", player); BUILDERONLY("@attach", player); do_attach(descr, player, arg1, arg2); break; default: goto bad; } break; case 'b': case 'B': /* @bless, @boot */ switch (command[2]) { case 'l': case 'L': Matched("@bless"); WIZARDONLY("@bless", player); PLAYERONLY("@bless", player); NOFORCE("@bless", force_level, player); do_bless(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("@boot"); WIZARDONLY("@boot", player); PLAYERONLY("@boot", player); do_boot(player, arg1); break; default: goto bad; } break; case 'c': case 'C': /* @chlock, @chown, @chown_lock, @clone, @conlock, @contents, @create, @credits */ switch (command[2]) { case 'h': case 'H': switch (command[3]) { case 'l': case 'L': Matched("@chlock"); NOGUEST("@chlock", player); set_standard_lock(descr, player, arg1, MESGPROP_CHLOCK, "Chown Lock", arg2); break; case 'o': case 'O': if(strlen(command) < 7) { Matched("@chown"); do_chown(descr, player, arg1, arg2); } else { Matched("@chown_lock"); NOGUEST("@chown_lock", player); set_standard_lock(descr, player, arg1, MESGPROP_CHLOCK, "Chown Lock", arg2); } break; default: goto bad; } break; case 'l': case 'L': Matched("@clone"); NOGUEST("@clone", player); BUILDERONLY("@clone", player); do_clone(descr, player, arg1); break; case 'o': case 'O': switch (command[4]) { case 'l': case 'L': Matched("@conlock"); NOGUEST("@conlock", player); set_standard_lock(descr, player, arg1, MESGPROP_CONLOCK, "Container Lock", arg2); break; case 't': case 'T': Matched("@contents"); do_contents(descr, player, arg1, arg2); break; default: goto bad; } break; case 'r': case 'R': if (string_compare(command, "@credits")) { Matched("@create"); NOGUEST("@create", player); BUILDERONLY("@create", player); do_create(player, arg1, arg2); } else { do_credits(player); } break; default: goto bad; } break; case 'd': case 'D': /* @dbginfo, @describe, @dig, @doing, @drop, @dump */ switch (command[2]) { #ifdef DISKBASE case 'b': case 'B': Matched("@dbginfo"); WIZARDONLY("@dbginfo", player); diskbase_debug(player); break; #endif case 'e': case 'E': Matched("@describe"); NOGUEST("@describe", player); set_standard_property(descr, player, arg1, MESGPROP_DESC, "Object Description", arg2); break; case 'i': case 'I': Matched("@dig"); NOGUEST("@dig", player); BUILDERONLY("@dig", player); do_dig(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("@doing"); if (!tp_who_doing) goto bad; NOGUEST("@doing", player); set_standard_property(descr, player, arg1, MESGPROP_DOING, "Doing", arg2); break; case 'r': case 'R': Matched("@drop"); NOGUEST("@drop", player); set_standard_property(descr, player, arg1, MESGPROP_DROP, "Drop Message", arg2); break; case 'u': case 'U': Matched("@dump"); WIZARDONLY("@dump", player); PLAYERONLY("@dump", player); do_dump(player, full_command); break; default: goto bad; } break; case 'e': case 'E': /* @edit, @entrances, @examine */ switch (command[2]) { case 'd': case 'D': Matched("@edit"); NOGUEST("@edit", player); PLAYERONLY("@edit", player); MUCKERONLY("@edit", player); do_edit(descr, player, arg1); break; case 'n': case 'N': Matched("@entrances"); do_entrances(descr, player, arg1, arg2); break; case 'x': case 'X': Matched("@examine"); GODONLY("@examine", player); sane_dump_object(player, arg1); break; default: goto bad; } break; case 'f': case 'F': /* @fail, @find, @flock, @force, @force_lock */ switch (command[2]) { case 'a': case 'A': Matched("@fail"); NOGUEST("@fail", player); set_standard_property(descr, player, arg1, MESGPROP_FAIL, "Fail Message", arg2); break; case 'i': case 'I': Matched("@find"); do_find(player, arg1, arg2); break; case 'l': case 'L': Matched("@flock"); NOGUEST("@flock", player); NOFORCE("@flock", force_level, player); set_standard_lock(descr, player, arg1, MESGPROP_FLOCK, "Force Lock", arg2); break; case 'o': case 'O': if(strlen(command) < 7) { Matched("@force"); do_force(descr, player, arg1, arg2); } else { Matched("@force_lock"); NOGUEST("@force_lock", player); NOFORCE("@force_lock", force_level, player); set_standard_lock(descr, player, arg1, MESGPROP_FLOCK, "Force Lock", arg2); } break; default: goto bad; } break; case 'h': case 'H': /* @hashes */ Matched("@hashes"); do_hashes(player, arg1); break; case 'i': case 'I': /* @idescribe */ Matched("@idescribe"); NOGUEST("@idescribe", player); set_standard_property(descr, player, arg1, MESGPROP_IDESC, "Inside Description", arg2); break; case 'k': case 'K': /* @kill */ Matched("@kill"); do_dequeue(descr, player, arg1); break; case 'l': case 'L': /* @link, @list, @lock */ switch (command[2]) { case 'i': case 'I': switch (command[3]) { case 'n': case 'N': Matched("@link"); NOGUEST("@link", player); do_link(descr, player, arg1, arg2); break; case 's': case 'S': Matched("@list"); match_and_list(descr, player, arg1, arg2); break; default: goto bad; } break; case 'o': case 'O': Matched("@lock"); NOGUEST("@lock", player); set_standard_lock(descr, player, arg1, MESGPROP_LOCK, "Lock", arg2); break; default: goto bad; } break; case 'm': case 'M': /* @mcpedit, @mcpprogram, @memory, @mpitops, @muftops */ switch (command[2]) { #ifdef MCP_SUPPORT case 'c': case 'C': if (string_prefix("@mcpedit", command)) { Matched("@mcpedit"); NOGUEST("@mcpedit", player); PLAYERONLY("@mcpedit", player); MUCKERONLY("@mcpedit", player); do_mcpedit(descr, player, arg1); break; } else { Matched("@mcpprogram"); NOGUEST("@mcpprogram", player); PLAYERONLY("@mcpprogram", player); MUCKERONLY("@mcpprogram", player); do_mcpprogram(descr, player, arg1); break; } #endif #ifndef NO_MEMORY_COMMAND case 'e': case 'E': Matched("@memory"); WIZARDONLY("@memory", player); do_memory(player); break; #endif case 'p': case 'P': Matched("@mpitops"); WIZARDONLY("@mpitops", player); do_mpi_topprofs(player, arg1); break; case 'u': case 'U': Matched("@muftops"); WIZARDONLY("@muftops", player); do_muf_topprofs(player, arg1); break; default: goto bad; } break; case 'n': case 'N': /* @name, @newpassword */ switch (command[2]) { case 'a': case 'A': Matched("@name"); NOGUEST("@name", player); do_name(descr, player, arg1, arg2); break; case 'e': case 'E': if (strcmp(command, "@newpassword")) goto bad; WIZARDONLY("@newpassword", player); PLAYERONLY("@newpassword", player); do_newpassword(player, arg1, arg2); break; default: goto bad; } break; case 'o': case 'O': /* @odrop, @oecho, @ofail, @open, @osuccess, @owned */ switch (command[2]) { case 'd': case 'D': Matched("@odrop"); NOGUEST("@odrop", player); set_standard_property(descr, player, arg1, MESGPROP_ODROP, "ODrop Message", arg2); break; case 'e': case 'E': Matched("@oecho"); NOGUEST("@oecho", player); set_standard_property(descr, player, arg1, MESGPROP_OECHO, "Outside-echo Prefix", arg2); break; case 'f': case 'F': Matched("@ofail"); NOGUEST("@ofail", player); set_standard_property(descr, player, arg1, MESGPROP_OFAIL, "OFail Message", arg2); break; case 'p': case 'P': Matched("@open"); NOGUEST("@open", player); BUILDERONLY("@open", player); do_open(descr, player, arg1, arg2); break; case 's': case 'S': Matched("@osuccess"); NOGUEST("@osuccess", player); set_standard_property(descr, player, arg1, MESGPROP_OSUCC, "OSuccess Message", arg2); break; case 'w': case 'W': Matched("@owned"); do_owned(player, arg1, arg2); break; default: goto bad; } break; case 'p': case 'P': /* @password, @pcreate, @pecho, @program, @propset, @ps */ switch (command[2]) { case 'a': case 'A': Matched("@password"); PLAYERONLY("@password", player); NOGUEST("@password", player); do_password(player, arg1, arg2); break; case 'c': case 'C': Matched("@pcreate"); WIZARDONLY("@pcreate", player); PLAYERONLY("@pcreate", player); do_pcreate(player, arg1, arg2); break; case 'e': case 'E': Matched("@pecho"); NOGUEST("@pecho", player); set_standard_property(descr, player, arg1, MESGPROP_PECHO, "Puppet-echo Prefix", arg2); break; case 'r': case 'R': if (string_prefix("@program", command)) { Matched("@program"); NOGUEST("@program", player); PLAYERONLY("@program", player); MUCKERONLY("@program", player); do_prog(descr, player, arg1); break; } else { Matched("@propset"); NOGUEST("@propset", player); do_propset(descr, player, arg1, arg2); break; } case 's': case 'S': Matched("@ps"); list_events(player); break; default: goto bad; } break; case 'r': case 'R': /* @recycle, @reconfiguressl, @relink, @restart, @restrict */ switch (command[3]) { case 'c': case 'C': #ifdef USE_SSL if (!strcmp(command, "@reconfiguressl")) { WIZARDONLY("@reconfiguressl", player); PLAYERONLY("@reconfiguressl", player); do_reconfigure_ssl(player); break; } #endif Matched("@recycle"); NOGUEST("@recycle", player); do_recycle(descr, player, arg1); break; case 'l': case 'L': Matched("@relink"); NOGUEST("@relink", player); do_relink(descr, player, arg1, arg2); break; case 's': case 'S': if (!strcmp(command, "@restart")) { /* WIZARDONLY("@restart", player); PLAYERONLY("@restart", player); */ do_restart(player); } else if (!strcmp(command, "@restrict")) { WIZARDONLY("@restrict", player); PLAYERONLY("@restrict", player); do_restrict(player, arg1); } else { goto bad; } break; default: goto bad; } break; case 's': case 'S': /* @sanity, @sanchange, @sanfix, @set, @shutdown, @stats, @success, @sweep */ switch (command[2]) { case 'a': case 'A': if (!strcmp(command, "@sanity")) { GODONLY("@sanity", player); sanity(player); } else if (!strcmp(command, "@sanchange")) { GODONLY("@sanchange", player); sanechange(player, full_command); } else if (!strcmp(command, "@sanfix")) { GODONLY("@sanfix", player); sanfix(player); } else { goto bad; } break; case 'e': case 'E': Matched("@set"); NOGUEST("@set", player); do_set(descr, player, arg1, arg2); break; case 'h': case 'H': if (strcmp(command, "@shutdown")) goto bad; /* WIZARDONLY("@shutdown", player); PLAYERONLY("@shutdown", player); */ do_shutdown(player); break; case 't': case 'T': Matched("@stats"); do_stats(player, arg1); break; case 'u': case 'U': Matched("@success"); NOGUEST("@success", player); set_standard_property(descr, player, arg1, MESGPROP_SUCC, "Success Message", arg2); break; case 'w': case 'W': Matched("@sweep"); do_sweep(descr, player, arg1); break; default: goto bad; } break; case 't': case 'T': /* @teleport, @toad, @trace, @tune */ switch (command[2]) { case 'e': case 'E': Matched("@teleport"); do_teleport(descr, player, arg1, arg2); break; case 'o': case 'O': if (!strcmp(command, "@toad")) { WIZARDONLY("@toad", player); PLAYERONLY("@toad", player); do_toad(descr, player, arg1, arg2); } else if (!strcmp(command, "@tops")) { WIZARDONLY("@tops", player); do_all_topprofs(player, arg1); } else { goto bad; } break; case 'r': case 'R': Matched("@trace"); do_trace(descr, player, arg1, atoi(arg2)); break; case 'u': case 'U': Matched("@tune"); WIZARDONLY("@tune", player); PLAYERONLY("@tune", player); do_tune(player, arg1, arg2, !!strchr(full_command, ARG_DELIMITER)); break; default: goto bad; } break; case 'u': case 'U': /* @unbless, @unlink, @unlock, @uncompile, @usage */ switch (command[2]) { case 'N': case 'n': if (string_prefix(command, "@unb")) { Matched("@unbless"); WIZARDONLY("@unbless", player); PLAYERONLY("@unbless", player); NOFORCE("@unbless", force_level, player); do_unbless(descr, player, arg1, arg2); } else if (string_prefix(command, "@unli")) { Matched("@unlink"); NOGUEST("@unlink", player); do_unlink(descr, player, arg1); } else if (string_prefix(command, "@unlo")) { Matched("@unlock"); NOGUEST("@unlock", player); set_standard_lock(descr, player, arg1, MESGPROP_LOCK, "Lock", ""); } else if (string_prefix(command, "@uncom")) { Matched("@uncompile"); WIZARDONLY("@uncompile", player); PLAYERONLY("@uncompile", player); do_uncompile(player); } else { goto bad; } break; #ifndef NO_USAGE_COMMAND case 'S': case 's': Matched("@usage"); WIZARDONLY("@usage", player); do_usage(player); break; #endif default: goto bad; break; } break; case 'v': case 'V': /* @version */ Matched("@version"); do_version(player); break; case 'w': case 'W': /* @wall */ if (strcmp(command, "@wall")) goto bad; WIZARDONLY("@wall", player); PLAYERONLY("@wall", player); do_wall(player, full_command); break; default: goto bad; } break; case 'd': case 'D': /* disembark, drop */ switch (command[1]) { case 'i': case 'I': Matched("disembark"); do_leave(descr, player); break; case 'r': case 'R': Matched("drop"); do_drop(descr, player, arg1, arg2); break; default: goto bad; } break; case 'e': case 'E': /* examine */ Matched("examine"); do_examine(descr, player, arg1, arg2); break; case 'g': case 'G': /* get, give, goto, gripe */ switch (command[1]) { case 'e': case 'E': Matched("get"); do_get(descr, player, arg1, arg2); break; case 'i': case 'I': Matched("give"); do_give(descr, player, arg1, atoi(arg2)); break; case 'o': case 'O': Matched("goto"); do_move(descr, player, arg1, 0); break; case 'r': case 'R': if (string_compare(command, "gripe")) goto bad; do_gripe(player, full_command); break; default: goto bad; } break; case 'h': case 'H': /* help */ Matched("help"); do_help(player, arg1, arg2); break; case 'i': case 'I': /* inventory, info */ if (string_compare(command, "info")) { Matched("inventory"); do_inventory(player); } else { Matched("info"); do_info(player, arg1, arg2); } break; case 'k': case 'K': /* kill */ Matched("kill"); do_kill(descr, player, arg1, atoi(arg2)); break; case 'l': case 'L': /* leave, look */ if (string_prefix("look", command)) { Matched("look"); do_look_at(descr, player, arg1, arg2); break; } else { Matched("leave"); do_leave(descr, player); break; } case 'm': case 'M': /* man, motd, move, mpi */ if (string_prefix(command, "move")) { do_move(descr, player, arg1, 0); break; } else if (!string_compare(command, "motd")) { do_motd(player, full_command); break; } else if (!string_compare(command, "mpi")) { do_mpihelp(player, arg1, arg2); break; } else { if (string_compare(command, "man")) goto bad; do_man(player, (!*arg1 && !*arg2 && arg1 != arg2) ? "=" : arg1, arg2); } break; case 'n': case 'N': /* news */ Matched("news"); do_news(player, arg1, arg2); break; case 'p': case 'P': /* page, pose, put */ switch (command[1]) { case 'a': case 'A': Matched("page"); do_page(player, arg1, arg2); break; case 'o': case 'O': Matched("pose"); do_pose(player, full_command); break; case 'u': case 'U': Matched("put"); do_drop(descr, player, arg1, arg2); break; default: goto bad; } break; case 'r': case 'R': /* read, rob */ switch (command[1]) { case 'e': case 'E': Matched("read"); /* undocumented alias for look */ do_look_at(descr, player, arg1, arg2); break; case 'o': case 'O': Matched("rob"); do_rob(descr, player, arg1); break; default: goto bad; } break; case 's': case 'S': /* say, score */ switch (command[1]) { case 'a': case 'A': Matched("say"); do_say(player, full_command); break; case 'c': case 'C': Matched("score"); do_score(player); break; default: goto bad; } break; case 't': case 'T': /* take, throw */ switch (command[1]) { case 'a': case 'A': Matched("take"); do_get(descr, player, arg1, arg2); break; case 'h': case 'H': Matched("throw"); do_drop(descr, player, arg1, arg2); break; default: goto bad; } break; case 'w': case 'W': /* whisper */ Matched("whisper"); do_whisper(descr, player, arg1, arg2); break; default: bad: if (tp_m3_huh != 0) { char hbuf[BUFFER_LEN]; snprintf(hbuf,BUFFER_LEN,"HUH? %s", command); if(can_move(descr, player, hbuf, 3)) { do_move(descr, player, hbuf, 3); *match_args = 0; *match_cmdname = 0; break; } } notify(player, tp_huh_mesg); if (tp_log_failed_commands && !controls(player, LOCATION(player))) { log_status("HUH from %s(%d) in %s(%d)[%s]: %s %s", NAME(player), player, NAME(LOCATION(player)), LOCATION(player), NAME(OWNER(LOCATION(player))), command, full_command); } break; } } /* calculate time command took. */ gettimeofday(&endtime, NULL); if (starttime.tv_usec > endtime.tv_usec) { endtime.tv_usec += 1000000; endtime.tv_sec -= 1; } endtime.tv_usec -= starttime.tv_usec; endtime.tv_sec -= starttime.tv_sec; totaltime = endtime.tv_sec + (endtime.tv_usec * 1.0e-6); if (totaltime > (tp_cmd_log_threshold_msec / 1000.0)) { log2file(LOG_CMD_TIMES, "%6.3fs, %.16s: %s: %s", totaltime, ctime((time_t *)&starttime.tv_sec), whowhere(player), command); } }
char flag_2char(char *flag) { if (string_prefix("m", flag)) return 'M'; if (string_prefix("w", flag)) return 'W'; if (string_prefix("builder", flag) || string_prefix("bound", flag)) return 'B'; if (string_prefix("jump_ok", flag)) return 'J'; if (string_prefix("link_ok", flag)) return 'L'; if (string_prefix("dark", flag) || string_prefix("debugging", flag)) return 'D'; if (string_prefix("sticky", flag) || string_prefix("silent", flag) || string_prefix("setuid", flag)) return 'S'; if (string_prefix("quell", flag)) return 'Q'; if (string_prefix("chown_ok", flag) || string_prefix("color_on", flag) || string_prefix("ansi", flag)) return 'C'; if (string_prefix("haven", flag) || string_prefix("harduid", flag) || string_prefix("hide", flag)) return 'H'; if (string_prefix("abode", flag) || string_prefix("autostart", flag) || string_prefix("abate", flag)) return 'A'; if (string_prefix("vehicle", flag) || string_prefix("viewable", flag)) return 'V'; if (string_prefix("xforcible", flag) || string_prefix("expanded_debug", flag)) return 'X'; if (string_prefix("zombie", flag) || string_prefix("puppet", flag)) return 'Z'; if (string_prefix("guest", flag)) return 'G'; if (string_prefix("idle", flag)) return 'I'; #ifdef CONTROLS_SUPPORT if (string_prefix("controls", flag)) return '~'; #endif if (string_prefix("immobile", flag)) return '|'; if (string_prefix("mufcount", flag)) return '+'; if (string_prefix("light", flag) || string_prefix("oldcomment", flag)) return 'O'; if (string_prefix("parent", flag) || string_prefix("prog_debug", flag)) return '%'; if (string_prefix("protect", flag)) return '*'; if (string_prefix("antiprotect", flag)) return 'K'; if (string_prefix("examine_ok", flag)) return 'Y'; if (string_prefix("no_command", flag)) return 'N'; if (string_prefix("hidden", flag)) return '#'; if (string_prefix("pueblo", flag)) return '$'; if (string_prefix("nhtml", flag) || string_prefix("html", flag)) return '&'; if (string_prefix("meeper", flag) || string_prefix("mpi", flag)) return LMPI + '0'; if (string_prefix("mucker", flag) || string_prefix("mucker1", flag) || string_prefix("m1", flag)) return LM1 + '0'; if (string_prefix("nucker", flag) || string_prefix("mucker2", flag) || string_prefix("m2", flag)) return LM2 + '0'; if (string_prefix("sucker", flag) || string_prefix("mucker3", flag) || string_prefix("m3", flag)) return LM3 + '0'; if (string_prefix("mage", flag) || string_prefix("W1", flag)) return (tp_multi_wizlevels ? LMAGE : LM3) + '0'; if (string_prefix("wizard", flag) || string_prefix("W2", flag)) return (tp_multi_wizlevels ? LWIZ : LARCH) + '0'; if (string_prefix("archwizard", flag) || string_prefix("W3", flag)) return LARCH + '0'; if (string_prefix("boy", flag) || string_prefix("W4", flag)) return (tp_multi_wizlevels ? LBOY : LARCH) + '0'; if (string_prefix("man", flag) || string_prefix("W5", flag)) return LMAN + '0'; if (string_prefix("mobile", flag) || string_prefix("offer", flag)) return '?'; return 0; }
void set_property_nofetch(dbref object, const char *pname, PData * dat, bool pure) { char buf[BUFFER_LEN]; char *n; PropPtr p; /* Make sure that we are passed a valid property name */ if (!pname) return; while (*pname == PROPDIR_DELIMITER) pname++; strcpy(buf, pname); /* truncate propnames with a ':' in them at the ':' */ if ((n = index(buf, PROP_DELIMITER))) *n = '\0'; /* truncate propnames with a '\n' in them at the '\n' */ if ((n = index(buf, '\n'))) *n = '\0'; if (!*buf) return; if ((!(FLAGS(object) & LISTENER)) && (string_prefix(buf, "_listen") || string_prefix(buf, "~listen") || string_prefix(buf, "@listen") || string_prefix(buf, "_olisten") || string_prefix(buf, "~olisten") || string_prefix(buf, "@olisten") || string_prefix(buf, "_alisten") || string_prefix(buf, "~alisten") || string_prefix(buf, "@alisten") || string_prefix(buf, "_aolisten") || string_prefix(buf, "~aolisten") || string_prefix(buf, "@aolisten"))) { FLAGS(object) |= LISTENER; } if ((!(FLAG2(object) & F2COMMAND)) && (string_prefix(buf, "_command") || string_prefix(buf, "~command") || string_prefix(buf, "@command") || string_prefix(buf, "_ocommand") || string_prefix(buf, "~ocommand") || string_prefix(buf, "@ocommand"))) { FLAG2(object) |= F2COMMAND; } p = propdir_new_elem(&(DBFETCH(object)->properties), buf); /* free up any old values */ clear_propnode(p); SetPFlagsRaw(p, dat->flags); if (PropFlags(p) & PROP_ISUNLOADED) { SetPDataUnion(p, dat->data); return; } switch (PropType(p)) { case PROP_STRTYP: if (!dat->data.str || !*dat->data.str) { SetPType(p, PROP_DIRTYP); SetPDataStr(p, NULL); if (!PropDir(p)) { remove_property_nofetch(object, pname); } } else { #ifdef COMPRESS if (!pure) { if (!(dat->flags & PROP_NOCOMPRESS) && isascii_str(dat->data.str)) { SetPDataStr(p, alloc_compressed(dat->data.str)); } else { dat->flags |= PROP_NOCOMPRESS; SetPDataStr(p, alloc_string(dat->data.str)); } SetPFlagsRaw(p, (dat->flags | PROP_COMPRESSED)); } else #endif SetPDataStr(p, alloc_string(dat->data.str)); } break; case PROP_INTTYP: SetPDataVal(p, dat->data.val); if (!dat->data.val) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_FLTTYP: SetPDataFVal(p, dat->data.fval); if (dat->data.fval == 0.0) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_REFTYP: SetPDataRef(p, dat->data.ref); if (dat->data.ref == NOTHING) { SetPType(p, PROP_DIRTYP); SetPDataRef(p, 0); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_LOKTYP: SetPDataLok(p, dat->data.lok); break; case PROP_DIRTYP: SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(object, pname); break; } }
char power_2char(char *p) { if (string_prefix("ALL_MUF_PRIMS", p)) { return 'm'; } else if (string_prefix("ANNOUNCE", p)) { return 'a'; } else if (string_prefix("BOOT", p)) { return 'b'; } else if (string_prefix("CHOWN_ANYTHING", p)) { return 'c'; } else if (string_prefix("CONTROL_ALL", p)) { return 'r'; } else if (string_prefix("CONTROL_MUF", p)) { return 'f'; } else if (string_prefix("EXPANDED_WHO", p)) { return 'x'; } else if (string_prefix("HIDE", p)) { return 'h'; } else if (string_prefix("IDLE", p)) { return 'i'; } else if (string_prefix("LINK_ANYWHERE", p)) { return 'l'; } else if (string_prefix("LONG_FINGERS", p)) { return 'g'; } else if (string_prefix("NO_PAY", p)) { return 'n'; } else if (string_prefix("OPEN_ANYWHERE", p)) { return 'o'; } else if (string_prefix("PLAYER_CREATE", p)) { return 'p'; } else if (string_prefix("SEARCH", p)) { return 's'; } else if (string_prefix("SEE_ALL", p)) { return 'e'; } else if (string_prefix("SHUTDOWN", p)) { return 'd'; } else if (string_prefix("TELEPORT", p)) { return 't'; } else if (string_prefix("STAFF", p)) { return 'w'; } else { return 0; } }
const char * mfn_select(MFUNARGS) { char origprop[BUFFER_LEN]; char propname[BUFFER_LEN]; char bestname[BUFFER_LEN]; dbref obj = what; dbref bestobj = 0; char *pname; const char *ptr; char *out, *in; int i, targval, bestval; int baselen; int limit; int blessed = 0; pname = argv[1]; if (argc == 3) { obj = mesg_dbref(descr, player, what, perms, argv[2], mesgtyp); } if (obj == PERMDENIED) ABORT_MPI("SELECT", "Permission denied."); if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME) ABORT_MPI("SELECT", "Match failed."); /* * Search contiguously for a bit, looking for a best match. * This allows fast hits on LARGE lists. */ limit = 18; i = targval = atoi(argv[0]); do { ptr = get_list_item(player, obj, perms, (char *)pname, i--, mesgtyp, &blessed); } while (limit-->0 && i >= 0 && ptr && !*ptr); if (ptr == NULL) ABORT_MPI("SELECT", "Failed list read."); if (*ptr != '\0') return ptr; /* * If we didn't find it before, search only existing props. * This gets fast hits on very SPARSE lists. */ /* First, normalize the base propname */ out = origprop; in = argv[1]; while (*in != '\0') { *out++ = PROPDIR_DELIMITER; while (*in == PROPDIR_DELIMITER) in++; while (*in && *in != PROPDIR_DELIMITER) *out++ = *in++; } *out++ = '\0'; i = targval; bestname[0] = '\0'; bestval = 0; baselen = strlen(origprop); for (; obj != NOTHING; obj = getparent(obj)) { pname = next_prop_name(obj, propname, sizeof(propname), origprop); while (pname && string_prefix(pname, origprop)) { ptr = pname + baselen; if (*ptr == NUMBER_TOKEN) ptr++; if (!*ptr && is_propdir(obj, pname)) { char propname2[BUFFER_LEN]; char *pname2; int sublen = strlen(pname); pname2 = strcpyn(propname2, sizeof(propname2), pname); propname2[sublen++] = PROPDIR_DELIMITER; propname2[sublen] = '\0'; pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2); while (pname2) { ptr = pname2 + sublen; if (number(ptr)) { i = atoi(ptr); if (bestval < i && i <= targval) { bestval = i; bestobj = obj; strcpyn(bestname, sizeof(bestname), pname2); } } pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2); } } ptr = pname + baselen; if (number(ptr)) { i = atoi(ptr); if (bestval < i && i <= targval) { bestval = i; bestobj = obj; strcpyn(bestname, sizeof(bestname), pname); } } pname = next_prop_name(obj, propname, sizeof(propname), pname); } } if (*bestname) { ptr = safegetprop_strict(player, bestobj, perms, bestname, mesgtyp, &blessed); if (!ptr) ABORT_MPI("SELECT", "Failed property read."); } else { ptr = ""; } return ptr; }
void SipRedirectorGateway::processForm(const HttpRequestContext& requestContext, const HttpMessage& request, HttpMessage*& response) { UtlString string_get("get"); UtlString string_set("set"); UtlString string_prefix("prefix"); UtlString string_destination("destination"); OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm entered", mLogName.data()); UtlString* user; // Process the request. // Get the body of the request. const HttpBody* request_body = request.getBody(); OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm A *** request body is '%s'", mLogName.data(), request_body->getBytes()); // Get the values from the form. if (request_body->isMultipart()) { // Extract the values from the form data. UtlHashMap values; int c = request_body->getMultipartCount(); for (int i = 0; i < c; i++) { UtlString* name = new UtlString; if (request_body->getMultipart(i)->getPartHeaderValue("name", *name)) { const char* v; int l; request_body->getMultipartBytes(i, &v, &l); // Strip leading and trailing whitespace from values. UtlString* value = new UtlString(v, l); value->strip(UtlString::both); OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::processForm " "form value '%s' = '%s'", mLogName.data(), name->data(), value->data()); // 'name' and 'value' are now owned by 'values'. values.insertKeyAndValue(name, value); } else { // 'name' is not owned by 'values' and we have to delete it. delete name; } } if (values.findValue(&string_get)) { // This is a "get gateway" request. // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } else if (values.findValue(&string_set)) { // This is a "set gateway" request. // Validate the routing prefix. UtlString* prefix = dynamic_cast <UtlString*> (values.findValue(&string_prefix)); if (prefixIsValid(*prefix)) { // Validate the destination. UtlString* destination = dynamic_cast <UtlString*> (values.findValue(&string_destination)); if (destination_is_valid(destination)) { OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::processForm " "add mapping '%s' -> '%s'", mLogName.data(), prefix->data(), destination->data()); mMapLock.acquire(); // Insert the mapping. mMapUserToContacts.insertKeyAndValue(prefix, destination); mMapContactsToUser.insertKeyAndValue(destination, prefix); mMapLock.release(); writeMappings(); } } // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } else { // Incomprehensible request. // Insert the HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } } else { // Incomprehensible request. // Insert the default HTML into the response. HttpBody* response_body = new HttpBody(form, -1, CONTENT_TYPE_TEXT_HTML); response->setBody(response_body); } #if 0 #if 0 // This is quite a chore, because getMultipartBytes gets the entire // multipart section, including the trailing delimiter, rather than just // the body, which is what we need. const char* value; int length; request_body->getMultipartBytes(0, &value, &length); #if 0 OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm A *** seeing '%.*s'", mLogName.data(), length, value); #endif // Advance 'value' over the first \r\n\r\n, which ends the headers. const char* s = strstr(value, "\r\n\r\n"); if (s) { s += 4; // Allow for length of \r\n\r\n. length -= s - value; value = s; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm B *** seeing '%.*s'", mLogName.data(), length, value); #if 0 // Search backward for the last \r, excepting the one in the second-to-last // position, which marks the end of the contents. if (length >= 3) { for (s = value + length - 3; !(s == value || *s == '\r'); s--) { /* empty */ } length = s - value; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm seeing '%.*s'", mLogName.data(), length, value); #endif // Add the mappings. const char* error_msg; int error_location; UtlBoolean success = addMappings(value, length, user, error_msg, error_location); // Construct the response. response = new HttpMessage(); // Send 200 OK reply. response->setResponseFirstHeaderLine(HTTP_PROTOCOL_VERSION, HTTP_OK_CODE, HTTP_OK_TEXT); // Construct the HTML. char buffer1[100]; #if 0 OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm *** domain '%s'", mLogName.data(), Gatewayredirector->mDomainName.data()); #endif if (success) { OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm success user '%s'", mLogName.data(), user->data()); sprintf(buffer1, "<code>sip:<font size=\"+1\">%s</font>@%s:65070</code> redirects to:<br />", user->data(), Gatewayredirector->mDomainName.data()); } else { OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::processForm failure error_msg '%s', error_location %d", mLogName.data(), error_msg, error_location); strcpy(buffer1, "<i>Error:</i>"); } // Transcribe the input value into buffer2. char buffer2[FORM_SIZE]; char* p; int i; if (success) { // An impossible location. error_location = -1; } for (p = buffer2, i = 0; ; i++) { // If this is the error location, insert the error message. if (i == error_location) { *p++ = '!'; *p++ = '-'; *p++ = '-'; strcpy(p, error_msg); p += strlen(error_msg); *p++ = '-'; *p++ = '-'; *p++ = '!'; } // Test for ending the loop after testing to insert the error message, // because the error message may be after the last character. if (i >= length) { break; } switch (value[i]) { case '<': *p++ = '&'; *p++ = 'l'; *p++ = 't'; *p++ = ';'; break; case '>': *p++ = '&'; *p++ = 'g'; *p++ = 't'; *p++ = ';'; break; case '&': *p++ = '&'; *p++ = 'a'; *p++ = 'm'; *p++ = 'p'; *p++ = ';'; break; default: *p++ = value[i]; break; } } *p++ = '\0'; #endif #endif }