int KSI_HttpClient_new(KSI_CTX *ctx, KSI_NetworkClient **client) { int res = KSI_UNKNOWN_ERROR; KSI_NetworkClient *tmp = NULL; KSI_HttpClient *http = NULL; if (ctx == NULL || client == NULL) { res = KSI_INVALID_ARGUMENT; goto cleanup; } res = KSI_AbstractHttpClient_new(ctx, &tmp); if (res != KSI_OK) goto cleanup; http = tmp->impl; http->sendRequest = sendRequest; tmp->performAll = performAll; res = KSI_CTX_registerGlobals(ctx, curlGlobal_init, curlGlobal_cleanup); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } *client = tmp; tmp = NULL; res = KSI_OK; cleanup: KSI_NetworkClient_free(tmp); return res; }
int KSI_CTX_setNetworkProvider(KSI_CTX *ctx, KSI_NetworkClient *netProvider){ int res = KSI_UNKNOWN_ERROR; if (ctx == NULL){ res = KSI_INVALID_ARGUMENT; goto cleanup; } if (ctx->netProvider != NULL) { KSI_NetworkClient_free (ctx->netProvider); } ctx->netProvider = netProvider; ctx->isCustomNetProvider = 1; res = KSI_OK; cleanup: return res; }
void KSI_CTX_free(KSI_CTX *ctx) { if (ctx != NULL) { /* Call cleanup methods. */ globalCleanup(ctx); KSI_List_free(ctx->cleanupFnList); KSI_free(ctx->errors); KSI_NetworkClient_free(ctx->netProvider); KSI_PKITruststore_free(ctx->pkiTruststore); KSI_PublicationsFile_free(ctx->publicationsFile); KSI_free(ctx->publicationCertEmail_DEPRECATED); freeCertConstraintsArray(ctx->certConstraints); KSI_Signature_free(ctx->lastFailedSignature); KSI_free(ctx); } }
static void Test_ExtendSignature_useProvider(CuTest* tc, const char *uri_host, unsigned port, const char *user, const char *key, const char *pub_uri, int (*createProvider)(KSI_CTX *ctx, KSI_NetworkClient **http), int (*setPubfail)(KSI_NetworkClient *client, const char *url), int (*setExtender)(KSI_NetworkClient *client, const char *url_host, unsigned port, const char *user, const char *pass)) { int res = KSI_UNKNOWN_ERROR; KSI_Signature *sig = NULL; KSI_Signature *ext = NULL; KSI_NetworkClient *client = NULL; KSI_CTX *ctx = NULL; /* Create the context. */ res = KSI_CTX_new(&ctx); CuAssert(tc, "Unable to create ctx.", res == KSI_OK && ctx != NULL); res = createProvider(ctx, &client); CuAssert(tc, "Unable to create network client.", res == KSI_OK && client != NULL); res = setExtender(client, uri_host, port, user, key); CuAssert(tc, "Unable to set extender specific service information.", res == KSI_OK); res = setPubfail(client, pub_uri); CuAssert(tc, "Unable to set publications file url.", res == KSI_OK); res = KSI_CTX_setNetworkProvider(ctx, client); CuAssert(tc, "Unable to set new network client.", res == KSI_OK); client = NULL; res = KSI_Signature_fromFile(ctx, getFullResourcePath("resource/tlv/ok-sig-2014-07-01.1.ksig"), &sig); CuAssert(tc, "Unable to set read signature from file.", res == KSI_OK && sig != NULL); res = KSI_Signature_extend(sig, ctx, NULL, &ext); CuAssert(tc, "The extending of signature must not fail.", res == KSI_OK && ext != NULL); KSI_NetworkClient_free(client); KSI_Signature_free(sig); KSI_Signature_free(ext); KSI_CTX_free(ctx); return; }
void KSI_HttpClient_free(KSI_HttpClient *http) { KSI_NetworkClient_free((KSI_NetworkClient*)http); }
int KSI_CTX_new(KSI_CTX **context) { int res = KSI_UNKNOWN_ERROR; KSI_CTX *ctx = NULL; KSI_NetworkClient *client = NULL; ctx = KSI_new(KSI_CTX); if (ctx == NULL) { res = KSI_OUT_OF_MEMORY; goto cleanup; } /* Init error stack */ ctx->errors_size = KSI_ERR_STACK_LEN; ctx->errors = KSI_malloc(sizeof(KSI_ERR) * ctx->errors_size); if (ctx->errors == NULL) { res = KSI_OUT_OF_MEMORY; goto cleanup; } ctx->errors_count = 0; ctx->publicationsFile = NULL; ctx->pkiTruststore = NULL; ctx->netProvider = NULL; ctx->publicationCertEmail_DEPRECATED = NULL; ctx->loggerCB = NULL; ctx->requestHeaderCB = NULL; ctx->flags[KSI_CTX_FLAG_AGGR_PDU_VER] = KSI_AGGREGATION_PDU_VERSION; ctx->flags[KSI_CTX_FLAG_EXT_PDU_VER] = KSI_EXTENDING_PDU_VERSION; ctx->loggerCtx = NULL; ctx->certConstraints = NULL; ctx->freeCertConstraintsArray = freeCertConstraintsArray; ctx->lastFailedSignature = NULL; KSI_ERR_clearErrors(ctx); /* Create global cleanup list as the first thing. */ res = KSI_List_new(NULL, &ctx->cleanupFnList); if (res != KSI_OK) goto cleanup; /* Create and set the logger. */ res = KSI_CTX_setLoggerCallback(ctx, KSI_LOG_StreamLogger, stdout); if (res != KSI_OK) goto cleanup; res = KSI_CTX_setLogLevel(ctx, KSI_LOG_NONE); if (res != KSI_OK) goto cleanup; res = KSI_UriClient_new(ctx, &client); if (res != KSI_OK) goto cleanup; res = KSI_CTX_setNetworkProvider(ctx, client); if (res != KSI_OK) goto cleanup; ctx->isCustomNetProvider = 0; client = NULL; /* Initialize truststore. */ res = KSI_PKITruststore_registerGlobals(ctx); if (res != KSI_OK) goto cleanup; /* Return the context. */ *context = ctx; ctx = NULL; res = KSI_OK; cleanup: KSI_NetworkClient_free(client); KSI_CTX_free(ctx); return res; }
int KSI_TcpClient_new(KSI_CTX *ctx, KSI_NetworkClient **tcp) { int res; KSI_NetworkClient *tmp = NULL; KSI_TcpClient *t = NULL; TcpClient_Endpoint *endp_aggr = NULL; TcpClient_Endpoint *endp_ext = NULL; TcpClient_Endpoint *endp_pub = NULL; KSI_ERR_clearErrors(ctx); if (ctx == NULL || tcp == NULL) { KSI_pushError(ctx, res = KSI_INVALID_ARGUMENT, NULL); goto cleanup; } res = KSI_AbstractNetworkClient_new(ctx, &tmp); if (tmp == NULL) { KSI_pushError(ctx, res = KSI_OUT_OF_MEMORY, NULL); goto cleanup; } t = KSI_new(KSI_TcpClient); if (tmp == NULL) { KSI_pushError(ctx, res = KSI_OUT_OF_MEMORY, NULL); goto cleanup; } t->sendRequest = sendRequest; t->transferTimeoutSeconds = 10; t->http = NULL; res = KSI_HttpClient_new(ctx, &t->http); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } /* Create implementations for abstract endpoints. */ res = TcpClient_Endpoint_new(&endp_aggr); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } res = TcpClient_Endpoint_new(&endp_ext); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } res = TcpClient_Endpoint_new(&endp_pub); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } /* Set implementations for abstract endpoints. */ res = KSI_NetEndpoint_setImplContext(tmp->aggregator, endp_aggr, (void (*)(void*))TcpClient_Endpoint_free); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } endp_aggr = NULL; res = KSI_NetEndpoint_setImplContext(tmp->extender, endp_ext, (void (*)(void*))TcpClient_Endpoint_free); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } endp_ext = NULL; res = KSI_NetEndpoint_setImplContext(tmp->publicationsFile, endp_pub, (void (*)(void*))TcpClient_Endpoint_free); if (res != KSI_OK) { KSI_pushError(ctx, res, NULL); goto cleanup; } endp_pub = NULL; tmp->sendExtendRequest = prepareExtendRequest; tmp->sendSignRequest = prepareAggregationRequest; tmp->sendPublicationRequest = sendPublicationRequest; tmp->implFree = (void (*)(void *))tcpClient_free; tmp->requestCount = 0; tmp->impl = t; t = NULL; *tcp = tmp; tmp = NULL; res = KSI_OK; cleanup: tcpClient_free(t); KSI_NetworkClient_free(tmp); TcpClient_Endpoint_free(endp_aggr); TcpClient_Endpoint_free(endp_ext); TcpClient_Endpoint_free(endp_pub); return res; }
static void tcpClient_free(KSI_TcpClient *tcp) { if (tcp != NULL) { KSI_NetworkClient_free(tcp->http); KSI_free(tcp); } }