Example #1
0
int
printseclastmark(FILE * fp, const struct sectree *sec, int nline)
{
	int count, i, j, n, m, l, pcount;
	bzero(boardlist, sizeof (boardlist));
	count = makeboardlist(sec, boardlist, MAXBOARD);
	fakesort(boardlist, count);
	fprintf(fp, "btb('%s', '%s');", sec->basestr, scriptstr(sec->title));
	for (i = 0, n = 0, pcount = 0; i < NBRDITEM && n < nline; i++) {
		for (j = 0; j < count && n < nline; j++) {
			m = boardlist[j].brdn;
			if (lastmarklist[m].count <= i)
				continue;
			//printlastmarkline(fp, &lastmarklist[m], i);
			n++;
			if (i == 0)
				pcount++;
			boardlist[j].used++;
		}
	}
	if (strlen(sec->basestr) >= 2) {
		for (i = 0; i < count; i++) {
			m = boardlist[i].brdn;
			if (lastmarklist[m].count && !boardlist[i].used) {
				boardlist[i].used++;
				pcount++;
			}
		}
	}
	for (i = 0; i < count; i++) {
		m = boardlist[i].brdn;
		for (j = 0; j < boardlist[i].used; j++)
			printlastmarkline(fp, &lastmarklist[m], j);
	}
	if (pcount < count) {
		if (sec->parent != &sectree)
			l = 20;
		else
			l = 3;
		fprintf(fp, "ltb('%s',new Array(", sec->basestr);
		for (i = 0, j = 0; i < count && j < l; i++) {
			if (boardlist[i].used)
				continue;
			m = boardlist[i].brdn;
			fprintf(fp, "%s'%d','%s'", j ? "," : "",
				lastmarklist[m].bnum,
				scriptstr(lastmarklist[m].boardtitle));
			j++;
		}
		fprintf(fp, "));");
		n++;
	}

	if (!count)
		fprintf(fp,
			"document.write('<tr><td colspan=2>&nbsp;</td></tr>');");
	fprintf(fp, "etb();\n");
	return n;
}
Example #2
0
int
printlastmarkline(FILE * fp, struct lastmarkl *lm, int i)
{
	char *title = lm->title[i];
	fprintf(fp, "itb('%d','%s',%d,", lm->bnum, scriptstr(lm->boardtitle),
		lm->thread[i]);
	if (!strncmp(title, "[зЊди] ", 7) && strlen(title) > 20)
		title += 7;
	if (strlen(title) > 45)
		title[45] = 0;
	fprintf(fp, "'%s');", scriptstr(title));
	return 0;
}
Example #3
0
int
oneboardscript(struct boardmem *brd)
{
	char bmbuf[IDLEN * 4 + 4], *ptr;
	int i, limit, brdnum, hasicon;
	struct boardaux *boardaux = getboardaux(getbnumx(brd));
	updatewwwindex(brd);
	brdnum = getbnumx(brd);
	hasicon = brd->wwwicon;
	if (hasicon)
		hasicon += hideboard_x(brd) ? 1 : 0;
	printf("new abrd(%d,'%s','%s',%d,%d,%d,%d,%d,",
	       brdnum, brd->header.filename, scriptstr(brd->header.title),
	       hasicon, brd->total, brd->score,
	       (brd->header.flag & VOTE_FLAG) ? 1 : 0,
	       (brd->header.
		level & PERM_POSTMASK) ? 2 : ((brd->header.
					       flag & CLOSECLUB_FLAG) ? 1 : 0));

	ptr = userid_str(bm2str(bmbuf, &(brd->header)));
	if (!*ptr)
		printf("'ипнч╟ФжВ',");
	else
		printf("'%s',", ptr);
	printf("'%s ',", scriptstr(boardaux->intro));
	limit = 8;
	if ((ptr = strstr(brd->header.filename, "admin"))) {
		if (strlen(ptr) == 5)
			limit = 4;
	}
	if ((brd->header.flag & CLOSECLUB_FLAG))
		printf("''");
	else {
		limit = min(limit, boardaux->nlastmark);
		printf("new Array(");
		for (i = 0; i < limit; i++) {
			struct lastmark *lm = &boardaux->lastmark[i];
			printf("new alm(%d,'%s','%s',%d)",
			       lm->thread, scriptstr(lm->title), 
			       lm->authors, lm->marked ? 1 : 0);
			if (i < limit - 1)
				printf(",");
		}
		printf(")");
	}
	printf(")");
	return 0;
}
Example #4
0
bool JSGlobal::JS_load(JSContext *cx, JS::CallArgs &args)
{
    JS::RootedString script(cx);
    char *content;
    size_t len;

    if (!JS_ConvertArguments(cx, args, "S", script.address())) {
        return false;
    }

    JSAutoByteString scriptstr(cx, script);
    Path scriptpath(scriptstr.ptr());

    Path::schemeInfo *schemeCwd = Path::GetCwdScheme();

    if (scriptpath.path() == NULL) {
        JS_ReportError(cx, "script error : invalid file location");
        return false;
    }

    /* only embed are allowed in an http context */
    if (SCHEME_MATCH(schemeCwd, "http")
        && !URLSCHEME_MATCH(scriptstr.ptr(), "embed")) {
        JS_ReportError(cx, "script access error : Can't load in this context");
        return false;
    }

    if (!scriptpath.GetScheme()->AllowSyncStream()) {
        JS_ReportError(cx,
                       "script error : \"%s\" scheme Can't load in a sync way",
                       schemeCwd->str);
        return false;
    }

    PtrAutoDelete<Stream *> stream(scriptpath.CreateStream());

    if (!stream.ptr() || !stream.ptr()->getContentSync(&content, &len, true)) {
        JS_ReportError(cx, "load() failed read script");
        return false;
    }

    if (!m_JS->LoadScriptContent(content, len, scriptpath.path())) {
        JS_ReportError(cx, "load() failed to load script");
        return false;
    }

    return true;
}
Example #5
0
void sinsp_chisel::load(string cmdstr)
{
	m_filename = cmdstr;
	trim(cmdstr);

	ifstream is;

	//
	// Try to open the file as is
	//
	if(!openfile(m_filename, &is))
	{
		//
		// Try to add the .sc extension
		//
		if(!openfile(m_filename + ".sc", &is))
		{
			if(!openfile(m_filename + ".lua", &is))
			{
				throw sinsp_exception("can't open file " + m_filename);
			}
		}
	}

	//
	// Bring the file into a string
	//
	string docstr((istreambuf_iterator<char>(is)),
		istreambuf_iterator<char>());

#ifdef HAS_LUA_CHISELS
	//
	// Rewind the stream
	//
	is.seekg(0);

	//
	// Load the file
	//
	std::istreambuf_iterator<char> eos;
	std::string scriptstr(std::istreambuf_iterator<char>(is), eos);

	//
	// Open the script
	//
	m_ls = lua_open();
 
	luaL_openlibs(m_ls);

	//
	// Load our own lua libs
	//
	luaL_openlib(m_ls, "sysdig", ll_sysdig, 0);
	luaL_openlib(m_ls, "chisel", ll_chisel, 0);
	luaL_openlib(m_ls, "evt", ll_evt, 0);

	//
	// Add our chisel paths to package.path
	//
	for(uint32_t j = 0; j < g_chisel_dirs->size(); j++)
	{
		string path(g_chisel_dirs->at(j).m_dir);
		path += "?.lua";
		add_lua_package_path(m_ls, path.c_str());
	}

	//
	// Load the script
	//
	if(luaL_loadstring(m_ls, scriptstr.c_str()) || lua_pcall(m_ls, 0, 0, 0)) 
	{
		throw sinsp_exception("Failed to load chisel " + 
			m_filename + ": " + lua_tostring(m_ls, -1));
	}

	//
	// Allocate the chisel context for the script
	//
	m_lua_cinfo = new chiselinfo(m_inspector);

	//
	// Set the context globals
	//
	lua_pushlightuserdata(m_ls, this);
	lua_setglobal(m_ls, "sichisel");

	//
	// Extract the args
	//
	lua_getglobal(m_ls, "args");
	if(!lua_istable(m_ls, -1))
	{
		throw sinsp_exception("Failed to load chisel " + 
			m_filename + ": args table missing");
	}

	try
	{
		parse_lua_chisel_args(m_ls, &m_lua_script_info);
	}
	catch(sinsp_exception& e)
	{
		throw e;
	}

	//
	// Check if the script has an on_event
	//
	lua_getglobal(m_ls, "on_event");
	if(lua_isfunction(m_ls, -1))
	{
		m_lua_has_handle_evt = true;
		lua_pop(m_ls, 1);
	}
#endif

	is.close();
}