Esempio n. 1
0
File: uri.c Progetto: lb1a/avfs
/* Escapes the abspath segment of a URI.
 * Returns ne_malloc-allocated string.
 */
char *uri_abspath_escape(const char *abs_path) 
{
    const char *pnt;
    char *ret, *retpos;
    int count = 0;
    for (pnt = abs_path; *pnt != '\0'; pnt++) {
	if (ESCAPE(*pnt)) {
	    count++;
	}
    }
    if (count == 0) {
	return ne_strdup(abs_path);
    }
    /* An escaped character is "%xx", i.e., two MORE
     * characters than the original string */
    retpos = ret = ne_malloc(strlen(abs_path) + 2*count + 1);
    for (pnt = abs_path; *pnt != '\0'; pnt++) {
	if (ESCAPE(*pnt)) {
	    /* Escape it - %<hex><hex> */
	    sprintf(retpos, "%%%02x", (unsigned char) *pnt);
	    retpos += 3;
	} else {
	    /* It's cool */
	    *retpos++ = *pnt;
	}
    }
    *retpos = '\0';
    return ret;
}
Esempio n. 2
0
static void
readstring(FILE *fp, char *buf, const char *str)
{
    int last, c;
    /* What is the advantage of setitimer() over alarm()? */
    struct itimerval it;

    signal(SIGALRM, resize_timeout);
    memset((char *) &it, 0, sizeof(struct itimerval));
    it.it_value.tv_sec = TIMEOUT;
    setitimer(ITIMER_REAL, &it, (struct itimerval *) NULL);
    if ((c = getc(fp)) == 0233) {	/* meta-escape, CSI */
	c = ESCAPE("")[0];
	*buf++ = (char) c;
	*buf++ = '[';
    } else {
	*buf++ = (char) c;
    }
    if (c != *str) {
	fprintf(stderr, "%s: unknown character, exiting.\r\n", myname);
	onintr(0);
    }
    last = str[strlen(str) - 1];
    while ((*buf++ = (char) getc(fp)) != last) {
	;
    }
    memset((char *) &it, 0, sizeof(struct itimerval));
    setitimer(ITIMER_REAL, &it, (struct itimerval *) NULL);
    *buf = 0;
}
Esempio n. 3
0
/**
 * virSystemdEscapeName:
 *
 * This function escapes various characters in @name and appends that
 * escaped string to @buf, in order to comply with the requirements
 * from systemd/machined.  Parameter @full_escape decides whether to
 * also escape dot as a first character and '-'.
 */
static void virSystemdEscapeName(virBufferPtr buf,
                                 const char *name,
                                 bool full_escape)
{
    static const char hextable[16] = "0123456789abcdef";

#define ESCAPE(c)                                                       \
    do {                                                                \
        virBufferAddChar(buf, '\\');                                    \
        virBufferAddChar(buf, 'x');                                     \
        virBufferAddChar(buf, hextable[(c >> 4) & 15]);                 \
        virBufferAddChar(buf, hextable[c & 15]);                        \
    } while (0)

#define VALID_CHARS                             \
        "0123456789"                            \
        "abcdefghijklmnopqrstuvwxyz"            \
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            \
        ":-_.\\"

    if (full_escape && *name == '.') {
        ESCAPE(*name);
        name++;
    }

    while (*name) {
        if (*name == '/')
            virBufferAddChar(buf, '-');
        else if ((full_escape && *name == '-') ||
                 *name == '\\' ||
                 !strchr(VALID_CHARS, *name))
            ESCAPE(*name);
        else
            virBufferAddChar(buf, *name);
        name++;
    }

#undef ESCAPE
#undef VALID_CHARS
}
Esempio n. 4
0
 bool JstrChecker::IS_STRING(const wstring &str, wstring &strvl) {
     if (str.front() != JsonSymbol::STRING_BOUND || str.back() != JsonSymbol::STRING_BOUND) return false;
     strvl = L"";
     for (size_t i = 1; i < str.size() - 1; i++) {
         if (str[i] == JsonSymbol::ESCAPE_SYM) {
             if (i == str.size() - 2) return false;
             strvl.push_back(ESCAPE(str[i + 1]));
             i++;
         } else if (str[i] == JsonSymbol::STRING_BOUND) {
             return false;
         } else {
             strvl.push_back(str[i]);
         }
     }
     return true;
 }
