コード例 #1
0
ファイル: ngstream_webserv_impl.c プロジェクト: spchamp/ilu
static void FreeDataSourceObjectData(DataSourceObjectData* p_object_data) {
	
	ilu_Error an_error;
	CORBA_Environment ilu_env;
	
	if (p_object_data->m_state_change_condition)
		ilu_DestroyCondition(p_object_data->m_state_change_condition);

	if (p_object_data->m_access_mutex) {
		ilu_DestroyMutex(p_object_data->m_access_mutex, &an_error);
		if (ILU_ERRNOK(an_error)) {
			ILU_HANDLED(an_error);
			ILU_CLER(an_error);
		}
	}
	if (p_object_data->m_renderSink) {
		CORBA_Object_release(p_object_data->m_renderSink, &ilu_env);
		log_and_clear_if_exception(&ilu_env, "CORBA_Object_release problem");
	}

	if (p_object_data->m_pipeline) {
		ILU_C_ReleasePipeline(p_object_data->m_pipeline, &ilu_env);
		log_and_clear_if_exception(&ilu_env, "Calling ILU_C_ReleasePipeline");
		ILU_C_SetPipelineContext(NULL); 
	}
	
	CLOSE_FUNCTION(p_object_data->m_h_native_content_file);
	ilu_free(p_object_data->m_pc_object_id);	
	ilu_free(p_object_data);
}
コード例 #2
0
ファイル: iluhttp_webserv_impl.c プロジェクト: spchamp/ilu
iluhttp_Response* server_iluhttp_Resource_POST (iluhttp_Resource http_obj, 
												   iluhttp_Request* p_http_req, 
												   ILU_C_ENVIRONMENT* ilu_env) {
	char c_filename[2048];			/* holds the name of of the referenced file */
	int h_file;						/* for obtaining file information */
	STAT_STRUCT stat_struct;
	char* pc_walker;
	char* pc_extension;				/* points to file extension */
	iluhttp_Response* p_the_response;	/* for building up our response */
	
	/* log appropriately */
	if (DO_LOG_FULL()) {
		LOG_ENTER();
		fprintf(g_p_logfile, "\n------------------------------------------\n");
		fprintf(g_p_logfile, "POST called on %s\n", p_http_req->URI);
		nglib_print_iluhttp_request (p_http_req, g_p_logfile);	
		LOG_EXIT();
	}

	if (g_batcher) /* ensure batching if appropriate */
		ILU_C_SetBatcherContext(g_batcher); 

	/* make up the full file name, defaulting to the default file name if necessary */
	if (strcmp(p_http_req->URI, "/") == 0) /*  */
		sprintf(c_filename, "%s%s", g_pc_file_base, DEFAULT_SERVER_FILE_NAME);
	else
		sprintf(c_filename, "%s%s", g_pc_file_base, p_http_req->URI);

	/* terminate properly if params or queries are present*/
	pc_walker = c_filename;
	while (*pc_walker && (*pc_walker != ';') && (*pc_walker != '?'))
		pc_walker++;
	*pc_walker = '\0';

	if (nglib_validate_path(c_filename, g_pc_file_base) == ilu_FALSE) {
		/* return not found if we've gone outside our root */
		return build_simple_response(iluhttp_NotFound, NULL, 0);
	}

	/* open up the file */
	h_file = OPEN_FUNCTION(c_filename, RDONLY_MODE); 
	if ((h_file == -1) || (FSTAT_FUNCTION(h_file, &stat_struct) == -1)) {
		/* return not found if there's a problem opening the file */
		return build_simple_response(iluhttp_NotFound, NULL, 0);
	}
	
	/* close the file */
	CLOSE_FUNCTION(h_file);

	/* determine file extension */
	pc_extension = c_filename + strlen(c_filename) - 1;
	while (pc_extension > c_filename) {
		if (*pc_extension == '.') {
			pc_extension++;
			break;
		}
		pc_extension--;
	}

	if (pc_extension == c_filename)  /* ensure we didn't walk all the way back */
		pc_extension = NULL;

	if (pc_extension && strcmp(pc_extension, "iluhttpresponse") == 0) {
		/* it's a file containing the complete response to send back */
		
		p_the_response = build_response_from_file(c_filename, ilu_TRUE);

		if (!p_the_response)  /* if had an error - respond appropriate error iluhttp_NoContent? */
			return  build_simple_response(iluhttp_NoContent, NULL, 0);

		/* return the response the file contained */
		return p_the_response;
	}


	return build_simple_response(iluhttp_NotImplemented, "POST not implemented", 0);
}
コード例 #3
0
ファイル: io.c プロジェクト: dgarske/nucleus_port
int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
                        byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
{
    SOCKET_T sfd = 0;
    word16   port;
    int      ret = -1;
#ifdef WOLFSSL_SMALL_STACK
    char*    path;
    char*    domainName;
#else
    char     path[80];
    char     domainName[80];
#endif

#ifdef WOLFSSL_SMALL_STACK
    path = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER);
    if (path == NULL)
        return -1;
    
    domainName = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER);
    if (domainName == NULL) {
        XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER);
        return -1;
    }
