Exemple #1
0
EXTERN value neko_select_file( value path, const char *file, const char *ext ) {
	struct stat s;
	value ff;
	buffer b = alloc_buffer(file);
	buffer_append(b,ext);
	ff = buffer_to_string(b);
	if( stat(val_string(ff),&s) == 0 ) {
		char *p = strchr(file,'/');
		if( p == NULL )
			p = strchr(file,'\\');
		if( p != NULL )
			return ff;
		b = alloc_buffer("./");
		buffer_append(b,file);
		buffer_append(b,ext);
		return buffer_to_string(b);
	}
	while( val_is_array(path) && val_array_size(path) == 2 ) {
		value p = val_array_ptr(path)[0];
		buffer b = alloc_buffer(NULL);
		path = val_array_ptr(path)[1];
		val_buffer(b,p);
		val_buffer(b,ff);
		p = buffer_to_string(b);
		if( stat(val_string(p),&s) == 0 )
			return p;
	}
	return ff;
}
Exemple #2
0
static void report( neko_vm *vm, value exc, int isexc ) {
	int i;
	buffer b = alloc_buffer(NULL);
	value st = neko_exc_stack(vm);
	for(i=0;i<val_array_size(st);i++) {
		value s = val_array_ptr(st)[i];
		buffer_append(b,"Called from ");
		if( val_is_null(s) )
			buffer_append(b,"a C function");
		else if( val_is_string(s) ) {
			buffer_append(b,val_string(s));
			buffer_append(b," (no debug available)");
		} else if( val_is_array(s) && val_array_size(s) == 2 && val_is_string(val_array_ptr(s)[0]) && val_is_int(val_array_ptr(s)[1]) ) {
			val_buffer(b,val_array_ptr(s)[0]);
			buffer_append(b," line ");
			val_buffer(b,val_array_ptr(s)[1]);
		} else
			val_buffer(b,s);
		buffer_append_char(b,'\n');
	}
	if( isexc )
		buffer_append(b,"Uncaught exception - ");
	val_buffer(b,exc);
#	ifdef NEKO_STANDALONE
	neko_standalone_error(val_string(buffer_to_string(b)));
#	else
	fprintf(stderr,"%s\n",val_string(buffer_to_string(b)));
#	endif
}
Exemple #3
0
/**
	request : 'db -> sql:string -> 'result
	<doc>Executes the SQL request and returns its result</doc>
**/
static value request( value v, value sql ) {
	database *db;
	result *r;
	const char *tl;
	int i,j;
	val_check_kind(v,k_db);
	val_check(sql,string);
	db = val_db(v);
	r = (result*)alloc(sizeof(result));
	r->db = db;
	if( sqlite3_prepare(db->db,val_string(sql),val_strlen(sql),&r->r,&tl) != SQLITE_OK ) {
		buffer b = alloc_buffer("Sqlite error in ");
		val_buffer(b,sql);
		buffer_append(b," : ");
		buffer_append(b,sqlite3_errmsg(db->db));
		val_throw(buffer_to_string(b));
	}
	if( *tl ) {
		sqlite3_finalize(r->r);
		val_throw(alloc_string("Cannot execute several SQL requests at the same time"));
	}
	r->ncols = sqlite3_column_count(r->r);
	r->names = (field*)alloc_private(sizeof(field)*r->ncols);
	r->bools = (int*)alloc_private(sizeof(int)*r->ncols);
	r->first = 1;
	r->done = 0;
	for(i=0;i<r->ncols;i++) {
		field id = val_id(sqlite3_column_name(r->r,i));
		const char *dtype = sqlite3_column_decltype(r->r,i);
		for(j=0;j<i;j++)
			if( r->names[j] == id ) {
				if( strcmp(sqlite3_column_name(r->r,i),sqlite3_column_name(r->r,j)) == 0 ) {
					buffer b = alloc_buffer("Error, same field is two times in the request ");
					val_buffer(b,sql);
					sqlite3_finalize(r->r);
					val_throw(buffer_to_string(b));
				} else {
					buffer b = alloc_buffer("Error, same field ids for : ");
					buffer_append(b,sqlite3_column_name(r->r,i));
					buffer_append(b," and ");
					buffer_append(b,sqlite3_column_name(r->r,j));
					buffer_append_char(b,'.');
					sqlite3_finalize(r->r);
					val_throw(buffer_to_string(b));
				}
			}
		r->names[i] = id;
		r->bools[i] = dtype?(strcmp(dtype,"BOOL") == 0):0;
	}
	// changes in an update/delete
	if( db->last != NULL )
		finalize_result(val_result(db->last),0);
	db->last = alloc_abstract(k_result,r);
	return db->last;
}
Exemple #4
0
/* includes a newline at the end of the address info */
int ia_to_string (const struct internet_addr * ia, char * buf, int bsize)
{
  int offset = 0;
  offset += snprintf (buf + offset, bsize - offset,
                      "v %d, port %d, addr ", ia->ip_version, ntohs (ia->port));
  if (ia->ip_version == 4)
    offset += buffer_to_string (((char *) &(ia->ip)) + 12, 4, NULL, 4, 1,
                                buf + offset, bsize - offset);
  else
    offset += buffer_to_string ((char *) &(ia->ip), 16, NULL, 16, 1,
                                buf + offset, bsize - offset);
  return offset;
}
Exemple #5
0
static value init_path( const char *path ) {
	value l = val_null, tmp;
	char *p, *p2;
	char *allocated = NULL;
#ifdef NEKO_WINDOWS
	char exe_path[MAX_PATH];
	if( path == NULL ) {
#		ifdef NEKO_STANDALONE
#			define SELF_DLL NULL
#		else
#			define SELF_DLL "neko.dll"
#		endif
		if( GetModuleFileName(GetModuleHandle(SELF_DLL),exe_path,MAX_PATH) == 0 )
			return val_null;
		p = strrchr(exe_path,'\\');
		if( p == NULL )
			return val_null;
		*p = 0;
		path = exe_path;
	}
#else
	if( path == NULL ) {
		allocated = strdup("/usr/local/lib/neko:/usr/lib/neko:/usr/local/bin:/usr/bin");
		path = allocated;
	}
#endif
	while( true ) {
		// windows drive letter (same behavior expected on all os)
		if( *path && path[1] == ':' ) {
			p = strchr(path+2,':');
			p2 = strchr(path+2,';');
		} else {
			p = strchr(path,':');
			p2 = strchr(path,';');
		}
		if( p == NULL || (p2 != NULL && p2 < p) )
			p = p2;
		if( p != NULL )
			*p = 0;
		tmp = alloc_array(2);
		if( (p && p[-1] != '/' && p[-1] != '\\') || (!p && path[strlen(path)-1] != '/' && path[strlen(path)-1] != '\\') ) {
			buffer b = alloc_buffer(path);
			char c = '/';
			buffer_append_sub(b,&c,1);
			val_array_ptr(tmp)[0] = buffer_to_string(b);
		} else
			val_array_ptr(tmp)[0] = alloc_string(path);
		val_array_ptr(tmp)[1] = l;
		l = tmp;
		if( p != NULL )
			*p = (p == p2)?';':':';
		else
			break;
		path = p+1;
	}
	if( allocated != NULL )
		free(allocated);
	return l;
}
Exemple #6
0
/**
	result_next : 'result -> object?
	<doc>Returns the next row in the result or [null] if no more result.</doc>
**/
static value result_next( value v ) {
	int i;
	result *r;
	val_check_kind(v,k_result);
	r = val_result(v);
	if( r->done )
		return val_null;
	switch( sqlite3_step(r->r) ) {
	case SQLITE_ROW:
		r->first = 0;
		v = alloc_object(NULL);
		for(i=0;i<r->ncols;i++) {
			value f;
			switch( sqlite3_column_type(r->r,i) ) {
			case SQLITE_NULL:
				f = val_null;
				break;
			case SQLITE_INTEGER:
				if( r->bools[i] )
					f = alloc_bool(sqlite3_column_int(r->r,i));
				else
					f = alloc_int(sqlite3_column_int(r->r,i));
				break;
			case SQLITE_FLOAT:
				f = alloc_float(sqlite3_column_double(r->r,i));
				break;
			case SQLITE_TEXT:
				f = alloc_string((char*)sqlite3_column_text(r->r,i));
				break;
			case SQLITE_BLOB:
				{
					int size = sqlite3_column_bytes(r->r,i);
					f = alloc_empty_string(size);
					memcpy(val_string(f),sqlite3_column_blob(r->r,i),size);
					break;
				}
			default:
				{
					buffer b = alloc_buffer("Unknown Sqlite type #");
					val_buffer(b,alloc_int(sqlite3_column_type(r->r,i)));
					val_throw(buffer_to_string(b));
				}
			}
			alloc_field(v,r->names[i],f);
		}
		return v;
	case SQLITE_DONE:
		finalize_result(r,1);
		return val_null;
	case SQLITE_BUSY:
		val_throw(alloc_string("Database is busy"));
	case SQLITE_ERROR:
		sqlite_error(r->db->db);
	default:
		neko_error();
	}
	return val_null;
}
Exemple #7
0
value ImagePngData(value img) {
	ImageData _img = getImage(img);
	int size;
	void *ptr = gdImagePngPtr(imageImage(_img),&size);
	buffer ret = alloc_buffer(NULL);
	buffer_append_sub(ret,ptr,size);
	gdFree(ptr);
	return buffer_to_string(ret);
}
 void testStreambuf()
 {
     asio::streambuf sb(3);
     std::string const s =
         "0123456789012345678901234567890123456789012345678901234567890123456789"
         "0123456789012345678901234567890123456789012345678901234567890123456789"
         "0123456789012345678901234567890123456789012345678901234567890123456789";
     sb << s;
     expect(buffer_to_string(sb.data()) == s);
 }
