Exemple #1
0
void THROW_ParamTypeError(CTX ctx, ksfp_t *sfp, size_t n, kmethodn_t mn, kclass_t reqt, kclass_t cid)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: Type Error: %T.%M(#%d)", cid, mn, (int)n);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname), LOG_i("argument", n), LOG_t("requested_type", reqt), LOG_t("given_type", cid)));
}
Exemple #2
0
void THROW_NoSuchMethod(CTX ctx, ksfp_t *sfp, kclass_t cid, kmethodn_t mn)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: No Such Method: %T.%M", cid, mn);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname)));
}
void knh_makeEvidence(Ctx *ctx, const char *ns, const char *event, int p, const char *fmt, ...)
{
	if(p > LOG_WARNING && !knh_isSystemVerbose()) return;
	va_list ap;
	va_start(ap , fmt);
	if(fmt[0] == '*') {
		char newfmt[512];
		knh_snprintf(newfmt, sizeof(newfmt), K_EVENT_FORMAT "%s", ns, event, fmt+1);
		ctx->share->ebiSPI->vsyslog(p, newfmt, ap);
	}
	else {
		DBG_ASSERT(ctx->bufa != NULL);
		knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf);
		knh_printf(ctx, cwb->w, K_EVENT_FORMAT, ns, event);
		if(ctx->gma != NULL && SP(ctx->gma)->line != 0) {
			knh_write_uline(ctx, cwb->w, SP(ctx->gma)->uri, SP(ctx->gma)->line);
		}
		knh_vprintf(ctx, cwb->w, fmt, ap);
		ctx->share->ebiSPI->syslog(p, knh_cwb_tochar(ctx, cwb));
		knh_cwb_clear(cwb, 0);
	}
	va_end(ap);
	if(p == LOG_EMERG || p == LOG_CRIT) {
#if defined(K_USING_DEBUG)
		DBG_ABORT();
#endif
		knh_exit(ctx, 0);
	}
}
Exemple #4
0
static void ClassOP_man(CTX ctx, knh_OutputStream_t *w, const knh_ClassTBL_t *ct, knh_NameSpace_t *ns)
{
	size_t i, cnt = 0, hasCaption = 0;
	knh_Array_t *a = ct->methods;
	int isBOL = 1;
	char buf[40];
	for(i = 0; i < knh_Array_size(a); i++) {
		knh_Method_t *mtd = a->methods[i];
		char *op = MNOP__(SP(mtd)->mn);
		if(op == NULL) continue;
		if(hasCaption == 0) {
			knh_write_ctext(ctx, w, _("OPERATOR"));
			hasCaption = 1;
		}
		if(isBOL == 1) {
			knh_write_TAB(ctx, w);
			isBOL = 0;
		}
		knh_snprintf(buf, sizeof(buf), "%-14s", op);
		knh_write_ascii(ctx, w, buf);
		if(cnt % 5 == 4) {
			knh_write_EOL(ctx, w);
			isBOL = 1;
		}
		cnt++;
	}
	if(isBOL != 1) {
		knh_write_EOL(ctx, w);
	}
	if(hasCaption == 1) {
		knh_write_EOL(ctx, w);
	}
}
Exemple #5
0
static
void knh_sqlite3_perror(Ctx *ctx, sqlite3 *db, int r)
{
	char *msg = "SQL!!", buf[512];
	if(r == SQLITE_PERM || r == SQLITE_AUTH) {
		msg = "Security!!";
	}
	knh_snprintf(buf, sizeof(buf), "%s: %s", msg, sqlite3_errmsg(db));
	KNH_WARNING(ctx, buf);
}
static void getmessage(int fd, char* path)
{
	char send_buf[BUF_LEN] = {'\0'};
	knh_snprintf(send_buf, BUF_LEN, "GET %s HTTP/1.0\r\n", path);
	send(fd, send_buf, strlen(send_buf), 0);
	knh_snprintf(send_buf, BUF_LEN, "Host: %s:%d\r\n\r\n", UPDATE_HOST, PORT);
	send(fd, send_buf, strlen(send_buf), 0);
	
	if (fd != -1) {
		char buf[BUF_LEN] = {'\0'};
		recv(fd, buf, BUF_LEN, 0);
		char *version_str;
		if ((version_str = strstr(buf, "\r\n\r\nMESSAGE:")) != 0 ){
			version_str += strlen("\r\n\r\nMESSAGE:");
			CHANGE_COLOR(stderr, GREEN);
			fprintf(stderr, "%s", version_str);
			CHANGE_COLOR(stderr, WHITE);
		}
	}
}
void knh_checkSecurityAlert(void)
{
	char path[BUF_LEN] = {'\0'};
	unsigned int clock = getclock();
	unsigned int mem   = getmem();
	int ncpu  = getncpu();
	knh_snprintf(path, 512, UPDATE_PATH,
				 K_DIST, K_VERSION, K_PLATFORM,
				 CPU_NAME, K_REVISION, clock, mem, ncpu);
	DBG_P("Path == [%s] \n", path);
	serverconnect(path);
}
Exemple #8
0
static void knh_setArgs(CTX ctx, Args_t *args, kMap *m)
{
    kDictMap *dmap = knh_toDictMap(ctx, m, 0);
    ksfp_t *lsfp = ctx->esp;
    knitr_t mitrbuf = K_NITR_INIT, *mitr = &mitrbuf;
    klr_setesp(ctx, lsfp+1);
    char buf[256] = {0};
    while(m->spi->next(ctx, m->mapptr, mitr, lsfp)) {
        const char *key = S_totext(lsfp[0].s);
        Object *o = knh_DictMap_getNULL(ctx, dmap, S_tobytes(lsfp[0].s));
        switch (O_cid(o)) {
        case CLASS_Int:
            knh_snprintf(buf, sizeof(buf), "%s=" KINT_FMT, key, N_toint(o));
            break;
        case CLASS_Float:
            knh_snprintf(buf, sizeof(buf), "%s=" KFLOAT_FMT, key, N_tofloat(o));
            break;
        case CLASS_Boolean:
            knh_snprintf(buf, sizeof(buf), "%s=%s",
                         key, N_tobool(o) ? "true" : "false");
            break;
        case CLASS_String:
            knh_snprintf(buf, sizeof(buf), "%s=%s", key, S_totext((kString *)o));
            break;
        default:
            TODO();
            break;
        }
        DBG_P("m[%s] = {class:%s, struct:%s, o:%s}", S_totext(lsfp[0].s),
              CLASS__(O_cid(o)), STRUCT__(O_bcid(o)), O__(o));
        if (knh_strlen(buf) > 0) {
            DBG_P("param: \"%s\"", buf);
            oauth_add_param_to_array(&args->argc, &args->argv, buf);
        }
        buf[0] = '\0';
        klr_setesp(ctx, lsfp+1);
    }
}
Exemple #9
0
static const char* knh_format_w3cdtf(char *buf, size_t bufsiz, struct tm *tmp)
{
	// 2001-08-02T10:45:23+09:00
#if defined(K_USING_WINDOWS_)
	_tzset();
	int gmtoff = (int)(_timezone / (60 * 60));
#else
	int gmtoff = (int)(tmp->tm_gmtoff / (60 * 60));
#endif /* defined(K_USING_WINDOWS_) */
	knh_snprintf(buf, bufsiz, "%04d-%02d-%02dT%02d:%02d:%02d%+02d:%02d",
		(int)(tmp->tm_year + 1900), (int)(tmp->tm_mon + 1), tmp->tm_mday,
		tmp->tm_hour, tmp->tm_min, tmp->tm_sec, gmtoff, 0);
	return (const char*)buf;
}
Exemple #10
0
char *knh_format_utf8(char *buf, size_t bufsiz, kuint_t ucs4)
{
	/* TODO: here, we assume that BOM bigEndian
	 and only 3 bytes or 1 byte UTF
	 */
	kuint_t mask = 0x0;
	kuint_t byte1 = 0x7F;
	kuint_t byte2 = 0x7FF;
	kuint_t byte3 = 0xFFFF;

	char *ret = buf;
	unsigned char utf8[8];
	if (ucs4 <= byte1) {
		/* 7 bits */
		knh_snprintf(buf, bufsiz, "%c", (int)(0xffff & ucs4));
		ret = buf;
	} else if (ucs4 <= byte2) {
		/* cut last 6 bits */
		TODO();
		/* first 5 bits */
	} else if (ucs4 <= byte3) {
		/* cut last 6 bits */
		mask = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3| 1 << 4 | 1 << 5;
		utf8[2] = (unsigned char)(ucs4 & mask);
		utf8[2] = utf8[2] | 1 << 7;
		/* cut next 6 bits */
		ucs4 = ucs4 >> 6;
		utf8[1] = (unsigned char)(ucs4 & mask);
		utf8[1] = utf8[1] | 1 << 7;
		/* first 4 bits */
		mask = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3;
		ucs4 = ucs4 >> 6;
		utf8[0] = (unsigned char)(ucs4 & mask);
		utf8[0] = utf8[0] | 1 << 7 | 1 << 6 | 1 << 5;
		utf8[3] = '\0';
		knh_snprintf(buf, bufsiz, "%s", utf8);
	} else {
Exemple #11
0
static kException* new_Assertion(CTX ctx, kline_t uline)
{
	kException* e = new_(Exception);
	char buf[256] = {'A', 's', 's', 'e', 'r', 't', 'i', 'o', 'n', '!', '!', ':', ' '};
	char *mbuf = buf + 13;
	knh_readuline(ctx, uline, mbuf, sizeof(buf)-13);
	if(mbuf[0] == 0) {
		kuri_t uri = ULINE_uri(uline);
		size_t line = ULINE_line(uline);
		knh_snprintf(buf, sizeof(buf), "Assertion!!: %s at line %lu", FILENAME__(uri), line);
	}
	KNH_SETv(ctx, e->emsg, new_String2(ctx, CLASS_String, (const char*)buf, knh_strlen(buf), SPOL_ASCII));
	e->uline = uline;
	return e;
}
Exemple #12
0
void knh_path_reset(CTX ctx, knh_path_t *ph, const char *scheme, knh_bytes_t t)
{
	knh_index_t idx = knh_bytes_index(t, ':');
	char *buf = P_buf(ph);
	if(t.len + 1 > K_PATHMAX) t.len = K_PATHMAX - 1;
	if(idx > 0 || scheme == NULL) {
		knh_memcpy(buf, t.text, t.len); buf[t.len] = 0;
		ph->pbody = idx + 1;
		ph->plen = t.len;
	}
	else {
		knh_snprintf(buf, K_PATHMAX, "%s:%s", scheme, t.text);
		ph->pbody = knh_strlen(scheme) + 1;
		ph->plen = t.len + ph->pbody;
	}
	DBG_ASSERT(buf[ph->plen] == 0);
	ph->isRealPath = 0;
}
Exemple #13
0
int konoha_main(konoha_t konoha, int argc, const char **argv)
{
	CTX ctx = (CTX)konoha;
	int i, ret = 0, n = knh_parseopt(ctx, argc, argv);
	knh_linkDynamicReadline(ctx);
	knh_linkDynamicRegex(ctx);
	knh_linkDynamicIconv(ctx);
	for (i = 0; konoha_modules[i].init != NULL; ++i) {
		konoha_modules[i].init(argc, n, argv);
	}
	argc = argc - n;
	argv = argv + n;
	if(isActorMode) {
		char portstr[6] = {0};
		knh_snprintf(portstr, sizeof(portstr), "%d", port);
		const char *argv_actor[3] = {"actsrv", portstr, NULL};
		argc = 2;
		argv = argv_actor;
	}
	knh_parsearg(ctx, argc, argv);
	if(argc == 0) {
		ret = konoha_shell(ctx, NULL);
	}
	else if(isMPIMode) {
		kMPI_argv0 = argv[0];
		knh_loadPackage(ctx, STEXT("konoha.mpi"));
		knh_eval(ctx, "using konoha.mpi.*; int main(String[] args) { new TaskScript().exec(MPI.vload()); MPI.vmainloop(); return 0 }", 1, NULL);
		ret = knh_runMain(ctx, argc, argv);
	}
	else {
		if(knh_startScript(ctx, argv[0]) == K_CONTINUE && !knh_isCompileOnly(ctx)) {
			ret = knh_runMain(ctx, argc, argv);
			if(isInteractiveMode) {
				konoha_shell(ctx, NULL);
			}
		}
	}
	for (i = 0; konoha_modules[i].exit != NULL; ++i) {
		konoha_modules[i].exit();
	}
	return ret;
}
Exemple #14
0
void knh_Stmt_toERR(Ctx *ctx, Stmt *stmt, Term *tm)
{
    if(SP(stmt)->stt == STT_ERR) return;
    SP(stmt)->stt = STT_ERR;
    knh_uri_t uri = 0;
    int line = 0;
    if(IS_Token(tm)) {
        uri =  SP((Token*)tm)->uri;
        line =  SP((Token*)tm)->line;
    }
    else if(IS_Stmt(tm)) {
        uri =  SP((Stmt*)tm)->uri;
        line =  SP((Stmt*)tm)->line;
    }
    {
        char buf[256];
        knh_snprintf(buf, sizeof(buf), "Script!!: running errors at %s:%d", URIDN(SP(stmt)->uri), SP(stmt)->line);
        KNH_SETv(ctx, DP(stmt)->errMsg, new_String(ctx, B(buf), NULL));
        KNH_SETv(ctx, DP(stmt)->next, KNH_NULL);
    }
}
Exemple #15
0
int konoha_main(konoha_t konoha, int argc, const char **argv)
{
	CTX ctx = (CTX)konoha;
	int i, ret = 0, n = knh_parseopt(ctx, argc, argv);
	knh_linkDynamicReadline(ctx);
	knh_linkDynamicRegex(ctx);
	knh_linkDynamicIconv(ctx);
	for (i = 0; konoha_modules[i].init != NULL; ++i) {
		konoha_modules[i].init(argc, n, argv);
	}
	argc = argc - n;
	argv = argv + n;
	if(isActorMode) {
		char portstr[6] = {0};
		knh_snprintf(portstr, sizeof(portstr), "%d", port);
		const char *argv_actor[3] = {"actsrv", portstr, NULL};
		argc = 2;
		argv = argv_actor;
	}
	knh_parsearg(ctx, argc, argv);
	if(argc == 0) {
		ret = konoha_shell(ctx, NULL);
	}
	else {
		if(knh_startScript(ctx, argv[0]) == K_CONTINUE && !knh_isCompileOnly(ctx)) {
			ret = knh_runMain(ctx, argc, argv);
			if(isInteractiveMode) {
				konoha_shell(ctx, NULL);
			}
		}
	}
	for (i = 0; konoha_modules[i].exit != NULL; ++i) {
		konoha_modules[i].exit();
	}
	return ret;
}
void knh_write_ffmt(Ctx *ctx, knh_OutputStream_t *w, const char *fmt, knh_float_t n)
{
	char buf[K_FLOAT_FMTSIZ];
	knh_snprintf(buf, sizeof(buf), fmt, n);
	knh_write(ctx, w, B(buf));
}
void knh_write_dfmt(Ctx *ctx, knh_OutputStream_t *w, const char *fmt, knh_intptr_t n)
{
	char buf[K_INT_FMTSIZ];
	knh_snprintf(buf, sizeof(buf), fmt, n);
	knh_write(ctx, w, B(buf));
}
void knh_write__p(Ctx *ctx, knh_OutputStream_t *w, void *ptr)
{
	char buf[K_INT_FMTSIZ];
	knh_snprintf(buf, sizeof(buf), "%p", ptr);
	knh_write(ctx, w, B(buf));
}
Exemple #19
0
static void setkonohainfo(knh_sysinfo_t *sysinfo)
{
	static char options[512] = {0};
	static char date[40] = {0};
	char *p = options;
	sysinfo->konoha_type = K_PROGNAME;
	sysinfo->konoha_codename = K_CODENAME;
	sysinfo->konoha_version = K_VERSION;
	sysinfo->konoha_disttype = K_DISTTYPE;
	sysinfo->konoha_disturl  = K_DISTURL;
	sysinfo->konoha_major_version = K_MAJOR_VERSION;
	sysinfo->konoha_minor_version = K_MINOR_VERSION;
	sysinfo->konoha_patch_version = K_PATCH_VERSION;
#if defined(K_PATCH_LEVEL)
	sysinfo->konoha_patch_level = K_PATCH_LEVEL;
#elif defined(K_REVISION)
	sysinfo->konoha_patch_level = K_REVISION;
#endif
	sysinfo->konoha_cc = CC_TYPE;
	knh_snprintf(date, sizeof(date), "%s %s", __DATE__, __TIME__);
	sysinfo->konoha_builtdate = date;
	sysinfo->konoha_config = CC_PLATFORM;
	sysinfo->konoha_disttype = K_DISTTYPE;
	sysinfo->konoha_disturl = K_DISTURL;
	sysinfo->konoha_systembits = (sizeof(void*) * 8);
	sysinfo->konoha_options = (const char*)options;
	/* THESE OPTIONS MUST BE ORDERED ALPHABETICALLY */
#if defined(K_USING_FASTEST)
	APPEND_OPTION(p, "fastest");
#endif
#if defined(K_USING_ICONV)
	APPEND_OPTION(p, "iconv");
#endif
#if defined(K_USING_INT32)
	APPEND_OPTION(p, "int32");
#endif
//#if defined(K_USING_PREFETCH)
//	APPEND_OPTION(p, "prefetch");
//#endif
//#if defined(K_USING_READLINE)
//	APPEND_OPTION(p, "readline");
//#endif
#if defined(K_USING_RCGC)
	APPEND_OPTION(p, "rcgc");
#elif defined(K_USING_BMGC)
#if defined(K_USING_GENGC)
	APPEND_OPTION(p, "gen-bmgc");
#else
	APPEND_OPTION(p, "bmgc");
#endif
#else
	APPEND_OPTION(p, "msgc");
#endif
#if defined(K_USING_THCODE_)
	APPEND_OPTION(p, "thcode");
#else
	APPEND_OPTION(p, "switch");
#endif
#if defined(K_USING_SQLITE3)
	APPEND_OPTION(p, "sqlite3");
#endif
#if defined(K_USING_SYSLOG)
	APPEND_OPTION(p, "syslog");
#endif
#if defined(K_USING_THREAD)
	APPEND_OPTION(p, "thread");
#endif
#if defined(K_CONFIG_OS)
	if(sysinfo->kern_ostype == NULL) sysinfo->kern_ostype = K_CONFIG_OS;
#endif
}
Exemple #20
0
static char *knh_locale_charset(void)
{
	static char codepage[64];
	knh_snprintf(codepage, sizeof(codepage), "CP%d", (int)GetACP());
	return codepage;
}