处理goto导致的编译不通过。

This commit is contained in:
zhengchao
2018-11-29 16:39:25 +08:00
parent f76a8c5ca2
commit 0e47b8d715
4 changed files with 34 additions and 38 deletions

View File

@@ -109,16 +109,16 @@ struct http_field_name * http_field_construct_from_string(const char * str_field
return NULL; return NULL;
} }
const char * http_field_to_string(const struct http_field_name * field) const char * http_field_name_to_string(const struct http_field_name * field)
{ {
if (field->field_id != TFE_HTTP_UNKNOWN_FIELD) return __str_std_header_field_map[field->field_id]; if (field->field_id != TFE_HTTP_UNKNOWN_FIELD) return __str_std_header_field_map[field->field_id];
return field->field_name; return field->field_name;
} }
void http_field_destory(struct http_field_name * field) void http_field_name_destory(struct http_field_name * field)
{ {
if(field->field_id == TFE_HTTP_UNKNOWN_FIELD) FREE(&field->field_name); if(field->field_id == TFE_HTTP_UNKNOWN_FIELD) free((void*)field->field_name);
free(field); FREE(&(field));
} }
struct http_frame_session_ctx struct http_frame_session_ctx

View File

@@ -159,7 +159,7 @@ void connection_close_cb(struct evhttp_connection* connection, void* arg)
//printf("call connection_close_cb\n"); //printf("call connection_close_cb\n");
} }
char* get_request_url(struct evhttp_uri* uri, int url_len) char* get_request_url(struct evhttp_uri* uri, size_t url_len)
{ {
const char* path = evhttp_uri_get_path(uri); const char* path = evhttp_uri_get_path(uri);
const char* query = evhttp_uri_get_query(uri); const char* query = evhttp_uri_get_query(uri);
@@ -184,6 +184,11 @@ char* get_request_url(struct evhttp_uri* uri, int url_len)
//data is for POST. if method is GET, data should be NULL //data is for POST. if method is GET, data should be NULL
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase, struct evdns_base* dnsbase) void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase, struct evdns_base* dnsbase)
{ {
const char* host=NULL;
int port=0;
size_t url_len=0;
char* request_url=NULL;
struct evhttp_request* request=NULL;
struct promise* p = future_to_promise(f); struct promise* p = future_to_promise(f);
struct tfe_rpc_ctx* ctx = ALLOC(struct tfe_rpc_ctx, 1); struct tfe_rpc_ctx* ctx = ALLOC(struct tfe_rpc_ctx, 1);
ctx->evbase = evbase; ctx->evbase = evbase;
@@ -196,13 +201,13 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse url failed!"); _wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse url failed!");
goto error_out; goto error_out;
} }
const char* host = evhttp_uri_get_host(uri); host = evhttp_uri_get_host(uri);
if(!host) if(!host)
{ {
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse host failed!"); _wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse host failed!");
goto error_out; goto error_out;
} }
int port = evhttp_uri_get_port(uri); port = evhttp_uri_get_port(uri);
if(port < 0) if(port < 0)
{ {
port = 80; port = 80;
@@ -215,7 +220,7 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
goto error_out; goto error_out;
} }
evhttp_connection_set_closecb(ctx->connection, connection_close_cb, evbase); evhttp_connection_set_closecb(ctx->connection, connection_close_cb, evbase);
struct evhttp_request* request = evhttp_request_new(get_response_cb, (void*)p); request = evhttp_request_new(get_response_cb, (void*)p);
//evhttp_request_set_header_cb(request, read_header_done_cb); //evhttp_request_set_header_cb(request, read_header_done_cb);
if(flag == CHUNK_CB) if(flag == CHUNK_CB)
{ {
@@ -223,8 +228,8 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
} }
evhttp_request_set_error_cb(request, request_error_cb); evhttp_request_set_error_cb(request, request_error_cb);
evhttp_add_header(evhttp_request_get_output_headers(request), "Host", host); evhttp_add_header(evhttp_request_get_output_headers(request), "Host", host);
int url_len = strlen(url); url_len = strlen(url);
char* request_url = get_request_url(uri, url_len); request_url = get_request_url(uri, url_len);
//printf("request url is %s\n", request_url); //printf("request url is %s\n", request_url);
if(request_url == NULL) if(request_url == NULL)
{ {

View File

@@ -275,41 +275,31 @@ static EVP_PKEY* transform_key_to_EVP(const char* str)
return key; return key;
} }
static void err_out(X509* cert, EVP_PKEY* key, STACK_OF(X509)* chain)
{
if(cert)
{
X509_free(cert);
}
if(key)
{
EVP_PKEY_free(key);
}
if(chain)
{
sk_X509_pop_free(chain, X509_free);
}
return;
}
static struct keyring_private* get_keyring_from_response(const char* data) static struct keyring_private* get_keyring_from_response(const char* data)
{ {
X509* cert = NULL; X509* cert = NULL;
X509* chain_cert = NULL;
struct keyring_private* _kyr=NULL;
EVP_PKEY* key = NULL; EVP_PKEY* key = NULL;
STACK_OF(X509)* chain = NULL; STACK_OF(X509)* chain = NULL;
cJSON* data_json = NULL;
cJSON* chain_cert_json = NULL;
cJSON* cert_json = NULL;
cJSON* key_json = NULL;
cJSON* chain_json = NULL;
if(data == NULL) if(data == NULL)
{ {
goto error_out; goto error_out;
} }
cJSON* data_json = cJSON_Parse(data); data_json = cJSON_Parse(data);
if(data_json == NULL) if(data_json == NULL)
{ {
goto error_out; goto error_out;
} }
cJSON* cert_json = NULL;
cJSON* key_json = NULL;
cJSON* chain_json = NULL;
cert_json = cJSON_GetObjectItemCaseSensitive(data_json, "CERTIFICATE"); cert_json = cJSON_GetObjectItemCaseSensitive(data_json, "CERTIFICATE");
key_json = cJSON_GetObjectItemCaseSensitive(data_json, "PRIVATE_KEY"); key_json = cJSON_GetObjectItemCaseSensitive(data_json, "PRIVATE_KEY");
chain_json = cJSON_GetObjectItemCaseSensitive(data_json, "CERTIFICATE_CHAIN"); chain_json = cJSON_GetObjectItemCaseSensitive(data_json, "CERTIFICATE_CHAIN");
@@ -333,11 +323,10 @@ static struct keyring_private* get_keyring_from_response(const char* data)
{ {
goto error_out; goto error_out;
} }
cJSON* chain_cert_json = NULL;
chain = sk_X509_new_null(); chain = sk_X509_new_null();
cJSON_ArrayForEach(chain_cert_json, chain_json) cJSON_ArrayForEach(chain_cert_json, chain_json)
{ {
X509* chain_cert = NULL; chain_cert = NULL;
if (chain_cert_json && chain_cert_json->valuestring != NULL) if (chain_cert_json && chain_cert_json->valuestring != NULL)
{ {
chain_cert = transform_cert_to_x509(chain_cert_json->valuestring); chain_cert = transform_cert_to_x509(chain_cert_json->valuestring);
@@ -349,7 +338,7 @@ static struct keyring_private* get_keyring_from_response(const char* data)
sk_X509_push(chain, chain_cert); sk_X509_push(chain, chain_cert);
ssl_x509_refcount_inc(chain_cert); ssl_x509_refcount_inc(chain_cert);
} }
struct keyring_private* _kyr= keyring_new(); _kyr= keyring_new();
keyring_set_cert(_kyr, cert); keyring_set_cert(_kyr, cert);
keyring_set_key(_kyr, key); keyring_set_key(_kyr, key);
keyring_set_chain(_kyr, chain); keyring_set_chain(_kyr, chain);

View File

@@ -1,12 +1,14 @@
#include "mirror_stream.h" #include "mirror_stream.h"
#include <tfe_stream.h> #include <tfe_stream.h>
#include <tfe_utils.h>
#include <tfe_plugin.h> #include <tfe_plugin.h>
#include <assert.h> #include <assert.h>
int decrypt_mirror_init(struct tfe_proxy * proxy) int decrypt_mirror_init(struct tfe_proxy * proxy)
{ {
const char* filepath="./conf/tfe/decrypt_mirror.conf"; const char* filepath="./conf/tfe/decrypt_mirror.conf";
int thread_num=2, ret=0;//todo: aquire from proxy; int thread_num=2;
UNUSED int ret=0;//todo: aquire from proxy;
ret=mirror_stream_init(thread_num, filepath); ret=mirror_stream_init(thread_num, filepath);
// assert(ret==0); // assert(ret==0);
return 0; return 0;
@@ -15,7 +17,7 @@ int decrypt_mirror_init(struct tfe_proxy * proxy)
int decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id, int decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, void ** pme) enum tfe_conn_dir dir, void ** pme)
{ {
int ret=0; UNUSED int ret=0;
ret=mirror_stream_open(thread_id, stream->addr, pme); ret=mirror_stream_open(thread_id, stream->addr, pme);
// assert(ret==0); // assert(ret==0);
return 0; return 0;
@@ -24,7 +26,7 @@ int decrypt_mirror_on_open_cb(const struct tfe_stream * stream, unsigned int thr
enum tfe_stream_action decrypt_mirror_on_data_cb(const struct tfe_stream * stream, unsigned int thread_id, enum tfe_stream_action decrypt_mirror_on_data_cb(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme) enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme)
{ {
int ret=0; UNUSED int ret=0;
ret=mirror_stream_write(dir, data,len, pme, thread_id); ret=mirror_stream_write(dir, data,len, pme, thread_id);
return ACTION_FORWARD_DATA; return ACTION_FORWARD_DATA;
} }