Exemple #9
0
value ImageJpegData(value img, value quality) {
	ImageData _img = getImage(img);
	int _quality = val_int(quality);
	int size;
	void *ptr = gdImageJpegPtr(imageImage(_img),&size,_quality);
	buffer ret = alloc_buffer(NULL);
	buffer_append_sub(ret,ptr,size);
	gdFree(ptr);
	return buffer_to_string(ret);
}
Exemple #10
0
static void report( neko_vm *vm, value exc ) {
#if OSX
	CFStringRef title = CFSTR("Uncaught exception");
	CFStringRef message;
#endif
	int i = 0;
	buffer b = alloc_buffer(NULL);
	value st = neko_exc_stack(vm);
	if( val_array_size(st) > 20 ) {
		i = val_array_size(st) - 20;
		buffer_append(b,"...\n");
	}
	for(i;i<val_array_size(st);i++) {
		value s = val_array_ptr(st)[i];
		if( val_is_null(s) )
			buffer_append(b,"Called from a C function\n");
		else if( val_is_string(s) ) {
			buffer_append(b,"Called from ");
			buffer_append(b,val_string(s));
			buffer_append(b," (no debug available)\n");
		} else if( val_is_array(s) && val_array_size(s) == 2 && val_is_string(val_array_ptr(s)[0]) && val_is_int(val_array_ptr(s)[1]) ) {
			buffer_append(b,"Called from ");
			buffer_append(b,val_string(val_array_ptr(s)[0]));
			buffer_append(b," line ");
			val_buffer(b,val_array_ptr(s)[1]);
			buffer_append(b,"\n");
		} else {
			buffer_append(b,"Called from ");
			val_buffer(b,s);
			buffer_append(b,"\n");
		}
	}
	val_buffer(b,exc);
#if _WIN32
	MessageBox(NULL,val_string(buffer_to_string(b)),"Uncaught exception",MB_OK | MB_ICONERROR);
#elif OSX
	message = CFStringCreateWithCString(NULL,val_string(buffer_to_string(b)), kCFStringEncodingUTF8);
	CFUserNotificationDisplayNotice(0,0,NULL,NULL,NULL,title,message,NULL);
#elif LINUX
	fprintf(stderr,"Uncaught Exception: %s\n",val_string(buffer_to_string(b)));
#endif
}
Exemple #11
0
static void zlib_error( z_stream *z, int err ) {
	buffer b = alloc_buffer("ZLib Error : ");
	if( z && z->msg ) {
		buffer_append(b,z->msg);
		buffer_append(b," (");
	}
	val_buffer(b,alloc_int(err));
	if( z && z->msg )
		buffer_append_char(b,')');
	val_throw(buffer_to_string(b));
}
Exemple #12
0
uint64_t *exec_behaviour( uint64_t *message_ptr )
{
buffer_ptr = &buffer_pool_ptr->ring[ ++idx & RING_ENTRY_MASK ].buffer;

	// Receive message from socket
  buffer_ptr->size = read( fd, buffer_ptr->data, RAW_MSG_SIZE_MAX );
  buffer_ptr->data[ buffer_ptr->size ] = 0;

  DEBUGV( printf( "Publishing message: %s\n", buffer_to_string( buffer_ptr ) ) );
  *message_ptr = ( uint64_t )buffer_ptr;
  return message_ptr;;
}
Exemple #13
0
/**
	$print : any* -> void
	<doc>Can print any value</doc>
**/
static value builtin_print( value *args, int nargs ) {
	buffer b;
	int i;
	if( nargs == 1 && val_is_string(*args) ) {
		val_print(*args);
		return neko_builtins[1];
	}
	b = alloc_buffer(NULL);
	for(i=0;i<nargs;i++)
		val_buffer(b,args[i]);
	val_print(buffer_to_string(b));
	return neko_builtins[1];
}
Exemple #14
0
static muse_cell json_read_string( muse_port_t p )
{
	muse_char c = port_getchar(p);
	assert( c == '"' );

	{
		buffer_t *b = buffer_alloc();
	
		while ( !port_eof(p) ) {
			c = port_getchar(p);
			if ( c == '"' ) 
				break;
			else if ( c == '\\' ) {
				c = port_getchar(p);
				switch( c ) {
					case '"':	buffer_putc( b, c ); break;
					case '\\':	buffer_putc( b, c ); break;
					case '/':	buffer_putc( b, c ); break;
					case 'b':	buffer_putc( b, '\b' ); break;
					case 'f':	buffer_putc( b, '\f' ); break;
					case 'n':	buffer_putc( b, '\n' ); break;
					case 'r':	buffer_putc( b, '\r' ); break;
					case 't':	buffer_putc( b, '\t' ); break;
					case 'u':
						{
							muse_char d[4];
							d[0] = port_getchar(p);
							d[1] = port_getchar(p);
							d[2] = port_getchar(p);
							d[3] = port_getchar(p);
							buffer_putc( b, hex2word(d) );
							break;								
						}
					default:
						muse_raise_error( p->env, muse_csymbol(p->env,L"json:invalid-escape-code"), MUSE_NIL );
						buffer_putc( b, c );
						break;
				}
			} else {
				buffer_putc( b, c );
			}
		}

		{
			muse_cell str = buffer_to_string( b, p->env );
			buffer_free(b);
			return str;
		}
	}
}
uint64_t *exec_behaviour( uint64_t *message_ptr )
{
  buffer_ptr = &buffer_pool_ptr->ring[ ++idx & RING_ENTRY_MASK ].buffer;;

  // Read next message from file
  buffer_ptr->size = read( fd, buffer_ptr->data, RAW_MSG_SIZE_MAX );
  if( buffer_ptr->data[ buffer_ptr->size - 1 ] == '\n' ) 
    buffer_ptr->data[ buffer_ptr->size - 1 ] = 0;
  else
    buffer_ptr->data[ buffer_ptr->size ] = 0;

  DEBUGV( printf( "Publishing message: %a\n", buffer_to_string( buffer_ptr ) ) );
  *message_ptr = ( uint64_t )buffer_ptr;
  return message_ptr;
}
Exemple #16
0
/**
	set_cookie : name:string -> val:string -> void
	<doc>Set a cookie</doc>
**/
static value set_cookie( value name, value v ) {
	mcontext *c = CONTEXT();
	buffer b;
	value str;
	val_check(name,string);
	val_check(v,string);
	HEADERS_NOT_SENT("Cookie");
	b = alloc_buffer(NULL);
	val_buffer(b,name);
	buffer_append(b,"=");
	val_buffer(b,v);
	buffer_append(b,";");
	str = buffer_to_string(b);
	ap_table_add(c->r->headers_out,"Set-Cookie",val_string(str));
	return val_true;
}
Exemple #17
0
value __SSL_read(value ssl) {
	buffer b;
	char buf[256];
	int len;
	//val_check_kind(o,k_socket);
	b = alloc_buffer(NULL);
	while (true) {
		len = SSL_read((SSL*) val_data(ssl), buf, 256);
		//if( len == SOCKET_ERROR )
		//	return block_error();
		if (len == 0)
			break;
		buffer_append_sub(b, buf, len);
	}
	return buffer_to_string(b);
}
Exemple #18
0
static void thread_loop( void *_p ) {
	tparams *p = (tparams*)_p;
	value exc = NULL;
	val_callEx(val_null,p->callb,&p->callparam,1,&exc);
	// display exception
	if( exc != NULL ) {
		buffer b = alloc_buffer(NULL);
		fprintf(stderr,"An exception occured in a neko Thread :\n");
		val_buffer(b,exc);
		fprintf(stderr,"%s\n",val_string(buffer_to_string(b)));
	}
	// cleanup
	neko_vm_select(NULL);
	p->t->v = val_null;
	p->t->vm = NULL;
}
Exemple #19
0
value hxfcgi_set_cookie(value hreq, value name, value v) {
	val_check_kind(hreq,hxRequest);
	val_check(name,string);
	val_check(v,string);
	buffer b;
	value str;
	hxfcgi::Request *req = get_request(hreq);
	b = alloc_buffer(NULL);
	val_buffer(b,name);
	buffer_append(b,"=");
	val_buffer(b,v);
	buffer_append(b,";");
	str = buffer_to_string(b);
	req->addHeader("Set-Cookie",val_string(str));
	return val_true;
}
Exemple #20
0
/**
	connect : filename:string -> 'db
	<doc>Open or create the database stored in the specified file.</doc>
**/
static value connect( value filename ) {
	int err;
	database *db = (database*)alloc(sizeof(database));
	value v;
	val_check(filename,string);
	db->last = NULL;
	if( (err = sqlite3_open(val_string(filename),&db->db)) != SQLITE_OK ) {
		buffer b = alloc_buffer("Sqlite error : ");
		buffer_append(b,sqlite3_errmsg(db->db));
		sqlite3_close(db->db);
		val_throw(buffer_to_string(b));
	}
	v = alloc_abstract(k_db,db);
	val_gc(v,free_db);
	return v;
}
static const char *compute_sha1(struct firmware *firmware)
{
	int ret;
	unsigned char hash[SHA_DIGEST_LENGTH];

	if (firmware->sha1[0] == '\0') {
		ret = sha1(firmware, hash);
		if (ret < 0) {
			errno = -ret;
			return NULL;
		}

		buffer_to_string(hash, SHA_DIGEST_LENGTH, firmware->sha1);
	}

	return firmware->sha1;
}
Exemple #22
0
/* includes a newline at the end of the address info */
int addr_info_to_string (struct addr_info * ai, char * buf, int bsize)
{
  int offset = 0;
  offset += snprintf (buf, bsize, "(%d) ", ai->nbits);
  offset += buffer_to_string ((char *) (ai->destination), (ai->nbits + 7) / 8,
                              NULL, ADDRESS_SIZE, 0,
                              buf + offset, bsize - offset);
  offset += snprintf (buf + offset, bsize - offset,
                      ", v %d, port %d, addr ", ai->ip.ip_version,
                      ntohs (ai->ip.port));
  unsigned char * ap = (unsigned char *) &(ai->ip.ip);
  if (ai->ip.ip_version == 4)
    offset += snprintf (buf + offset, bsize - offset,
                        "%d.%d.%d.%d", ap [12], ap [13], ap [14], ap [15]);
  else if ((bsize - offset) >= 42)
    offset += ip6_to_string (ap, buf + offset);
  offset += snprintf (buf + offset, bsize - offset, "\n");
  return offset;
}
Exemple #23
0
/**
	put_env : var:string -> val:string -> void
	<doc>Set some environment variable value</doc>
**/
static value put_env( value e, value v ) {
#ifdef NEKO_WINDOWS
	buffer b;
	val_check(e,string);
	val_check(v,string);
	b = alloc_buffer(NULL);
	val_buffer(b,e);
	buffer_append_sub(b,"=",1);
	val_buffer(b,v);
	if( putenv(val_string(buffer_to_string(b))) != 0 )
		neko_error();
#else
	val_check(e,string);
	val_check(v,string);
	if( setenv(val_string(e),val_string(v),1) != 0 )
		neko_error();
#endif
	return val_true;
}
Exemple #24
0
/**
	socket_read : 'socket -> string
	<doc>Read the whole content of a the data available from a socket until the connection close.
	If the socket hasn't been close by the other side, the function might block.
	</doc>
**/
static value socket_read( value o ) {
	buffer b;
	char buf[256];
	int len;
	val_check_kind(o,k_socket);
	b = alloc_buffer(NULL);
	while( true ) {
		POSIX_LABEL(read_again);
		len = recv(val_sock(o),buf,256,MSG_NOSIGNAL);
		if( len == SOCKET_ERROR ) {
			HANDLE_EINTR(read_again);
			return block_error();
		}
		if( len == 0 )
			break;
		buffer_append_sub(b,buf,len);
	}
	return buffer_to_string(b);
}
/**
	regexp_replace_fun : 'regexp -> from:string -> f:('regexp -> any) -> string
	<doc>Perform a replacement of all matched substrings by calling [f] for every match</doc>
**/
static value regexp_replace_fun( value o, value s, value f ) {
	val_check_kind(o,k_regexp);
	val_check(s,string);
	val_check_function(f,1);
	{
		pcredata *d = PCRE(o);
		buffer b = alloc_buffer(NULL);
		int pos = 0;
		int len = val_strlen(s);
		const char *str = val_string(s);
		d->str = s;
		while( pcre_exec(d->r,NULL,str,len,pos,0,d->matchs,d->nmatchs * 3) >= 0 ) {
			buffer_append_sub(b,str+pos,d->matchs[0] - pos);
			val_buffer(b,val_call1(f,o));
			pos = d->matchs[1];
		}
		d->str = alloc_null();
		buffer_append_sub(b,str+pos,len-pos);
		return buffer_to_string(b);
	}
}
Exemple #26
0
static  value ssl_read( value ssl ) {
	int len, bufsize = 256;
	buffer b;
	unsigned char buf[256];
	mbedtls_ssl_context *ctx;
	val_check_kind(ssl,k_ssl);
	ctx = val_ssl(ssl);
	b = alloc_buffer(NULL);
	while( true ) {
		POSIX_LABEL(read_again);
		len = mbedtls_ssl_read( ctx, buf, bufsize );
		if( len == SOCKET_ERROR ) {
			HANDLE_EINTR(read_again);
			return block_error();
		}
		if( len == 0 )
			break;
		buffer_append_sub(b,(const char *)buf,len);
	}
	return buffer_to_string(b);
}
static value do_replace( value o, value s, value s2, bool all ) {	
	val_check_kind(o,k_regexp);	
	val_check(s,string);
	val_check(s2,string);	
	{
		pcredata *d = PCRE(o);
		buffer b = alloc_buffer(NULL);
		int pos = 0;
		int len = val_strlen(s);
		const char *str = val_string(s);
		const char *str2 = val_string(s2);
		int len2 = val_strlen(s2);
		while( pcre_exec(d->r,NULL,str,len,pos,0,d->matchs,d->nmatchs * 3) >= 0 ) {
			buffer_append_sub(b,str+pos,d->matchs[0] - pos);
			buffer_append_sub(b,str2,len2);
			pos = d->matchs[1];
			if( !all )
				break;
		}
		d->str = alloc_null();
		buffer_append_sub(b,str+pos,len-pos);
		return buffer_to_string(b);
	}
}
Exemple #28
0
/**
	process_run : cmd:string -> args:string array -> 'process
	<doc>
	Start a process using a command and the specified arguments.
	When args is not null, cmd and args will be auto-quoted/escaped.
	If no auto-quoting/escaping is desired, you should append necessary 
	arguments to cmd as if it is inputted to the shell directly, and pass
	null as args.
	</doc>
**/
static value process_run( value cmd, value vargs ) {
	int i, isRaw;
	vprocess *p;
	val_check(cmd,string);
	isRaw = val_is_null(vargs);
	if (!isRaw) {
		val_check(vargs,array);
	}
#	ifdef NEKO_WINDOWS
	{		 
		SECURITY_ATTRIBUTES sattr;		
		STARTUPINFO sinf;
		HANDLE proc = GetCurrentProcess();
		HANDLE oread,eread,iwrite;
		// creates commandline
		buffer b = alloc_buffer(NULL);
		value sargs;
		if (isRaw) {
			char* cmdexe = getenv("COMSPEC");
			if (!cmdexe) cmdexe = "cmd.exe";
			buffer_append(b,"\"");
			buffer_append(b,cmdexe);
			buffer_append(b,"\" /C \"");
			buffer_append(b,val_string(cmd));
			buffer_append_char(b,'"');
		} else {
			buffer_append_char(b,'"');
			val_buffer(b,cmd);
			buffer_append_char(b,'"');
			for(i=0;i<val_array_size(vargs);i++) {
				value v = val_array_ptr(vargs)[i];
				int j,len;
				unsigned int bs_count = 0;
				unsigned int k;
				val_check(v,string);
				len = val_strlen(v);
				buffer_append(b," \"");
				for(j=0;j<len;j++) {
					char c = val_string(v)[j];
					switch( c ) {
					case '"':
						// Double backslashes.
						for (k=0;k<bs_count*2;k++) {
							buffer_append_char(b,'\\');
						}
						bs_count = 0;
						buffer_append(b, "\\\"");
						break;
					case '\\':
						// Don't know if we need to double yet.
						bs_count++;
						break;
					default:
						// Normal char
						for (k=0;k<bs_count;k++) {
							buffer_append_char(b,'\\');
						}
						bs_count = 0;
						buffer_append_char(b,c);
						break;
					}
				}
				// Add remaining backslashes, if any.
				for (k=0;k<bs_count*2;k++) {
					buffer_append_char(b,'\\');
				}
				buffer_append_char(b,'"');
			}
		}
		sargs = buffer_to_string(b);
		p = (vprocess*)alloc_private(sizeof(vprocess));
		// startup process
		sattr.nLength = sizeof(sattr);
		sattr.bInheritHandle = TRUE;
		sattr.lpSecurityDescriptor = NULL;
		memset(&sinf,0,sizeof(sinf));
		sinf.cb = sizeof(sinf);
		sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		sinf.wShowWindow = SW_HIDE;
		CreatePipe(&oread,&sinf.hStdOutput,&sattr,0);
		CreatePipe(&eread,&sinf.hStdError,&sattr,0);
		CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0);
		DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS);
		DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS);
		CloseHandle(oread);
		CloseHandle(eread);
		CloseHandle(iwrite);
		if( !CreateProcess(NULL,val_string(sargs),NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) )			
			neko_error();
		// close unused pipes
		CloseHandle(sinf.hStdOutput);
		CloseHandle(sinf.hStdError);
		CloseHandle(sinf.hStdInput);
	}
