Example #1
0
/*process thread func*/
void* process_thread(void* pdata){
	struct server_data* psd = NULL; 
	CLT_T* pclt = NULL;
	struct list_head* pclt_head = NULL;

	psd = get_server();
	if(psd==NULL){
		pthread_exit(NULL);	
	}
	pclt_head = &psd->sd_clt_head;
	post_server();
	process_init();
	while(1){
		list_for_each_entry(pclt,pclt_head,ci_list){
			if(pclt->ci_rlen>0){
				process_deal(pclt);
				if(!sem_trywait(&pclt->ci_sem)){
					pclt->ci_rlen = 0;	
					sem_post(&pclt->ci_sem);
				}
				clt_fresh(pclt);
			}
		}
	}
	pthread_exit(NULL);
}
Example #2
0
// register_biome({lots of stuff})
static int l_register_biome(lua_State *L)
{
	int index = 1;
	luaL_checktype(L, index, LUA_TTABLE);

	BiomeDefManager *bmgr = get_server(L)->getEmergeManager()->biomedef;
	if (!bmgr) {
		verbosestream << "register_biome: BiomeDefManager not active" << std::endl;
		return 0;
	}
	
	enum BiomeTerrainType terrain = (BiomeTerrainType)getenumfield(L, index,
					"terrain_type", es_BiomeTerrainType, BIOME_TERRAIN_NORMAL);
	Biome *b = bmgr->createBiome(terrain);

	b->name            = getstringfield_default(L, index, "name", "");
	b->top_nodename    = getstringfield_default(L, index, "top_node", "");
	b->top_depth       = getintfield_default(L, index, "top_depth", 0);
	b->filler_nodename = getstringfield_default(L, index, "filler_node", "");
	b->filler_height   = getintfield_default(L, index, "filler_height", 0);
	b->height_min      = getintfield_default(L, index, "height_min", 0);
	b->height_max      = getintfield_default(L, index, "height_max", 0);
	b->heat_point      = getfloatfield_default(L, index, "heat_point", 0.);
	b->humidity_point  = getfloatfield_default(L, index, "humidity_point", 0.);

	b->flags    = 0; //reserved
	b->c_top    = CONTENT_IGNORE;
	b->c_filler = CONTENT_IGNORE;
	bmgr->addBiome(b);

	verbosestream << "register_biome: " << b->name << std::endl;
	return 0;
}
Example #3
0
void
tm_frame_rep::choose_file (object fun, string title, string type,
			   string prompt, url name) {
  command  cb  = dialogue_command (get_server(), fun, 1);
  widget   wid = file_chooser_widget (cb, type, prompt);
  if (!is_scratch (name)) {
    set_directory (wid, as_string (head (name)));
    if ((type != "image") && (type != "")) {
      url u= tail (name);
      string old_suf= suffix (u);
      string new_suf= format_to_suffix (type);
      if ((suffix_to_format (suffix (u)) != type) &&
	  (old_suf != "") && (new_suf != ""))
	{
	  u= unglue (u, N(old_suf) + 1);
	  u= glue (u, "." * new_suf);
	}
      set_file (wid, as_string (u));
    }
  }
  else set_directory (wid, ".");
  dialogue_start (title, wid);
  if (type == "directory") send_keyboard_focus (get_directory (dialogue_wid));
  else send_keyboard_focus (get_file (dialogue_wid));
}
Example #4
0
// rollback_revert_actions_by(actor, seconds) -> bool, log messages
static int l_rollback_revert_actions_by(lua_State *L)
{
	std::string actor = luaL_checkstring(L, 1);
	int seconds = luaL_checknumber(L, 2);
	Server *server = get_server(L);
	IRollbackManager *rollback = server->getRollbackManager();
	std::list<RollbackAction> actions = rollback->getRevertActions(actor, seconds);
	std::list<std::string> log;
	bool success = server->rollbackRevertActions(actions, &log);
	// Push boolean result
	lua_pushboolean(L, success);
	// Get the table insert function and push the log table
	lua_getglobal(L, "table");
	lua_getfield(L, -1, "insert");
	int table_insert = lua_gettop(L);
	lua_newtable(L);
	int table = lua_gettop(L);
	for(std::list<std::string>::const_iterator i = log.begin();
			i != log.end(); i++)
	{
		lua_pushvalue(L, table_insert);
		lua_pushvalue(L, table);
		lua_pushstring(L, i->c_str());
		if(lua_pcall(L, 2, 0, 0))
			script_error(L, "error: %s", lua_tostring(L, -1));
	}
	lua_remove(L, -2); // Remove table
	lua_remove(L, -2); // Remove insert
	return 2;
}
Example #5
0
int default_call_back()
{
    int ret;
    sl_server_tdata_t  *tdata;
    sl_server_t *server;

    tdata = get_tdata();
    server = get_server();
    

    //res = read(tdata->client_fd, tdata->read_buf, tdata->read_size);   
    //((char*)(tdata->read_buf))[tdata->read_size-1] = '\0';

    sl_io_head_t *req = (sl_io_head_t*)sl_server_get_read_buf();
    sl_io_head_t *res = (sl_io_head_t*)sl_server_get_write_buf();
    int req_size = sl_server_get_read_size();

    sl_io_read(tdata->client_fd, req, req_size);

    
    server->handler();
    
    //((char*)(tdata->write_buf))[tdata->write_size-1] = '\0';
    //write(tdata->client_fd, tdata->write_buf, strlen(tdata->write_buf));

    sl_io_write(tdata->client_fd, res);
    
    return 0;
}
Example #6
0
/**
 * Send the response to the client. If the response has already been
 * commited, this function does nothing.
 */
