ENGINE * ENGINE_by_id(const char *id) { ENGINE *iterator; ENGINE *tmp; tmp = engine_list_head; while (tmp) { printf("my engine iterator, id%s\n", tmp->id); tmp = tmp->next; } printf("my engine, file:%s line:%d\n", __FILE__, __LINE__); if (id == NULL) { ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_PASSED_NULL_PARAMETER); return NULL; } CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); printf("my engine, file:%s line:%d\n", __FILE__, __LINE__); iterator = engine_list_head; while (iterator && (strcmp(id, iterator->id) != 0) && printf("my engine iterator, id%s\n", iterator->id)) iterator = iterator->next; if (iterator) { /* We need to return a structural reference. If this is an * ENGINE type that returns copies, make a duplicate - otherwise * increment the existing ENGINE's reference count. */ if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) { ENGINE *cp = ENGINE_new(); if (!cp) iterator = NULL; else { engine_cpy(cp, iterator); iterator = cp; } } else { iterator->struct_ref++; engine_ref_debug(iterator, 0, 1) } } CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); printf("my engine, file:%s line:%d\n", __FILE__, __LINE__); if (iterator == NULL) { ENGINEerr(ENGINE_F_ENGINE_BY_ID, ENGINE_R_NO_SUCH_ENGINE); ERR_asprintf_error_data("id=%s", id); } return iterator; }
ENGINE *ENGINE_by_id(const char *id) { ENGINE *iterator; char *load_dir = NULL; if (id == NULL) { ENGINEerr(ENGINE_F_ENGINE_BY_ID, ERR_R_PASSED_NULL_PARAMETER); return NULL; } CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); iterator = engine_list_head; while (iterator && (strcmp(id, iterator->id) != 0)) iterator = iterator->next; if (iterator != NULL) { /* * We need to return a structural reference. If this is an ENGINE * type that returns copies, make a duplicate - otherwise increment * the existing ENGINE's reference count. */ if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) { ENGINE *cp = ENGINE_new(); if (cp == NULL) iterator = NULL; else { engine_cpy(cp, iterator); iterator = cp; } } else { iterator->struct_ref++; engine_ref_debug(iterator, 0, 1); } } CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); if (iterator != NULL) return iterator; /* * Prevent infinite recursion if we're looking for the dynamic engine. */ if (strcmp(id, "dynamic")) { # ifdef OPENSSL_SYS_VMS if ((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = "SSLROOT:[ENGINES]"; # else if ((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = ENGINESDIR; # endif iterator = ENGINE_by_id("dynamic"); if (!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) || !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) || !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD", load_dir, 0) || !ENGINE_ctrl_cmd_string(iterator, "LIST_ADD", "1", 0) || !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0)) goto notfound; return iterator; } notfound: ENGINE_free(iterator); ENGINEerr(ENGINE_F_ENGINE_BY_ID, ENGINE_R_NO_SUCH_ENGINE); ERR_add_error_data(2, "id=", id); return NULL; /* EEK! Experimental code ends */ }