#	else
	char **argv;
	if (isRaw) {
		argv = (char**)alloc_private(sizeof(char*)*4);
		argv[0] = "/bin/sh";
		argv[1] = "-c";
		argv[2] = val_string(cmd);
		argv[3] = NULL;
	} else {
		argv = (char**)alloc_private(sizeof(char*)*(val_array_size(vargs)+2));
		argv[0] = val_string(cmd);
		for(i=0;i<val_array_size(vargs);i++) {
			value v = val_array_ptr(vargs)[i];
			val_check(v,string);
			argv[i+1] = val_string(v);
		}
		argv[i+1] = NULL;
	}
	int input[2], output[2], error[2];
	if( pipe(input) || pipe(output) || pipe(error) )
		neko_error();
	p = (vprocess*)alloc_private(sizeof(vprocess));
	p->pid = fork();
	if( p->pid == -1 ) {
		do_close(input[0]);
		do_close(input[1]);
		do_close(output[0]);
		do_close(output[1]);
		do_close(error[0]);
		do_close(error[1]);
		neko_error();
	}
	// child
	if( p->pid == 0 ) {
		close(input[1]);
		close(output[0]);
		close(error[0]);
		dup2(input[0],0);
		dup2(output[1],1);
		dup2(error[1],2);
		execvp(argv[0],argv);
		fprintf(stderr,"Command not found : %s\n",val_string(cmd));
		exit(1);
	}
	// parent
	do_close(input[0]);
	do_close(output[1]);
	do_close(error[1]);
	p->iwrite = input[1];
	p->oread = output[0];
	p->eread = error[0];