static void send_response(HttpResponse res) {
  Socket_T S= res->S;

  if(!res->is_committed) {
    char date[STRLEN];
    char server[STRLEN];
    char *headers= get_headers(res);
    int length = StringBuffer_length(res->outputbuffer);

    res->is_committed= TRUE;
    get_date(date, STRLEN);
    get_server(server, STRLEN);
    socket_print(S, "%s %d %s\r\n", res->protocol, res->status,
		 res->status_msg);
    socket_print(S, "Date: %s\r\n", date);
    socket_print(S, "Server: %s\r\n", server);
    socket_print(S, "Content-Length: %d\r\n", length);
    socket_print(S, "Connection: close\r\n");
    if(headers)
	socket_print(S, "%s", headers);
    socket_print(S, "\r\n");
    if(length)
	socket_write(S, (unsigned char *)StringBuffer_toString(res->outputbuffer), length);
    FREE(headers);
  }
}
Example #7
0
int process_init(void){
	int i;
	struct server_data* psd = NULL;
	psd = get_server();	
	post_server();

	for(i=0;i<MAX_METHOD;i++){
		PM_T* ppm = ppm_tab[i];
		struct cmd_info *pci = NULL;
		if(NULL==ppm){
			continue;
		}
		/*cmd header init*/
		if(ppm->pm_header != NULL){
			pci = (struct cmd_info*)malloc(sizeof(struct cmd_info));			
			if(NULL==pci){
				perror("init cmd head failed");
				return -1;
			}
			bzero(pci, sizeof(struct cmd_info));
			INIT_LIST_HEAD(&pci->ci_list);
			memcpy(pci->ci_header,ppm->pm_header, strlen(ppm->pm_header));
			pci->ci_pm_pos = i;
			list_add(&pci->ci_list, &psd->sd_cmdinfo_head);
			ppm->pm_pcmd = pci;	
		}
		if(ppm->pm_init){
			if(!ppm->pm_init(ppm->pm_ctrl_file))
				ppm->pm_stat = PMS_INITED;
			method_fresh(ppm);
		}
	}

	return 0;
}
int
main_v1_1( void )
{
	char			*function = "Tspi_TPM_StirRandom02";
	BYTE			entropy;
	TSS_HCONTEXT		hContext;
	TSS_HTPM		whTPM = -1;
	TSS_RESULT		result;
	UINT32			exitCode = 0;

	print_begin_test( function );

		// seed entropy with time
	srand( time(0) );

		// Create Context
	result = Tspi_Context_Create( &hContext );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Create", result );
		exit( result );
	}

		// Connect to Context
	result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) );
	if ( result != TSS_SUCCESS )
	{
		print_error( "Tspi_Context_Connect", result );
		Tspi_Context_FreeMemory( hContext, NULL );
		Tspi_Context_Close( hContext );
		exit( result );
	}

	entropy = ( rand() % 100 );

		//Get random number
	result = Tspi_TPM_StirRandom( whTPM, 16, &entropy );
	if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE )
	{
		if( !(checkNonAPI(result)) )
		{
			print_error( function, result );
		}
		else
		{
			print_error_nonapi( function, result );
		}
		exitCode = result;
	}
	else
	{
		print_success( function, result );
	}

	print_end_test( function );
	Tspi_Context_FreeMemory( hContext, NULL );
	Tspi_Context_Close( hContext );
	exit( exitCode );
}
main_v1_1(void){

	char		*nameOfFunction = "Tspi_GetAttribData09";
	TSS_HCONTEXT	hContext;
	TSS_RESULT	result;
	TSS_HKEY	hSRK;
	BYTE*		BLOB;
	UINT32		BlobLength;

	print_begin_test(nameOfFunction);

		//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create ", result);
		exit(result);
	}
		//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Load Key by UUID for SRK
	result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
				SRK_UUID, &hSRK);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_LoadKeyByUUID", result);
		Tspi_Context_Close(hContext);
		exit(result);
	}
		//Call GetAttribData
	result = Tspi_GetAttribData(hSRK, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY,
				    &BlobLength, &BLOB);
	if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) {
		if(!checkNonAPI(result)){
			print_error(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
		else{
			print_error_nonapi(nameOfFunction, result);
			print_end_test(nameOfFunction);
			Tspi_Context_FreeMemory(hContext, NULL);
			Tspi_Context_Close(hContext);
			exit(result);
		}
	}
	else{
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_FreeMemory(hContext, NULL);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
main_v1_2(char version){

	char		*nameOfFunction = "Tspi_TPM_OwnerGetSRKPubKey01";
	TSS_RESULT	result;
	TSS_HCONTEXT	hContext;
	TSS_HTPM	hTPM;
	TSS_HKEY	hSRK;
	TSS_HPOLICY	hPolicy;
	UINT32          pulPubKeyLength;
	BYTE            *prgbPubKey;

	print_begin_test(nameOfFunction);

		//Create Context
	result = Tspi_Context_Create(&hContext);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Create", result);
		exit(result);
	}
		//Connect Context
	result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_Connect", result);
		exit(result);
	}
		//Get TPM Object
	result = Tspi_Context_GetTpmObject(hContext, &hTPM);
	if (result != TSS_SUCCESS) {
		print_error("Tspi_Context_GetTpmObject", result);
		exit(result);
	}

	result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hPolicy );
	if ( result != TSS_SUCCESS ) {
		print_error( "Tspi_GetPolicyObject", result );
		return result;
	}

	result = Tspi_Policy_SetSecret( hPolicy, TESTSUITE_OWNER_SECRET_MODE,
					TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET);
	if ( result != TSS_SUCCESS ) {
		print_error( "Tspi_Policy_SetSecret", result );
		return result;
	}

		//Get SRK Public Key
	result = Tspi_TPM_OwnerGetSRKPubKey(hTPM, &pulPubKeyLength, &prgbPubKey);
	if (result != TSS_SUCCESS) {
		print_error(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(result);
	} else {
		print_success(nameOfFunction, result);
		print_end_test(nameOfFunction);
		Tspi_Context_Close(hContext);
		exit(0);
	}
}
Example #11
0
tmscm
tmg_window_get_serial () {
  // TMSCM_DEFER_INTS;
  int out= get_server()->get_window_serial ();
  // TMSCM_ALLOW_INTS;

  return int_to_tmscm (out);
}
Example #12
0
// get_modpath(modname)
static int l_get_modpath(lua_State *L)
{
	std::string modname = luaL_checkstring(L, 1);
	// Do it
	if(modname == "__builtin"){
		std::string path = get_server(L)->getBuiltinLuaPath();
		lua_pushstring(L, path.c_str());
		return 1;
	}
	const ModSpec *mod = get_server(L)->getModSpec(modname);
	if(!mod){
		lua_pushnil(L);
		return 1;
	}
	lua_pushstring(L, mod->path.c_str());
	return 1;
}
Example #13
0
// notify_authentication_modified(name)
static int l_notify_authentication_modified(lua_State *L)
{
	std::string name = "";
	if(lua_isstring(L, 1))
		name = lua_tostring(L, 1);
	get_server(L)->reportPrivsModified(name);
	return 0;
}
Example #14
0
tmscm
tmg_visible_footerP () {
  // TMSCM_DEFER_INTS;
  bool out= get_server()->visible_footer ();
  // TMSCM_ALLOW_INTS;

  return bool_to_tmscm (out);
}
Example #15
0
tmscm
tmg_full_screen_editP () {
  // TMSCM_DEFER_INTS;
  bool out= get_server()->in_full_screen_edit_mode ();
  // TMSCM_ALLOW_INTS;

  return bool_to_tmscm (out);
}
// is_known(self) -> true/false
// Checks if the item is defined.
int LuaItemStack::l_is_known(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	bool is_known = item.isKnown(get_server(L)->idef());
	lua_pushboolean(L, is_known);
	return 1;
}
Example #17
0
tmscm
tmg_recall_message () {
  // TMSCM_DEFER_INTS;
  get_server()->recall_message ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
Example #18
0
tmscm
tmg_quit_TeXmacs () {
  // TMSCM_DEFER_INTS;
  get_server()->quit ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
Example #19
0
tmscm
tmg_inclusions_gc () {
  // TMSCM_DEFER_INTS;
  get_server()->inclusions_gc ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
Example #20
0
tmscm
tmg_update_all_buffers () {
  // TMSCM_DEFER_INTS;
  get_server()->typeset_update_all ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
Example #21
0
tmscm
tmg_get_default_zoom_factor () {
  // TMSCM_DEFER_INTS;
  double out= get_server()->get_default_zoom_factor ();
  // TMSCM_ALLOW_INTS;

  return double_to_tmscm (out);
}
Example #22
0
tmscm
tmg_get_printer_paper_type () {
  // TMSCM_DEFER_INTS;
  string out= get_server()->get_printer_page_type ();
  // TMSCM_ALLOW_INTS;

  return string_to_tmscm (out);
}
Example #23
0
tmscm
tmg_style_clear_cache () {
  // TMSCM_DEFER_INTS;
  get_server()->style_clear_cache ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
Example #24
0
tmscm
tmg_dialogue_end () {
  // TMSCM_DEFER_INTS;
  get_server()->dialogue_end ();
  // TMSCM_ALLOW_INTS;

  return TMSCM_UNSPECIFIED;
}
// add_item(self, itemstack or itemstring or table or nil) -> itemstack
// Returns leftover item stack
int LuaItemStack::l_add_item(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	ItemStack newitem = read_item(L, 2);
	ItemStack leftover = item.addItem(newitem, get_server(L)->idef());
	create(L, leftover);
	return 1;
}
// add_wear(self, amount) -> true/false
// The range for "amount" is [0,65535]. Wear is only added if the item
// is a tool. Adding wear might destroy the item.
// Returns true if the item is (or was) a tool.
int LuaItemStack::l_add_wear(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	int amount = lua_tointeger(L, 2);
	bool result = item.addWear(amount, get_server(L)->idef());
	lua_pushboolean(L, result);
	return 1;
}
// get_tool_capabilities(self) -> table
// Returns the effective tool digging properties.
// Returns those of the hand ("") if this item has none associated.
int LuaItemStack::l_get_tool_capabilities(lua_State *L)
{
	LuaItemStack *o = checkobject(L, 1);
	ItemStack &item = o->m_stack;
	const ToolCapabilities &prop =
		item.getToolCapabilities(get_server(L)->idef());
	push_tool_capabilities(L, prop);
	return 1;
}
Example #28
0
tm_window_rep::tm_window_rep (widget wid2, tree geom):
    win (texmacs_window_widget (wid2, geom)),
    wid (wid2), id (create_window_id ()),
    serial (tm_window_serial++),
    menu_current (object ()), menu_cache (widget ()),
    text_ptr (NULL)
{
    zoomf= get_server () -> get_default_zoom_factor ();
}
Example #29
0
/*if dealed return 0, else return -1*/
int process_deal(CLT_T* pclt){
	struct server_data *psd = NULL;
	struct list_head* pcmd_head = NULL;
	struct cmd_info* pcmd_info = NULL;
	psd = get_server();
	if(psd==NULL || pclt==NULL){
		return -1;
	}
	pcmd_head = &psd->sd_cmdinfo_head;
	post_server();
	/*match method*/
	int i;	

	/*select and deal*/
	cmd_select(pclt, pcmd_head);

	/*clean client recive buffer*/
	pclt->ci_rlen = 0;
	bzero(pclt->ci_rbuf, sizeof(pclt->ci_rbuf));

#if 0	//old deal method
	for(i=0;i<MAX_METHOD;i++){
		PM_T* ppm = ppm_tab[i];
		if(NULL == ppm)
			continue;
		
		size_t hlen = strlen(ppm->pm_header);
		if(!strncmp(ppm->pm_header,pclt->ci_rbuf,hlen)){
			method_fresh(ppm);
			if(ppm->pm_init && ppm->pm_stat==PMS_UNINIT){
				ppm->pm_init(ppm->pm_ctrl_file);
				ppm_tab[i]->pm_stat = PMS_INITED;
			}

			if(ppm->pm_deal){
				if(!sem_trywait(&pclt->ci_sem)){
					printf("[%s][%s]\n",__func__,ppm->pm_header);
					pclt->ci_rlen -= hlen;
					memcpy(pclt->ci_rbuf,pclt->ci_rbuf+hlen,pclt->ci_rlen);
					sem_post(&pclt->ci_sem);
					printf("[process_deal][ID][%s]\n",pclt->ci_rbuf);
					ppm->pm_deal(pclt);
					return 0;
				}
			}
		}
	}
#endif

	if(!sem_trywait(&pclt->ci_sem)){
		sprintf(pclt->ci_wbuf, "ERROR DATA");	
		pclt->ci_wlen = strlen(pclt->ci_wbuf);
		sem_post(&pclt->ci_sem);
	}

	return -1;
}
Example #30
0
// chat_send_all(text)
static int l_chat_send_all(lua_State *L)
{
	const char *text = luaL_checkstring(L, 1);
	// Get server from registry
	Server *server = get_server(L);
	// Send
	server->notifyPlayers(narrow_to_wide(text));
	return 0;
}