예제 #1
0
파일: umui.c 프로젝트: BackupGGCode/faceaip
static void formAddAccessLimit(webs_t wp, char_t *path, char_t *query)
{
	char_t			*url, *method, *group, *secure, *ok;
	int				nCheck;
	accessMeth_t	am;
	short			nSecure;

	a_assert(wp);

	url = websGetVar(wp, T("url"), T("")); 
	group = websGetVar(wp, T("group"), T("")); 
	method = websGetVar(wp, T("method"), T("")); 
	secure = websGetVar(wp, T("secure"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add Access Limit Cancelled."));
	} else if ((url == NULL) || (*url == 0)) {
		websWrite(wp, T("ERROR:  No URL was entered."));
	} else if (umAccessLimitExists(url)) {
		websWrite(wp, T("ERROR:  An Access Limit for [%s] already exists."),
			url);
	} else {
		if (method && *method) {
			am = (accessMeth_t) gatoi(method);
		} else {
			am = AM_FULL;
		}

		if (secure && *secure) {
			nSecure = (short) gatoi(secure);
		} else {
			nSecure = 0;
		}

		nCheck = umAddAccessLimit(url, am, nSecure, group);
		if (nCheck != 0) {
			websWrite(wp, T("Unable to add Access Limit for [%s]"),	url);
		} else {
			websWrite(wp, T("Access limit for [%s], was successfully added."),
				url);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
예제 #2
0
static int evalCond(ej_t *ep, char_t *lhs, int rel, char_t *rhs)
{
	char_t	buf[16];
	int		l, r, lval;

	a_assert(lhs);
	a_assert(rhs);
	a_assert(rel > 0);

	lval = 0;
	if (gisdigit((int)*lhs) && gisdigit((int)*rhs)) {
		l = gatoi(lhs);
		r = gatoi(rhs);
		switch (rel) {
		case COND_AND:
			lval = l && r;
			break;
		case COND_OR:
			lval = l || r;
			break;
		default:
			ejError(ep, T("Bad operator %d"), rel);
			return -1;
		}
	} else {
		if (!gisdigit((int)*lhs)) {
			ejError(ep, T("Conditional must be numeric"), lhs);
		} else {
			ejError(ep, T("Conditional must be numeric"), rhs);
		}
	}

	stritoa(lval, buf, sizeof(buf));
	setString(B_L, &ep->result, buf);
	return 0;
}
예제 #3
0
파일: umui.c 프로젝트: BackupGGCode/faceaip
static void formAddGroup(webs_t wp, char_t *path, char_t *query)
{
	char_t			*group, *enabled, *privilege, *method, *ok, *pChar;
	int				nCheck;
	short			priv;
	accessMeth_t	am;
	bool_t			bDisable;

	a_assert(wp);

	group = websGetVar(wp, T("group"), T("")); 
	method = websGetVar(wp, T("method"), T("")); 
	enabled = websGetVar(wp, T("enabled"), T("")); 
	privilege = websGetVar(wp, T("privilege"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add Group Cancelled."));
	} else if ((group == NULL) || (*group == 0)) {
		websWrite(wp, T("No Group Name was entered."));
	} else if (umGroupExists(group)) {
		websWrite(wp, T("ERROR: Group, \"%s\" already exists."), group);
	} else {
		if (privilege && *privilege) {
/*
 *			privilege is a mulitple <SELECT> var, and must be parsed.
 *			Values for these variables are space delimited.
 */
			priv = 0;
			for (pChar = privilege; *pChar; pChar++) {
				if (*pChar == ' ') {
					*pChar = '\0';
					priv |= gatoi(privilege);
					*pChar = ' ';
					privilege = pChar + 1;
				}
			}
			priv |= gatoi(privilege);
		} else {
			priv = 0;
		}

		if (method && *method) {
			am = (accessMeth_t) gatoi(method);
		} else {
			am = AM_FULL;
		}

		if (enabled && *enabled && (gstrcmp(enabled, T("on")) == 0)) {
			bDisable = FALSE;
		} else {
			bDisable = TRUE;
		}

		nCheck = umAddGroup(group, priv, am, 0, bDisable);
		if (nCheck != 0) {
			websWrite(wp, T("Unable to add group, \"%s\", code: %d "),
				group, nCheck);
		} else {
			websWrite(wp, T("Group, \"%s\" was successfully added."), 
				group);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
예제 #4
0
static int evalExpr(ej_t *ep, char_t *lhs, int rel, char_t *rhs)
{
	char_t	*cp, buf[16];
	int		numeric, l, r, lval;

	a_assert(lhs);
	a_assert(rhs);
	a_assert(rel > 0);

/*
 *	All of the characters in the lhs and rhs must be numeric
 */
	numeric = 1;
	for (cp = lhs; *cp; cp++) {
		if (!gisdigit((int)*cp)) {
			numeric = 0;
			break;
		}
	}

	if (numeric) {
		for (cp = rhs; *cp; cp++) {
			if (!gisdigit((int)*cp)) {
				numeric = 0;
				break;
			}
		}
	}

	if (numeric) {
		l = gatoi(lhs);
		r = gatoi(rhs);
		switch (rel) {
		case EXPR_PLUS:
			lval = l + r;
			break;
		case EXPR_INC:
			lval = l + 1;
			break;
		case EXPR_MINUS:
			lval = l - r;
			break;
		case EXPR_DEC:
			lval = l - 1;
			break;
		case EXPR_MUL:
			lval = l * r;
			break;
		case EXPR_DIV:
			if (r != 0) {
				lval = l / r;
			} else {
				lval = 0;
			}
			break;
		case EXPR_MOD:
			if (r != 0) {
				lval = l % r;
			} else {
				lval = 0;
			}
			break;
		case EXPR_LSHIFT:
			lval = l << r;
			break;
		case EXPR_RSHIFT:
			lval = l >> r;
			break;
		case EXPR_EQ:
			lval = l == r;
			break;
		case EXPR_NOTEQ:
			lval = l != r;
			break;
		case EXPR_LESS:
			lval = (l < r) ? 1 : 0;
			break;
		case EXPR_LESSEQ:
			lval = (l <= r) ? 1 : 0;
			break;
		case EXPR_GREATER:
			lval = (l > r) ? 1 : 0;
			break;
		case EXPR_GREATEREQ:
			lval = (l >= r) ? 1 : 0;
			break;
		case EXPR_BOOL_COMP:
			lval = (r == 0) ? 1 : 0;
			break;
		default:
			ejError(ep, T("Bad operator %d"), rel);
			return -1;
		}

	} else {
		switch (rel) {
예제 #5
0
파일: misc.c 프로젝트: hiciu/ekg2
int irc_parse_line(session_t *s, const char *l)
{
	static GString *strbuf = NULL;
	irc_private_t *j = s->priv;
	int	i, c=0, ecode, n_params;
	char	*p, *cmd, *colon2, **args = NULL, **pfxcmd = NULL;

	gchar *buf;
	int	len;

	if (G_UNLIKELY(!strbuf))
		strbuf = g_string_new(l);
	else
		g_string_assign(strbuf, l);

	irc_convert_in(j, strbuf);
	buf = strbuf->str;
	len = strbuf->len;

	query_emit(NULL, "irc-parse-line", &s->uid, &buf);

	p=buf;
	if(!p)
		return -1;
/*
Each IRC message may consist of up to three main parts: the prefix
(optional), the command, and the command parameters (of which there
may be up to 15).  The prefix, command, and all parameters are
separated by one (or more) ASCII space character(s) (0x20).

The presence of a prefix is indicated with a single leading ASCII
colon character (':', 0x3b), which must be the first character of the
message itself.  There must be no gap (whitespace) between the colon
and the prefix.
*/
	/* GiM: In fact this is probably not needed, but just in case...  */
	for (i=0; i<len; i++) if (buf[i]=='\n' || buf[i]=='\r') buf[i]='\0';

	if ((colon2=xstrstr(p, " :")))
		*colon2 = '\0';

	args = array_make(OMITCOLON(p), " ", 0, 1, 0);

	if (colon2) {
		*colon2 = ' ';
		array_add(&args, xstrdup(colon2+2));
	}

#define prefix pfxcmd[0]
#define pfx_nick pfxcmd[1]
#define pfx_ihost pfxcmd[2]
#define cmdname pfxcmd[3]

	/* prefix is optional... */
	if (':' != *buf) {
		array_add(&pfxcmd, g_strdup(""));	// prefix
		array_add(&pfxcmd, g_strdup(""));	// pfx_nick
		array_add(&pfxcmd, g_strdup(""));	// pfx_ihost
	} else {
		array_add(&pfxcmd, array_shift(&args));						// prefix
		p = xstrchr(pfxcmd[0], '!');
		array_add(&pfxcmd, p ? g_strndup(pfxcmd[0], p-pfxcmd[0]) : g_strdup(""));	// pfx_nick
		array_add(&pfxcmd, p ? g_strdup(p+1) : g_strdup(""));				// pfx_ihost
	}

	cmd = array_shift(&args);
	array_add(&pfxcmd, cmd);		// cmdname

	/* debug only nasty hack ;> */
#ifdef GDEBUG
	/* mg: well, it's not the exact data sent, but color is needed indeed */
	i=0;
	if (*pfxcmd[0]) debug_iorecv("[%s]", pfxcmd[0]);
	debug_iorecv("[%s]", cmd);
	while (args[i] != NULL) debug_iorecv("[%s]",args[i++]);
	debug_iorecv("\n");
#endif

	n_params = g_strv_length(args);
	if (xstrlen(cmd) > 1) {
		if(!gatoi(cmd, &ecode)) {
			/* for scripts */
			char *emitname = saprintf("irc-protocol-numeric %s", cmd);
			if ((query_emit(NULL, "irc-protocol-numeric", &s->uid, &ecode, &args) == -1) ||
			    (query_emit(NULL, emitname, &s->uid, &args) == -1))
			{
				xfree(emitname);
				g_strfreev(pfxcmd);
				g_strfreev(args);
				return -1;
			}
			xfree(emitname);

			c=0;
			while(irccommands[c].type != -1) {
				if (irccommands[c].type == 1 && irccommands[c].num == ecode) {
					if (irccommands[c].min_params > n_params) {
						debug_error("[irc] parse_line() Not enough parameters! cmd=%s, n=%d, min=%d\n",
								cmd, n_params, irccommands[c].min_params);
					} else
					/* I'm sending c not ecode!!!! */
					if ((*(irccommands[c].handler))(s, j, c, pfxcmd, args) == -1 ) {
						debug_error("[irc] parse_line() error while executing handler!\n");
					}
					/* GiM: XXX I don't expect more,
					 * then one handler on list... */
					break;
				}
				c++;
			}
#ifdef GDEBUG
			if (irccommands[c].type == -1) {
				debug("trying default handler\n");
				if ((*(irccommands[0].handler))(s, j, 0, pfxcmd, args) == -1 ) {
					debug("[irc] parse_line() error while executing handler!\n");
				}

			}
#endif
		} else {
			c=0;
			while(irccommands[c].type != -1) {
				if (irccommands[c].type == 0 && !xstrcmp(irccommands[c].comm, cmd)) {
					if (irccommands[c].min_params > n_params) {
						debug_error("[irc] parse_line() Not enough parameters! cmd=%s, n=%d, min=%d\n",
								cmd, n_params, irccommands[c].min_params);
					} else
					/* dj: instead of  ecode,    c; */
					if ((*(irccommands[c].handler))(s, j, c, pfxcmd, args) == -1 ) {
						debug_error("[irc] parse_line() error while executing handler!\n");
					}
					break;
				}
				c++;
			}
		}
	}

	g_strfreev(pfxcmd);
	g_strfreev(args);
	return 0;
}