#	endif
	{
		value vp = alloc_abstract(k_process,p);
		val_gc(vp,free_process);
		return vp;
	}
}
Exemple #29
0
int
do_parse(request_t* request)
{
    int started = 0;
    int status;
    char* buffer;
    size_t length;
    char* p;
    char* pe;
    int cs;
    int gensaved = 0;
    int urisaved = 0;
    
    do
    {
        // Get a chunk of data to parse.
        status = fill_buffer(request, &buffer, &length);
        if(status < 0 || (status == 0 && started)) return -1;
        if(status == 0) return 0;
        started = 1;

        // If we saved some state in the buffers we need
        // to reinitialize them before resuming parsing.

        if(gensaved) reinit_buffer(request->genbuf, buffer);
        gensaved = 0;
        
        if(urisaved) reinit_buffer(request->uribuf, buffer);
        urisaved = 0;

        // Setup and run the main parse loop saving the
        // parse state afterwards.

        cs = request->cs;
        p = buffer;
        pe = buffer + length;

        
#line 219 "./c_src/request.c"
	{
	if ( p == pe )
		goto _test_eof;
	switch ( cs )
	{
case 1:
	switch( (*p) ) {
		case 36: goto tr0;
		case 95: goto tr0;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto tr0;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto tr0;
	} else
		goto tr0;
	goto st0;
st0:
cs = 0;
	goto _out;
tr0:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st2;
st2:
	if ( ++p == pe )
		goto _test_eof2;
case 2:
#line 253 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st48;
		case 95: goto st48;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st48;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st48;
	} else
		goto st48;
	goto st0;
tr2:
#line 44 "./c_src/request.rl"
	{
        request->method = buffer_to_string(request->genbuf, p);
        if(request->method == NULL) {p++; cs = 3; goto _out;}
    }
	goto st3;
st3:
	if ( ++p == pe )
		goto _test_eof3;
case 3:
#line 280 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr4;
		case 32: goto tr4;
		case 35: goto tr5;
		case 42: goto tr6;
		case 43: goto tr7;
		case 47: goto tr8;
		case 63: goto tr9;
	}
	if ( (*p) < 65 ) {
		if ( 45 <= (*p) && (*p) <= 57 )
			goto tr7;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr7;
	} else
		goto tr7;
	goto st0;
tr4:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 4; goto _out;}
    }
	goto st4;
st4:
	if ( ++p == pe )
		goto _test_eof4;
case 4:
#line 315 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr4;
		case 32: goto tr4;
		case 35: goto tr5;
		case 42: goto tr6;
		case 43: goto tr7;
		case 47: goto tr8;
		case 63: goto tr9;
		case 72: goto tr10;
	}
	if ( (*p) < 65 ) {
		if ( 45 <= (*p) && (*p) <= 57 )
			goto tr7;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr7;
	} else
		goto tr7;
	goto st0;