Esempio n. 5
0
    { "bash",	SHELL_BOURNE }, /* GNU Bourne again shell */
    { "jsh",    SHELL_BOURNE },
    { NULL,	SHELL_BOURNE }	/* default (same as xterm's) */
};
/* *INDENT-ON* */

char *emuname[EMULATIONS] =
{
    "VT100",
    "Sun",
};
char *myname;
int shell_type = SHELL_UNKNOWN;
char *getsize[EMULATIONS] =
{
    ESCAPE("7") ESCAPE("[r") ESCAPE("[999;999H") ESCAPE("[6n"),
    ESCAPE("[18t"),
};
#if defined(USE_STRUCT_TTYSIZE)
#elif defined(USE_STRUCT_WINSIZE)
char *getwsize[EMULATIONS] =
{				/* size in pixels */
    0,
    ESCAPE("[14t"),
};
#endif /* USE_STRUCT_{TTYSIZE|WINSIZE} */
char *restore[EMULATIONS] =
{
    ESCAPE("8"),
    0,
};
Esempio n. 6
0
Tab* spellsTab(const char* tabId, const char* tabTitle, ItrPair<Spell>& spells,
	bool haveSkillName)
{
	gNpcTrainers.load();
	gSpellIcons.load();
	gSkillLines.load();
	SkillLineAbilityIndex::load();

	tabTableChtml& t = *new tabTableChtml();
	t.id = tabId;
	t.title = tabTitle;
	t.columns.push_back(Column(ICON, "Icon/item", Column::NoEscape));
	t.columns.push_back(Column(NAME, "Name", Column::NoEscape));
	t.columns.push_back(Column(REAGENTS, "Reagents", Column::NoEscape));
	t.columns.push_back(Column(SOURCE, "Source", Column::NoEscape));
	t.columns.push_back(Column(SKILL, "Skill", Column::NoEscape));

	// it's expensive to construct this object. let's keep one instance.
	std::ostringstream stream;

	while(spells.hasNext()) {
		const Spell& s(spells.next());
		const Spell::Effect& e(s.effect[0]);
		const Quality* itemQuality = NULL;
		Row r;
		r[ENTRY] = toString(s.id);

		// ICON
		stream.str("");
		if(e.itemType) {
			itemQuality = streamMultiItem(stream, e.itemType, e.basePoints + e.dieSides);
		} else {
			const SpellIcon* si = gSpellIcons.find(s.spellIconID);
			if(si) {
				stream <<"<img src=\"";
				ESCAPE_URL(getIconRaw(si->icon));
				stream <<"\" alt=\"";
				ESCAPE(si->icon);
				stream <<"\">";
			} else if(s.spellIconID != 0) {
				stream << "Warning: invalid icon id ("<<s.spellIconID<<")";
			}
		}
		r[ICON] = stream.str();

		// NAME
		stream.str("");
		stream <<"<a href=\"spell="<<s.id<<"\">";
		if(itemQuality) {
			stream <<"<span style=\"color:#"<<itemQuality->color<<";\">";
		}
		ESCAPE(s.name);
		if(s.rank) if(s.rank[0]) {
			stream <<" ("<<s.rank<<")";
		}
		if(itemQuality) {
			stream <<"</span>";
		}
		stream <<"</a>";
		r[NAME] = stream.str();

		// REAGENTS
		stream.str("");
		for(size_t i=0; i<ARRAY_SIZE(s.reagent); i++) {
			const Spell::Reagent& re(s.reagent[i]);
			streamMultiItem(stream, re.id, re.count);
		}
		r[REAGENTS] = stream.str();

		// SOURCE
		stream.str("");
		int requiredSkillLevel = streamSource(stream, s.id);
		r[SOURCE] = stream.str();

		// SKILL
		stream.str("");
		auto slas = SkillLineAbilityIndex::findSpell(s.id);
		for(; slas.first != slas.second; ++slas.first) {
			const SkillLineAbility* sla = slas.first->second;
			stream << "<!--";
			if(haveSkillName) {
				stream << gSkillLines[sla->skill].name;
			}
			{
				char buf[32];
				sprintf(buf, "%04i", sla->minValue);
				stream <<buf<<"-->";
			}
			if(haveSkillName) {
				stream <<"<a href=\"spells="<<sla->skill<<"\">"<<gSkillLines[sla->skill].name<<"</a>\n";
			}
			if(requiredSkillLevel >= 0) {
				stream <<"<span class=\"skillRed\">"<<requiredSkillLevel<<"</span>\n";
			}
			stream <<"<span class=\"skillYellow\">"<<sla->minValue<<"</span>\n";
			stream <<"<span class=\"skillGreen\">"<<
				(sla->maxValue - (sla->maxValue - sla->minValue) / 2)<<"</span>\n";
			stream <<"<span class=\"skillGray\">"<<sla->maxValue<<"</span>\n";
		}
		r[SKILL] = stream.str();

		t.array.push_back(r);
	}
	t.count = t.array.size();
	return &t;
}
Esempio n. 7
0
/*
 * This function invokes /usr/bin/prodreg register, using
 * pfexec in order to gain the required authorizations
 * needed to modify the registry.
 *
 * Syntax:
 *
 * prodreg register -u uuid
 *   [-b backward-compatible-version ] *
 *   [-c child-uuid '{' instance# '}' '{' version '}'] *
 *   [-d dependent-uuid '{' instance# '}' '{' version '}'] *
 *   [-D attribute '{' value '}' ] *
 *   [-n display-name '{' language-tag '}' ] *
 *   [-p location ]
 *   [-P parent-uuid '{' instance# '}' '{' version '}']
 *   [-r required-uuid '{' instance# '}' '{' version '}'] *
 *   [-R alt_root ]
 *   [-t (PRODUCT | FEATURE | COMPONENT) ] ----> default: COMPONENT
 *   [-U unique-name ]
 *   [-v prod-version ]
 *   [-V vendor-string ]
 *   [-x uninstaller-command ]
 *
 * Anything with a '*' can appear more than once in the command line.
 * Other options can only appear zero or one time.  The -u uuid option
 * *MUST* be present.
 *
 */