#endif

    (void)ctx;

    if (ocspReqBuf == NULL || ocspReqSz == 0) {
        WOLFSSL_MSG("OCSP request is required for lookup");
    }
    else if (ocspRespBuf == NULL) {
        WOLFSSL_MSG("Cannot save OCSP response");
    }
    else if (decode_url(url, urlSz, domainName, path, &port) < 0) {
        WOLFSSL_MSG("Unable to decode OCSP URL");
    }
    else {
        /* Note, the library uses the EmbedOcspRespFree() callback to
         * free this buffer. */
        int   httpBufSz = SCRATCH_BUFFER_SIZE;
        byte* httpBuf   = (byte*)XMALLOC(httpBufSz, NULL,
                                                        DYNAMIC_TYPE_OCSP);

        if (httpBuf == NULL) {
            WOLFSSL_MSG("Unable to create OCSP response buffer");
        }
        else {
            httpBufSz = build_http_request(domainName, path, ocspReqSz,
                                                            httpBuf, httpBufSz);

            if ((tcp_connect(&sfd, domainName, port) != 0) || (sfd <= 0)) {
                WOLFSSL_MSG("OCSP Responder connection failed");
            }
            else if ((int)SEND_FUNCTION(sfd, (char*)httpBuf, httpBufSz, 0) !=
                                                                    httpBufSz) {
                WOLFSSL_MSG("OCSP http request failed");
            }
            else if ((int)SEND_FUNCTION(sfd, (char*)ocspReqBuf, ocspReqSz, 0) !=
                                                                    ocspReqSz) {
                WOLFSSL_MSG("OCSP ocsp request failed");
            }
            else {
                ret = process_http_response(sfd, ocspRespBuf, httpBuf,
                                                           SCRATCH_BUFFER_SIZE);
            }

            CLOSE_FUNCTION(sfd);
            XFREE(httpBuf, NULL, DYNAMIC_TYPE_OCSP);
        }
    }