tr5:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
	goto st5;
tr51:
#line 54 "./c_src/request.rl"
	{
        request->host = buffer_to_string(request->genbuf, p);
        if(request->host == NULL) {p++; cs = 5; goto _out;}
    }
	goto st5;
tr57:
#line 67 "./c_src/request.rl"
	{
        request->path = buffer_to_string(request->genbuf, p);
        if(request->path == NULL) {p++; cs = 5; goto _out;}
    }
	goto st5;
tr63:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
#line 72 "./c_src/request.rl"
	{
        request->query = buffer_to_string(request->genbuf, p);
        if(request->query == NULL) {p++; cs = 5; goto _out;}
    }
	goto st5;
tr67:
#line 72 "./c_src/request.rl"
	{
        request->query = buffer_to_string(request->genbuf, p);
        if(request->query == NULL) {p++; cs = 5; goto _out;}
    }
	goto st5;
tr71:
#line 59 "./c_src/request.rl"
	{
        request->port = 0;
    }
	goto st5;
st5:
	if ( ++p == pe )
		goto _test_eof5;
case 5:
#line 385 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr11;
		case 32: goto tr11;
		case 37: goto tr13;
		case 61: goto tr12;
		case 95: goto tr12;
	}
	if ( (*p) < 44 ) {
		if ( (*p) > 34 ) {
			if ( 36 <= (*p) && (*p) <= 42 )
				goto tr12;
		} else if ( (*p) >= 33 )
			goto tr12;
	} else if ( (*p) > 59 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto tr12;
		} else if ( (*p) >= 64 )
			goto tr12;
	} else
		goto tr12;
	goto st0;
tr11:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
#line 77 "./c_src/request.rl"
	{
        request->fragment = buffer_to_string(request->genbuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr39:
#line 77 "./c_src/request.rl"
	{
        request->fragment = buffer_to_string(request->genbuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr43:
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr50:
#line 54 "./c_src/request.rl"
	{
        request->host = buffer_to_string(request->genbuf, p);
        if(request->host == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr55:
#line 67 "./c_src/request.rl"
	{
        request->path = buffer_to_string(request->genbuf, p);
        if(request->path == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr61:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
#line 72 "./c_src/request.rl"
	{
        request->query = buffer_to_string(request->genbuf, p);
        if(request->query == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr65:
#line 72 "./c_src/request.rl"
	{
        request->query = buffer_to_string(request->genbuf, p);
        if(request->query == NULL) {p++; cs = 6; goto _out;}
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
tr70:
#line 59 "./c_src/request.rl"
	{
        request->port = 0;
    }
#line 87 "./c_src/request.rl"
	{
        request->uri = buffer_to_string(request->uribuf, p);
        if(request->fragment == NULL) {p++; cs = 6; goto _out;}
    }
	goto st6;
st6:
	if ( ++p == pe )
		goto _test_eof6;
case 6:
#line 512 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto st6;
		case 32: goto st6;
		case 72: goto st7;
	}
	goto st0;
st7:
	if ( ++p == pe )
		goto _test_eof7;
case 7:
	if ( (*p) == 84 )
		goto st8;
	goto st0;
st8:
	if ( ++p == pe )
		goto _test_eof8;
case 8:
	if ( (*p) == 84 )
		goto st9;
	goto st0;
st9:
	if ( ++p == pe )
		goto _test_eof9;
case 9:
	if ( (*p) == 80 )
		goto st10;
	goto st0;
st10:
	if ( ++p == pe )
		goto _test_eof10;
case 10:
	if ( (*p) == 47 )
		goto st11;
	goto st0;
st11:
	if ( ++p == pe )
		goto _test_eof11;
case 11:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr20;
	goto st0;
tr20:
#line 92 "./c_src/request.rl"
	{
        request->vsn_major = 0;
    }
#line 96 "./c_src/request.rl"
	{
        request->vsn_major = request->vsn_major*10 + ((*p)-'0');
    }
	goto st12;
tr22:
#line 96 "./c_src/request.rl"
	{
        request->vsn_major = request->vsn_major*10 + ((*p)-'0');
    }
	goto st12;
st12:
	if ( ++p == pe )
		goto _test_eof12;
case 12:
#line 574 "./c_src/request.c"
	if ( (*p) == 46 )
		goto st13;
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr22;
	goto st0;
st13:
	if ( ++p == pe )
		goto _test_eof13;
case 13:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr23;
	goto st0;
tr23:
#line 100 "./c_src/request.rl"
	{
        request->vsn_minor = 0;
    }
#line 104 "./c_src/request.rl"
	{
        request->vsn_minor = request->vsn_minor*10 + ((*p)-'0');
    }
	goto st14;
tr26:
#line 104 "./c_src/request.rl"
	{
        request->vsn_minor = request->vsn_minor*10 + ((*p)-'0');
    }
	goto st14;
st14:
	if ( ++p == pe )
		goto _test_eof14;
case 14:
#line 607 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto st15;
		case 13: goto st16;
		case 32: goto st15;
	}
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr26;
	goto st0;
st15:
	if ( ++p == pe )
		goto _test_eof15;
case 15:
	switch( (*p) ) {
		case 9: goto st15;
		case 13: goto st16;
		case 32: goto st15;
	}
	goto st0;
st16:
	if ( ++p == pe )
		goto _test_eof16;
case 16:
	if ( (*p) == 10 )
		goto st17;
	goto st0;
tr38:
#line 134 "./c_src/request.rl"
	{
        if(*p == ' ' || *p == '\t')
        {
            request->continued = 1;
            p--;
            {goto st20;}
        }
        else if(*p == '\r')
        {
            if(!append_header(request, p)) {p++; cs = 17; goto _out;}
            p--;
            {goto st68;}
        }
        else
        {
            if(!append_header(request, p)) {p++; cs = 17; goto _out;}
            p--;
            {goto st67;}
        }
    }
	goto st17;
st17:
	if ( ++p == pe )
		goto _test_eof17;
case 17:
#line 660 "./c_src/request.c"
	switch( (*p) ) {
		case 13: goto st18;
		case 33: goto tr29;
		case 124: goto tr29;
		case 126: goto tr29;
	}
	if ( (*p) < 45 ) {
		if ( (*p) > 39 ) {
			if ( 42 <= (*p) && (*p) <= 43 )
				goto tr29;
		} else if ( (*p) >= 35 )
			goto tr29;
	} else if ( (*p) > 46 ) {
		if ( (*p) < 65 ) {
			if ( 48 <= (*p) && (*p) <= 57 )
				goto tr29;
		} else if ( (*p) > 90 ) {
			if ( 94 <= (*p) && (*p) <= 122 )
				goto tr29;
		} else
			goto tr29;
	} else
		goto tr29;
	goto st0;
st18:
	if ( ++p == pe )
		goto _test_eof18;
case 18:
	if ( (*p) == 10 )
		goto tr30;
	goto st0;
tr30:
#line 155 "./c_src/request.rl"
	{
        build_version(request);
        {p++; cs = 69; goto _out;}
    }
	goto st69;
st69:
	if ( ++p == pe )
		goto _test_eof69;
case 69:
#line 703 "./c_src/request.c"
	goto st0;
tr29:
#line 108 "./c_src/request.rl"
	{
        assert(request->hdr_name == NULL && "header name already marked");        
        assert(request->genbuf->pos == NULL && "wont overwrite a mark");
        request->genbuf->pos = p;
    }
	goto st19;
st19:
	if ( ++p == pe )
		goto _test_eof19;
case 19:
#line 717 "./c_src/request.c"
	switch( (*p) ) {
		case 33: goto st19;
		case 58: goto tr32;
		case 124: goto st19;
		case 126: goto st19;
	}
	if ( (*p) < 45 ) {
		if ( (*p) > 39 ) {
			if ( 42 <= (*p) && (*p) <= 43 )
				goto st19;
		} else if ( (*p) >= 35 )
			goto st19;
	} else if ( (*p) > 46 ) {
		if ( (*p) < 65 ) {
			if ( 48 <= (*p) && (*p) <= 57 )
				goto st19;
		} else if ( (*p) > 90 ) {
			if ( 94 <= (*p) && (*p) <= 122 )
				goto st19;
		} else
			goto st19;
	} else
		goto st19;
	goto st0;
tr32:
#line 114 "./c_src/request.rl"
	{
        request->hdr_name = buffer_to_string(request->genbuf, p);
        if(request->hdr_name == NULL) {p++; cs = 20; goto _out;}
    }
	goto st20;
st20:
	if ( ++p == pe )
		goto _test_eof20;
case 20:
#line 753 "./c_src/request.c"
	if ( (*p) == 13 )
		goto tr34;
	goto tr33;
tr33:
#line 119 "./c_src/request.rl"
	{
        assert(request->hdr_name != NULL && "value must have a name");
        assert(request->continued ||
                    (request->genbuf->pos == NULL && "wont overwrite a mark"));
        
        if(request->continued)
        {
            request->continued = 1;
        }
        else
        {
            request->genbuf->pos = p;
        }
    }
	goto st21;
st21:
	if ( ++p == pe )
		goto _test_eof21;
case 21:
#line 778 "./c_src/request.c"
	if ( (*p) == 13 )
		goto st22;
	goto st21;
tr34:
#line 119 "./c_src/request.rl"
	{
        assert(request->hdr_name != NULL && "value must have a name");
        assert(request->continued ||
                    (request->genbuf->pos == NULL && "wont overwrite a mark"));
        
        if(request->continued)
        {
            request->continued = 1;
        }
        else
        {
            request->genbuf->pos = p;
        }
    }
	goto st22;
st22:
	if ( ++p == pe )
		goto _test_eof22;
case 22:
#line 803 "./c_src/request.c"
	if ( (*p) == 10 )
		goto st23;
	goto st0;
st23:
	if ( ++p == pe )
		goto _test_eof23;
case 23:
	goto tr38;
tr12:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st24;
st24:
	if ( ++p == pe )
		goto _test_eof24;
case 24:
#line 823 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr39;
		case 32: goto tr39;
		case 37: goto st25;
		case 61: goto st24;
		case 95: goto st24;
	}
	if ( (*p) < 44 ) {
		if ( (*p) > 34 ) {
			if ( 36 <= (*p) && (*p) <= 42 )
				goto st24;
		} else if ( (*p) >= 33 )
			goto st24;
	} else if ( (*p) > 59 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st24;
		} else if ( (*p) >= 64 )
			goto st24;
	} else
		goto st24;
	goto st0;
tr13:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st25;
st25:
	if ( ++p == pe )
		goto _test_eof25;
case 25:
#line 857 "./c_src/request.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st26;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st26;
	} else
		goto st26;
	goto st0;
st26:
	if ( ++p == pe )
		goto _test_eof26;
case 26:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st24;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st24;
	} else
		goto st24;
	goto st0;
tr6:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
	goto st27;
st27:
	if ( ++p == pe )
		goto _test_eof27;
case 27:
#line 891 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr43;
		case 32: goto tr43;
	}
	goto st0;
tr7:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st28;
st28:
	if ( ++p == pe )
		goto _test_eof28;
case 28:
#line 913 "./c_src/request.c"
	switch( (*p) ) {
		case 43: goto st28;
		case 58: goto tr45;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st28;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st28;
		} else if ( (*p) >= 65 )
			goto st28;
	} else
		goto st28;
	goto st0;
tr45:
#line 49 "./c_src/request.rl"
	{
        request->scheme = buffer_to_string(request->genbuf, p);
        if(request->scheme == NULL) {p++; cs = 29; goto _out;}
    }
	goto st29;
st29:
	if ( ++p == pe )
		goto _test_eof29;
case 29:
#line 941 "./c_src/request.c"
	if ( (*p) == 47 )
		goto st30;
	goto st0;
st30:
	if ( ++p == pe )
		goto _test_eof30;
case 30:
	if ( (*p) == 47 )
		goto st31;
	goto st0;
st31:
	if ( ++p == pe )
		goto _test_eof31;
case 31:
	switch( (*p) ) {
		case 33: goto tr48;
		case 37: goto tr49;
		case 59: goto tr48;
		case 61: goto tr48;
		case 63: goto tr48;
		case 95: goto tr48;
	}
	if ( (*p) < 48 ) {
		if ( (*p) > 42 ) {
			if ( 44 <= (*p) && (*p) <= 46 )
				goto tr48;
		} else if ( (*p) >= 36 )
			goto tr48;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto tr48;
		} else if ( (*p) >= 65 )
			goto tr48;
	} else
		goto tr48;
	goto st0;
tr48:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st32;
st32:
	if ( ++p == pe )
		goto _test_eof32;
case 32:
#line 990 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr50;
		case 32: goto tr50;
		case 35: goto tr51;
		case 47: goto tr52;
		case 58: goto tr53;
		case 63: goto tr54;
	}
	goto st0;
tr76:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st33;
tr8:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st33;
tr52:
#line 54 "./c_src/request.rl"
	{
        request->host = buffer_to_string(request->genbuf, p);
        if(request->host == NULL) {p++; cs = 33; goto _out;}
    }
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st33;
tr72:
#line 59 "./c_src/request.rl"
	{
        request->port = 0;
    }
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st33;
st33:
	if ( ++p == pe )
		goto _test_eof33;
case 33:
#line 1046 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr55;
		case 32: goto tr55;
		case 35: goto tr57;
		case 37: goto st34;
		case 61: goto st33;
		case 63: goto tr59;
		case 95: goto st33;
	}
	if ( (*p) < 44 ) {
		if ( 33 <= (*p) && (*p) <= 42 )
			goto st33;
	} else if ( (*p) > 59 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st33;
		} else if ( (*p) >= 64 )
			goto st33;
	} else
		goto st33;
	goto st0;