int
_private_prodreg_register(Wsreg_component *comp)
{

	int		i;
	char		*argv[1024];
	int		argc = 0;
	char		**tmpp;
	char		*tmp;
	Wsreg_component	**tmpc;
	char		buf[MAXPATHLEN];

	if (access(PRODREG_CLI, X_OK) != 0) {
		/* can't find prodreg */
		return (1);
	}

	/* form arguments to prodreg */
	argv[argc++] = RBAC_CLI;
	argv[argc++] = PRODREG_CLI;
	argv[argc++] = "register";
	argv[argc++] = "-u";
	argv[argc++] = wsreg_get_id(comp);

	/* backwards compatible versions */
	for (tmpp = wsreg_get_compatible_versions(comp);
		(tmpp != NULL) && (*tmpp != NULL);
		tmpp++) {
		argv[argc++] = "-b";
		argv[argc++] = *tmpp;
	}

	/* parent */
	if (wsreg_get_parent(comp) != NULL) {
		argv[argc++] = "-P";
		(void) snprintf(buf, MAXPATHLEN, "%s{%d}{%s}",
		    ESCAPE(wsreg_get_id(wsreg_get_parent(comp))),
		    wsreg_get_instance(wsreg_get_parent(comp)),
		    ESCAPE(wsreg_get_version(wsreg_get_parent(comp))));
		argv[argc++] = strdup(buf);
	}

	/* children */
	for (tmpc = wsreg_get_child_components(comp);
		(tmpc != NULL) && (*tmpc != NULL);
		tmpc++) {
		argv[argc++] = "-c";
		(void) snprintf(buf, MAXPATHLEN, "%s{%d}{%s}",
		    ESCAPE(wsreg_get_id(*tmpc)),
		    wsreg_get_instance(*tmpc),
		    ESCAPE(wsreg_get_version(*tmpc)));
		argv[argc++] = strdup(buf);
	}

	/* dependents */
	for (tmpc = wsreg_get_dependent_components(comp);
		(tmpc != NULL) && (*tmpc != NULL);
		tmpc++) {
		argv[argc++] = "-d";
		(void) snprintf(buf, MAXPATHLEN, "%s{%d}{%s}",
		    ESCAPE(wsreg_get_id(*tmpc)),
		    wsreg_get_instance(*tmpc),
		    ESCAPE(wsreg_get_version(*tmpc)));
		argv[argc++] = strdup(buf);
	}

	/* requirements */
	for (tmpc = wsreg_get_required_components(comp);
		(tmpc != NULL) && (*tmpc != NULL);
		tmpc++) {
		argv[argc++] = "-r";
		(void) snprintf(buf, MAXPATHLEN, "%s{%d}{%s}",
		    ESCAPE(wsreg_get_id(*tmpc)),
		    wsreg_get_instance(*tmpc),
		    ESCAPE(wsreg_get_version(*tmpc)));
		argv[argc++] = strdup(buf);
	}

	/* attributes */
	if ((tmpp = wsreg_get_data_pairs(comp)) != NULL) {
		while (*tmpp != NULL)  {
			argv[argc++] = "-D";
			(void) snprintf(buf, MAXPATHLEN, "%s{%s}",
			    ESCAPE(*tmpp), ESCAPE(*(tmpp + 1)));
			argv[argc++] = strdup(buf);
			tmpp += 2;
		}
	}

	/* display name */
	for (tmpp = wsreg_get_display_languages(comp);
		(tmpp != NULL) && (*tmpp != NULL);
		tmpp++) {
		argv[argc++] = "-n";
		(void) snprintf(buf, MAXPATHLEN, "%s{%s}",
		    ESCAPE(wsreg_get_display_name(comp, *tmpp)),
		    ESCAPE(*tmpp));
		argv[argc++] = strdup(buf);
	}

	/* location */
	if ((tmp = wsreg_get_location(comp)) != NULL) {
		argv[argc++] = "-p";
		argv[argc++] = tmp;
	}

	/* alt root */
	if (((tmp = wsreg_get_alternate_root()) != NULL) &&
	    (strlen(tmp) > 0)) {
		argv[argc++] = "-R";
		argv[argc++] = tmp;
	}

	/* type */
	switch (wsreg_get_type(comp)) {
	case WSREG_PRODUCT:
		argv[argc++] = "-t";
		argv[argc++] = "PRODUCT";
		break;
	case WSREG_FEATURE:
		argv[argc++] = "-t";
		argv[argc++] = "FEATURE";
		break;
	case WSREG_COMPONENT:
		/* the default is COMPONENT so we need not repeat it */
		break;
	}

	/* unique name */
	if ((tmp = wsreg_get_unique_name(comp)) != NULL) {
		argv[argc++] = "-U";
		argv[argc++] = tmp;
	}

	/* version */
	if ((tmp = wsreg_get_version(comp)) != NULL) {
		argv[argc++] = "-v";
		argv[argc++] = tmp;
	}

	/* vendor string */
	if ((tmp = wsreg_get_vendor(comp)) != NULL) {
		argv[argc++] = "-V";
		argv[argc++] = tmp;
	}

	/* uninstaller */
	if ((tmp = wsreg_get_uninstaller(comp)) != NULL) {
		argv[argc++] = "-x";
		argv[argc++] = tmp;
	}

	/* terminate argument array */
	argv[argc++] = NULL;

	/*
	 * Since we must return values following the libwsreg
	 * convention (0 indicates failure, nonzero success),
	 * we must reverse the results returned by prodreg
	 * which follows the Unix command line convention of
	 * 0 indicates success and nonzero means failure.
	 */
	i = _private_exec(argv);
	if (i == 0)
		i = 1;
	else
		i = 0;

	return (i);
}
Esempio n. 8
0
    { "dash",	SHELL_BOURNE },
    { "jsh",    SHELL_BOURNE },
    { "ksh",	SHELL_BOURNE }, /* Korn shell (from AT&T toolchest) */
    { "ksh-i",	SHELL_BOURNE }, /* another name for Korn shell */
    { "ksh93",	SHELL_BOURNE }, /* Korn shell */
    { "mksh",   SHELL_BOURNE },
    { "pdksh",  SHELL_BOURNE },
    { "zsh",    SHELL_BOURNE },
    { NULL,	SHELL_BOURNE }	/* default (same as xterm's) */
};
/* *INDENT-ON* */

static char *myname;
static int shell_type = SHELL_UNKNOWN;
static const char *getsize =
    ESCAPE("7") ESCAPE("[r") ESCAPE("[999;999H") ESCAPE("[6n");
static const char *restore =
    ESCAPE("8");
static const char *setname = "";

static struct termios tioorig;

static const char *size =
    ESCAPE("[%d;%dR");

static int tty;
static FILE *ttyfp;

static void
failed(const char *s)
{