#ifdef WOLFSSL_SMALL_STACK
    XFREE(path,       NULL, DYNAMIC_TYPE_TMP_BUFFER);
    XFREE(domainName, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif

    return ret;
}
コード例 #4
0
ファイル: iluhttp_webserv_impl.c プロジェクト: spchamp/ilu
iluhttp_Response* server_iluhttp_Resource_GETorHEAD (iluhttp_Resource http_obj, 
												  iluhttp_Request* p_http_req,
												  ilu_boolean b_include_body,
												  ILU_C_ENVIRONMENT* ilu_env) {

	char c_filename[2048];			/* holds the name of of the referenced file */
	int h_file;						/* for obtaining file information */
	STAT_STRUCT stat_struct;
	char c_buffer[256];				/* temporary and utility */
	char* pc_walker;
	char* pc_type_string;			/* points to MIME type string */
	char* pc_extension;				/* points to file extension */
	ilu_bytes pc_body_bytes;		/* points to body buffer */
	iluhttp_Response* p_the_response;	/* for building up our response */
	iluhttp_Header* p_header;

	/* make up the full file name, defaulting to the default file name if necessary */
	if (strcmp(p_http_req->URI, "/") == 0) /*  */
		sprintf(c_filename, "%s%s", g_pc_file_base, DEFAULT_SERVER_FILE_NAME);
	else
		sprintf(c_filename, "%s%s", g_pc_file_base, p_http_req->URI);

	/* terminate properly if params or queries are present*/
	pc_walker = c_filename;
	while (*pc_walker && (*pc_walker != ';') && (*pc_walker != '?'))
		pc_walker++;
	*pc_walker = '\0';

	if (nglib_validate_path(c_filename, g_pc_file_base) == ilu_FALSE) {
		/* return not found if we've gone outside our root */
		return build_simple_response(iluhttp_NotFound, NULL, 0);
	}

	/* open up the file */
	h_file = OPEN_FUNCTION(c_filename, RDONLY_MODE); 
	if ((h_file == -1) || (FSTAT_FUNCTION(h_file, &stat_struct) == -1)) {
		/* return not found if there's a problem opening the file */
		return build_simple_response(iluhttp_NotFound, NULL, 0);
	}

	/* determine file extension */
	pc_extension = c_filename + strlen(c_filename) - 1;
	while (pc_extension > c_filename) {
		if (*pc_extension == '.') {
			pc_extension++;
			break;
		}
		pc_extension--;
	}

	if (pc_extension == c_filename)  /* ensure we didn't walk all the way back */
		pc_extension = NULL;


	if (pc_extension && strcmp(pc_extension, "iluhttpresponse") == 0) {
		/* it's a file containing the complete response to send back */
		
		/* close the file */
		CLOSE_FUNCTION(h_file);
		
		p_the_response = build_response_from_file(c_filename, b_include_body);

		if (!p_the_response)  /* if had an error - respond appropriate error iluhttp_NoContent? */
			return  build_simple_response(iluhttp_NoContent, NULL, 0);

		/* return the response the file contained */
		return p_the_response;
	}


	 /* build up our response */
	p_the_response = (iluhttp_Response*) ilu_malloc(sizeof(iluhttp_Response));	/* create empty response */

	p_the_response->status = iluhttp_OK;	/* set it to indicate success */ 

	/* create space for headers */
	p_the_response->headers._buffer = (iluhttp_Header*) ilu_malloc(5*sizeof(iluhttp_Header));
	p_the_response->headers._maximum = 5;
	p_the_response->headers._length = 5;
	p_header = p_the_response->headers._buffer;

	p_header->name = nglib_duplicate_c_string("Date");		/* make a General header containing Date */
	p_header->value = nglib_get_current_time_string();
	p_header++;

	p_header->name = nglib_duplicate_c_string("Server");			/* create Server header */
	p_header->value = nglib_duplicate_c_string("HTTPNG-Object-Server/1.0");
	p_header++;

	p_header->name = nglib_duplicate_c_string("Content-Length");	/* create Content-Length header */
	sprintf(c_buffer, "%ld", stat_struct.st_size);
	p_header->value = nglib_duplicate_c_string(c_buffer);
	p_header++;

	p_header->name = nglib_duplicate_c_string("Last-Modified");	/* create Last-Modified header */
	p_header->value = nglib_get_time_string(&(stat_struct.st_mtime));
	p_header++;

	if ((pc_extension != NULL) &&		/* create Content-Type header if known */
		(pc_type_string = nglib_content_type_from_extension(pc_extension)) != NULL) {
		p_header->name = nglib_duplicate_c_string("Content-Type");
		p_header->value = nglib_duplicate_c_string(pc_type_string);
	}
	else {	/* forget about content-type - we don't know */
		p_the_response->headers._maximum = 4;
		p_the_response->headers._length = 4;
	}

	if (b_include_body) { /* if we should add the body */
		/* get a buffer of the file contents */
		pc_body_bytes = ilu_malloc(stat_struct.st_size);
		READ_FUNCTION(h_file, pc_body_bytes, stat_struct.st_size);

		/* and stuff on our body bytes */
		p_the_response->body = (iluhttp_OptionalEntityBody) ilu_malloc (sizeof(iluhttp_EntityBody));
		p_the_response->body->_buffer = pc_body_bytes;
		p_the_response->body->_length = stat_struct.st_size;
		p_the_response->body->_maximum = stat_struct.st_size;
	}
	else p_the_response->body = NULL;

	/* close the file */
	CLOSE_FUNCTION(h_file);

	/* return our generated response */
	return p_the_response;
}