st34:
	if ( ++p == pe )
		goto _test_eof34;
case 34:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st35;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st35;
	} else
		goto st35;
	goto st0;
st35:
	if ( ++p == pe )
		goto _test_eof35;
case 35:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st33;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st33;
	} else
		goto st33;
	goto st0;
tr9:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
	goto st36;
tr54:
#line 54 "./c_src/request.rl"
	{
        request->host = buffer_to_string(request->genbuf, p);
        if(request->host == NULL) {p++; cs = 36; goto _out;}
    }
	goto st36;
tr59:
#line 67 "./c_src/request.rl"
	{
        request->path = buffer_to_string(request->genbuf, p);
        if(request->path == NULL) {p++; cs = 36; goto _out;}
    }
	goto st36;
tr74:
#line 59 "./c_src/request.rl"
	{
        request->port = 0;
    }
	goto st36;
st36:
	if ( ++p == pe )
		goto _test_eof36;
case 36:
#line 1125 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr61;
		case 32: goto tr61;
		case 35: goto tr63;
		case 37: goto tr64;
		case 61: goto tr62;
		case 95: goto tr62;
	}
	if ( (*p) < 44 ) {
		if ( 33 <= (*p) && (*p) <= 42 )
			goto tr62;
	} else if ( (*p) > 59 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto tr62;
		} else if ( (*p) >= 64 )
			goto tr62;
	} else
		goto tr62;
	goto st0;
tr62:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st37;
st37:
	if ( ++p == pe )
		goto _test_eof37;
case 37:
#line 1157 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr65;
		case 32: goto tr65;
		case 35: goto tr67;
		case 37: goto st38;
		case 61: goto st37;
		case 95: goto st37;
	}
	if ( (*p) < 44 ) {
		if ( 33 <= (*p) && (*p) <= 42 )
			goto st37;
	} else if ( (*p) > 59 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st37;
		} else if ( (*p) >= 64 )
			goto st37;
	} else
		goto st37;
	goto st0;
tr64:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st38;
st38:
	if ( ++p == pe )
		goto _test_eof38;
case 38:
#line 1189 "./c_src/request.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st39;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st39;
	} else
		goto st39;
	goto st0;
st39:
	if ( ++p == pe )
		goto _test_eof39;
