Exemplo n.º 1
0
DaoState* DaoState_New( DaoType *type, DaoValue *state )
{
	DaoState *res = dao_malloc( sizeof(DaoState) );
	DaoCstruct_Init( (DaoCstruct*)res, type );
	DaoValue_Copy( state, &res->state );
	res->lock = DaoMutex_New();
	res->defmtx = DaoMutex_New();
	res->demands = DaoMap_New( 0 );
	DaoGC_IncRC( (DaoValue*)res->lock );
	DaoGC_IncRC( (DaoValue*)res->defmtx );
	DaoGC_IncRC( (DaoValue*)res->demands );
	return res;
}
Exemplo n.º 2
0
DAO_DLL int DaoCGI_OnLoad( DaoVmSpace *vmSpace, DaoNamespace *ns )
{
    DaoProcess *process = DaoVmSpace_AcquireProcess( vmSpace );
    DaoMap *httpENV, *httpGET, *httpPOST, *httpFILE, *httpCOOKIE;
    DaoMap *httpGETS, *httpPOSTS;
    srand( time(NULL) );

    vmMaster = vmSpace;

    ns = DaoNamespace_GetNamespace( ns, "cgi" );
    daox_type_namestream = DaoNamespace_DefineType( ns,
                           "tuple<file:string,size:int,data:io::FileStream>", "HttpUpload" );
    daox_type_filemap = DaoNamespace_DefineType( ns, "map<string,HttpUpload>", NULL );

    DaoNamespace_WrapFunctions( ns, cgiMeths );

    httpENV = DaoMap_New(1+rand());
    httpGET = DaoMap_New(1+rand());
    httpPOST = DaoMap_New(1+rand());
    httpFILE = DaoMap_New(1+rand());
    httpCOOKIE = DaoMap_New(1+rand());
    httpGETS = DaoMap_New(1+rand());
    httpPOSTS = DaoMap_New(1+rand());

    DaoNamespace_AddValue( ns, "HTTP_ENV", (DaoValue*)httpENV, "map<string,string>" );
    DaoNamespace_AddValue( ns, "HTTP_GET", (DaoValue*)httpGET, "map<string,string>" );
    DaoNamespace_AddValue( ns, "HTTP_POST", (DaoValue*)httpPOST, "map<string,string>" );
    DaoNamespace_AddValue( ns, "HTTP_FILE", (DaoValue*)httpFILE, "map<string,HttpUpload>" );
    DaoNamespace_AddValue( ns, "HTTP_COOKIE", (DaoValue*)httpCOOKIE, "map<string,string>");
    DaoNamespace_AddValue( ns,"HTTP_GETS",(DaoValue*)httpGETS,"map<string,list<string>>");
    DaoNamespace_AddValue( ns,"HTTP_POSTS",(DaoValue*)httpPOSTS,"map<string,list<string>>");

    // Prepare HTTP_ENV:
    ParseKeyValueStringArray( process, httpENV, environ );

    // Prepare HTTP_GET:
    char *query = getenv( "QUERY_STRING" );
    if( query == NULL ) { /* lighttpd does not set "QUERY_STRING": */
        query = getenv( "REQUEST_URI" );
        if( query ) query = strchr( query, '?' );
        if( query ) query += 1;
    }
    if( query ) ParseKeyValueString( process, httpGETS, httpGET, query );
    query = getenv( "HTTP_COOKIE" );
    if( query ) ParseKeyValueString( process, NULL, httpCOOKIE, query );

    PreparePostData( process, httpPOSTS, httpPOST, httpFILE );

    DaoVmSpace_ReleaseProcess( vmSpace, process );
    return 0;
}
Exemplo n.º 3
0
static DaoValue* DaoValue_DeepCopy( DaoValue *self )
{
	DNode *it;
	daoint i;
	if( self == NULL ) return NULL;
	if( self->type <= DAO_ENUM ) return self; /* simple types will be copied at use; */
	if( self->type == DAO_ARRAY ) return (DaoValue*) DaoArray_Copy( (DaoArray*) self );
	if( self->type == DAO_LIST ){
		DaoList *list = (DaoList*) self;
		DaoList *copy = DaoList_New();
		GC_ShiftRC( list->unitype, copy->unitype );
		copy->unitype = list->unitype;
		for(i=0; i<list->items.size; ++i){
			DaoValue *value = DaoValue_DeepCopy( list->items.items.pValue[i] );
			DaoList_Append( copy, value );
		}
		return (DaoValue*) copy;
	}else if( self->type == DAO_MAP ){
		DaoMap *map = (DaoMap*) self;
		DaoMap *copy = DaoMap_New( map->items->hashing );
		GC_ShiftRC( map->unitype, copy->unitype );
		copy->unitype = map->unitype;
		for(it=DMap_First(map->items); it; it=DMap_Next(map->items,it)){
			DaoValue *key = DaoValue_DeepCopy( it->key.pValue );
			DaoValue *value = DaoValue_DeepCopy( it->value.pValue );
			DaoMap_Insert( copy, key, value );
		}
		return (DaoValue*) copy;
	}else if( self->type == DAO_TUPLE ){
		DaoTuple *tuple = (DaoTuple*) self;
		DaoTuple *copy = DaoTuple_New( tuple->size );
		GC_ShiftRC( tuple->unitype, copy->unitype );
		copy->unitype = tuple->unitype;
		for(i=0; i<tuple->size; ++i){
			DaoValue *value = DaoValue_DeepCopy( tuple->items[i] );
			DaoTuple_SetItem( copy, value, i );
		}
		return (DaoValue*) copy;
	}
	return NULL;
}
Exemplo n.º 4
0
DaoMap* DaoProcess_NewMap( DaoProcess *self, unsigned int hashing )
{
	DaoMap *res = DaoMap_New( hashing );
	DaoProcess_CacheValue( self, (DaoValue*) res );
	return res;
}