case 39:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st37;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st37;
	} else
		goto st37;
	goto st0;
tr53:
#line 54 "./c_src/request.rl"
	{
        request->host = buffer_to_string(request->genbuf, p);
        if(request->host == NULL) {p++; cs = 40; goto _out;}
    }
	goto st40;
st40:
	if ( ++p == pe )
		goto _test_eof40;
case 40:
#line 1223 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr70;
		case 32: goto tr70;
		case 35: goto tr71;
		case 47: goto tr72;
		case 63: goto tr74;
	}
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr73;
	goto st0;
tr73:
#line 59 "./c_src/request.rl"
	{
        request->port = 0;
    }
#line 63 "./c_src/request.rl"
	{
        request->port = request->port*10 + ((*p)-'0');
    }
	goto st41;
tr77:
#line 63 "./c_src/request.rl"
	{
        request->port = request->port*10 + ((*p)-'0');
    }
	goto st41;
st41:
	if ( ++p == pe )
		goto _test_eof41;
case 41:
#line 1254 "./c_src/request.c"
	switch( (*p) ) {
		case 9: goto tr43;
		case 32: goto tr43;
		case 35: goto st5;
		case 47: goto tr76;
		case 63: goto st36;
	}
	if ( 48 <= (*p) && (*p) <= 57 )
		goto tr77;
	goto st0;
tr49:
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st42;
st42:
	if ( ++p == pe )
		goto _test_eof42;
case 42:
#line 1276 "./c_src/request.c"
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st43;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st43;
	} else
		goto st43;
	goto st0;
st43:
	if ( ++p == pe )
		goto _test_eof43;
case 43:
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st32;
	} else if ( (*p) > 70 ) {
		if ( 97 <= (*p) && (*p) <= 102 )
			goto st32;
	} else
		goto st32;
	goto st0;
tr10:
#line 82 "./c_src/request.rl"
	{
        assert(request->uribuf->pos == NULL && "wont overwrite uri mark");
        request->uribuf->pos = p;
    }
#line 39 "./c_src/request.rl"
	{
        assert(request->genbuf->pos == NULL && "won't overwrite a mark.");
        request->genbuf->pos = p;
    }
	goto st44;
st44:
	if ( ++p == pe )
		goto _test_eof44;
case 44:
#line 1315 "./c_src/request.c"
	switch( (*p) ) {
		case 43: goto st28;
		case 58: goto tr45;
		case 84: goto st45;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st28;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st28;
		} else if ( (*p) >= 65 )
			goto st28;
	} else
		goto st28;
	goto st0;
st45:
	if ( ++p == pe )
		goto _test_eof45;
case 45:
	switch( (*p) ) {
		case 43: goto st28;
		case 58: goto tr45;
		case 84: goto st46;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st28;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st28;
		} else if ( (*p) >= 65 )
			goto st28;
	} else
		goto st28;
	goto st0;
st46:
	if ( ++p == pe )
		goto _test_eof46;
case 46:
	switch( (*p) ) {
		case 43: goto st28;
		case 58: goto tr45;
		case 80: goto st47;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st28;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st28;
		} else if ( (*p) >= 65 )
			goto st28;
	} else
		goto st28;
	goto st0;
st47:
	if ( ++p == pe )
		goto _test_eof47;
case 47:
	switch( (*p) ) {
		case 43: goto st28;
		case 47: goto st11;
		case 58: goto tr45;
	}
	if ( (*p) < 65 ) {
		if ( 45 <= (*p) && (*p) <= 57 )
			goto st28;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st28;
	} else
		goto st28;
	goto st0;
st48:
	if ( ++p == pe )
		goto _test_eof48;
case 48:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st49;
		case 95: goto st49;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st49;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st49;
	} else
		goto st49;
	goto st0;
st49:
	if ( ++p == pe )
		goto _test_eof49;
case 49:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st50;
		case 95: goto st50;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st50;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st50;
	} else
		goto st50;
	goto st0;
st50:
	if ( ++p == pe )
		goto _test_eof50;
case 50:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st51;
		case 95: goto st51;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st51;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st51;
	} else
		goto st51;
	goto st0;
st51:
	if ( ++p == pe )
		goto _test_eof51;
case 51:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st52;
		case 95: goto st52;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st52;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st52;
	} else
		goto st52;
	goto st0;
st52:
	if ( ++p == pe )
		goto _test_eof52;
case 52:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st53;
		case 95: goto st53;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st53;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st53;
	} else
		goto st53;
	goto st0;
st53:
	if ( ++p == pe )
		goto _test_eof53;
case 53:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st54;
		case 95: goto st54;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st54;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st54;
	} else
		goto st54;
	goto st0;
st54:
	if ( ++p == pe )
		goto _test_eof54;
case 54:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st55;
		case 95: goto st55;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st55;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st55;
	} else
		goto st55;
	goto st0;
st55:
	if ( ++p == pe )
		goto _test_eof55;
case 55:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st56;
		case 95: goto st56;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st56;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st56;
	} else
		goto st56;
	goto st0;
st56:
	if ( ++p == pe )
		goto _test_eof56;
case 56:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st57;
		case 95: goto st57;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st57;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st57;
	} else
		goto st57;
	goto st0;
st57:
	if ( ++p == pe )
		goto _test_eof57;
case 57:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st58;
		case 95: goto st58;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st58;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st58;
	} else
		goto st58;
	goto st0;
st58:
	if ( ++p == pe )
		goto _test_eof58;
case 58:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st59;
		case 95: goto st59;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st59;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st59;
	} else
		goto st59;
	goto st0;
st59:
	if ( ++p == pe )
		goto _test_eof59;
case 59:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st60;
		case 95: goto st60;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st60;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st60;
	} else
		goto st60;
	goto st0;
st60:
	if ( ++p == pe )
		goto _test_eof60;
case 60:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st61;
		case 95: goto st61;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st61;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st61;
	} else
		goto st61;
	goto st0;
st61:
	if ( ++p == pe )
		goto _test_eof61;
case 61:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st62;
		case 95: goto st62;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st62;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st62;
	} else
		goto st62;
	goto st0;
st62:
	if ( ++p == pe )
		goto _test_eof62;
case 62:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st63;
		case 95: goto st63;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st63;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st63;
	} else
		goto st63;
	goto st0;
st63:
	if ( ++p == pe )
		goto _test_eof63;
case 63:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st64;
		case 95: goto st64;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st64;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st64;
	} else
		goto st64;
	goto st0;
st64:
	if ( ++p == pe )
		goto _test_eof64;
case 64:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st65;
		case 95: goto st65;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st65;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st65;
	} else
		goto st65;
	goto st0;
st65:
	if ( ++p == pe )
		goto _test_eof65;
case 65:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
		case 36: goto st66;
		case 95: goto st66;
	}
	if ( (*p) < 48 ) {
		if ( 45 <= (*p) && (*p) <= 46 )
			goto st66;
	} else if ( (*p) > 57 ) {
		if ( 65 <= (*p) && (*p) <= 90 )
			goto st66;
	} else
		goto st66;
	goto st0;
st66:
	if ( ++p == pe )
		goto _test_eof66;
case 66:
	switch( (*p) ) {
		case 9: goto tr2;
		case 32: goto tr2;
	}
	goto st0;
st67:
	if ( ++p == pe )
		goto _test_eof67;
case 67:
	switch( (*p) ) {
		case 33: goto tr29;
		case 124: goto tr29;
		case 126: goto tr29;
	}
	if ( (*p) < 45 ) {
		if ( (*p) > 39 ) {
			if ( 42 <= (*p) && (*p) <= 43 )
				goto tr29;
		} else if ( (*p) >= 35 )
			goto tr29;
	} else if ( (*p) > 46 ) {
		if ( (*p) < 65 ) {
			if ( 48 <= (*p) && (*p) <= 57 )
				goto tr29;
		} else if ( (*p) > 90 ) {
			if ( 94 <= (*p) && (*p) <= 122 )
				goto tr29;
		} else
			goto tr29;
	} else
		goto tr29;
	goto st0;
st68:
	if ( ++p == pe )
		goto _test_eof68;
case 68:
	if ( (*p) == 13 )
		goto st18;
	goto st0;
	}
	_test_eof2: cs = 2; goto _test_eof; 
	_test_eof3: cs = 3; goto _test_eof; 
	_test_eof4: cs = 4; goto _test_eof; 
	_test_eof5: cs = 5; goto _test_eof; 
	_test_eof6: cs = 6; goto _test_eof; 
	_test_eof7: cs = 7; goto _test_eof; 
	_test_eof8: cs = 8; goto _test_eof; 
	_test_eof9: cs = 9; goto _test_eof; 
	_test_eof10: cs = 10; goto _test_eof; 
	_test_eof11: cs = 11; goto _test_eof; 
	_test_eof12: cs = 12; goto _test_eof; 
	_test_eof13: cs = 13; goto _test_eof; 
	_test_eof14: cs = 14; goto _test_eof; 
	_test_eof15: cs = 15; goto _test_eof; 
	_test_eof16: cs = 16; goto _test_eof; 
	_test_eof17: cs = 17; goto _test_eof; 
	_test_eof18: cs = 18; goto _test_eof; 
	_test_eof69: cs = 69; goto _test_eof; 
	_test_eof19: cs = 19; goto _test_eof; 
	_test_eof20: cs = 20; goto _test_eof; 
	_test_eof21: cs = 21; goto _test_eof; 
	_test_eof22: cs = 22; goto _test_eof; 
	_test_eof23: cs = 23; goto _test_eof; 
	_test_eof24: cs = 24; goto _test_eof; 
	_test_eof25: cs = 25; goto _test_eof; 
	_test_eof26: cs = 26; goto _test_eof; 
	_test_eof27: cs = 27; goto _test_eof; 
	_test_eof28: cs = 28; goto _test_eof; 
	_test_eof29: cs = 29; goto _test_eof; 
	_test_eof30: cs = 30; goto _test_eof; 
	_test_eof31: cs = 31; goto _test_eof; 
	_test_eof32: cs = 32; goto _test_eof; 
	_test_eof33: cs = 33; goto _test_eof; 
	_test_eof34: cs = 34; goto _test_eof; 
	_test_eof35: cs = 35; goto _test_eof; 
	_test_eof36: cs = 36; goto _test_eof; 
	_test_eof37: cs = 37; goto _test_eof; 
	_test_eof38: cs = 38; goto _test_eof; 
	_test_eof39: cs = 39; goto _test_eof; 
	_test_eof40: cs = 40; goto _test_eof; 
	_test_eof41: cs = 41; goto _test_eof; 
	_test_eof42: cs = 42; goto _test_eof; 
	_test_eof43: cs = 43; goto _test_eof; 
	_test_eof44: cs = 44; goto _test_eof; 
	_test_eof45: cs = 45; goto _test_eof; 
	_test_eof46: cs = 46; goto _test_eof; 
	_test_eof47: cs = 47; goto _test_eof; 
	_test_eof48: cs = 48; goto _test_eof; 
	_test_eof49: cs = 49; goto _test_eof; 
	_test_eof50: cs = 50; goto _test_eof; 
	_test_eof51: cs = 51; goto _test_eof; 
	_test_eof52: cs = 52; goto _test_eof; 
	_test_eof53: cs = 53; goto _test_eof; 
	_test_eof54: cs = 54; goto _test_eof; 
	_test_eof55: cs = 55; goto _test_eof; 
	_test_eof56: cs = 56; goto _test_eof; 
	_test_eof57: cs = 57; goto _test_eof; 
	_test_eof58: cs = 58; goto _test_eof; 
	_test_eof59: cs = 59; goto _test_eof; 
	_test_eof60: cs = 60; goto _test_eof; 
	_test_eof61: cs = 61; goto _test_eof; 
	_test_eof62: cs = 62; goto _test_eof; 
	_test_eof63: cs = 63; goto _test_eof; 
	_test_eof64: cs = 64; goto _test_eof; 
	_test_eof65: cs = 65; goto _test_eof; 
	_test_eof66: cs = 66; goto _test_eof; 
	_test_eof67: cs = 67; goto _test_eof; 
	_test_eof68: cs = 68; goto _test_eof; 

	_test_eof: {}
	_out: {}
	}

#line 329 "./c_src/request.rl"

        if(PyErr_Occurred())
        {
            return -1;
        }

        request->cs = cs;
        request->nread += p - buffer;
        
        if(p < pe) save_chunk(request, p, pe-p);
        
        // Parsing stopped in the middle of a buffer
        // state. Save the current data and prepare
        // for reinitialization.
        
        gensaved = request->genbuf->pos ? 1 : 0;
        if(gensaved) save_buffer(request->genbuf, p);
        
        urisaved = request->uribuf->pos ? 1 : 0;
        if(urisaved) save_buffer(request->uribuf, p);

    } while(cs != http_req_parser_error && cs < http_req_parser_first_final);

    if(cs == http_req_parser_error)
    {
        if(!PyErr_Occurred())
        {
            // MAKE MOAR BUTTAH
            PyErr_SetString(PyExc_ValueError, "Failed to parse data stream.");
            return -1;
        }
    }

    return 1;
}
Exemple #30
0
// Returns 0 if the call succeeded and non-zero otherwise. If the call
// succeeded, the result is stored in "result" providing that the result is an
// integer or a buffer containing 4 values
static int acpi_call_dsm(acpi_handle handle, const char muid[16], int revid,
    int func, char args[4], uint32_t *result) {
    struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
    struct acpi_object_list input;
    union acpi_object params[4];
    union acpi_object *obj;
    int err;

    input.count = 4;
    input.pointer = params;
    params[0].type = ACPI_TYPE_BUFFER;
    params[0].buffer.length = 16;
    params[0].buffer.pointer = (char *)muid;
    params[1].type = ACPI_TYPE_INTEGER;
    params[1].integer.value = revid;
    params[2].type = ACPI_TYPE_INTEGER;
    params[2].integer.value = func;
    params[3].type = ACPI_TYPE_BUFFER;
    params[3].buffer.length = 4;
    if (args) {
        params[3].buffer.pointer = args;
    } else {
        // Some implementations (Asus U36SD) seem to check the args before the
        // function ID and crash if it is not a buffer.
        params[3].buffer.pointer = (char[4]){0, 0, 0, 0};
    }

    err = acpi_evaluate_object(handle, "_DSM", &input, &output);
    if (err) {
        struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
        char muid_str[5 * 16];
        char args_str[5 * 4];

        acpi_get_name(handle, ACPI_FULL_PATHNAME, &buf);

        pr_warn("failed to evaluate %s._DSM {%s} 0x%X 0x%X {%s}: %s\n",
            (char *)buf.pointer,
            buffer_to_string(muid, 16, muid_str), revid, func,
            buffer_to_string(args,  4, args_str), acpi_format_exception(err));
        return err;
    }

    obj = (union acpi_object *)output.pointer;

    if (obj->type == ACPI_TYPE_INTEGER && result) {
        *result = obj->integer.value;
    } else if (obj->type == ACPI_TYPE_BUFFER) {
        if (obj->buffer.length == 4 && result) {
            *result = 0;
            *result |= obj->buffer.pointer[0];
            *result |= (obj->buffer.pointer[1] << 8);
            *result |= (obj->buffer.pointer[2] << 16);
            *result |= (obj->buffer.pointer[3] << 24);
        }
    } else {
        pr_warn("_DSM call yields an unsupported result type: %#x\n",
            obj->type);
    }

    kfree(output.pointer);
    return 0;
}

// Returns 1 if a _DSM function and its function index exists and 0 otherwise
static int has_dsm_func(const char muid[16], int revid, int sfnc) {
    u32 result = 0;

    // fail if the _DSM call failed
    if (acpi_call_dsm(dis_handle, muid, revid, 0, 0, &result))
        return 0;

    // ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported. If
    // the n-th bit is enabled, function n is supported
    return result & 1 && result & (1 << sfnc);
}