?? ui_lib.c
字號:
return ui->user_data; }const char *UI_get0_result(UI *ui, int i) { if (i < 0) { UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL); return NULL; } if (i >= sk_UI_STRING_num(ui->strings)) { UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE); return NULL; } return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); }static int print_error(const char *str, size_t len, UI *ui) { UI_STRING uis; memset(&uis, 0, sizeof(uis)); uis.type = UIT_ERROR; uis.out_string = str; if (ui->meth->ui_write_string && !ui->meth->ui_write_string(ui, &uis)) return -1; return 0; }int UI_process(UI *ui) { int i, ok=0; if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui)) return -1; if (ui->flags & UI_FLAG_PRINT_ERRORS) ERR_print_errors_cb( (int (*)(const char *, size_t, void *))print_error, (void *)ui); for(i=0; i<sk_UI_STRING_num(ui->strings); i++) { if (ui->meth->ui_write_string && !ui->meth->ui_write_string(ui, sk_UI_STRING_value(ui->strings, i))) { ok=-1; goto err; } } if (ui->meth->ui_flush) switch(ui->meth->ui_flush(ui)) { case -1: /* Interrupt/Cancel/something... */ ok = -2; goto err; case 0: /* Errors */ ok = -1; goto err; default: /* Success */ ok = 0; break; } for(i=0; i<sk_UI_STRING_num(ui->strings); i++) { if (ui->meth->ui_read_string) { switch(ui->meth->ui_read_string(ui, sk_UI_STRING_value(ui->strings, i))) { case -1: /* Interrupt/Cancel/something... */ ok = -2; goto err; case 0: /* Errors */ ok = -1; goto err; default: /* Success */ ok = 0; break; } } } err: if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui)) return -1; return ok; }int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)) { if (ui == NULL) { UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER); return -1; } switch(cmd) { case UI_CTRL_PRINT_ERRORS: { int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS); if (i) ui->flags |= UI_FLAG_PRINT_ERRORS; else ui->flags &= ~UI_FLAG_PRINT_ERRORS; return save_flag; } case UI_CTRL_IS_REDOABLE: return !!(ui->flags & UI_FLAG_REDOABLE); default: break; } UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND); return -1; }int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp, new_func, dup_func, free_func); }int UI_set_ex_data(UI *r, int idx, void *arg) { return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); }void *UI_get_ex_data(UI *r, int idx) { return(CRYPTO_get_ex_data(&r->ex_data,idx)); }void UI_set_default_method(const UI_METHOD *meth) { default_UI_meth=meth; }const UI_METHOD *UI_get_default_method(void) { if (default_UI_meth == NULL) { default_UI_meth=UI_OpenSSL(); } return default_UI_meth; }const UI_METHOD *UI_get_method(UI *ui) { return ui->meth; }const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth) { ui->meth=meth; return ui->meth; }UI_METHOD *UI_create_method(char *name) { UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD)); if (ui_method) { memset(ui_method, 0, sizeof(*ui_method)); ui_method->name = BUF_strdup(name); } return ui_method; }/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method (that is, it hasn't been allocated using UI_create_method(), you deserve anything Murphy can throw at you and more! You have been warned. */void UI_destroy_method(UI_METHOD *ui_method) { OPENSSL_free(ui_method->name); ui_method->name = NULL; OPENSSL_free(ui_method); }int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) { if (method) { method->ui_open_session = opener; return 0; } else return -1; }int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)) { if (method) { method->ui_write_string = writer; return 0; } else return -1; }int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)) { if (method) { method->ui_flush = flusher; return 0; } else return -1; }int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)) { if (method) { method->ui_read_string = reader; return 0; } else return -1; }int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)) { if (method) { method->ui_close_session = closer; return 0; } else return -1; }int (*UI_method_get_opener(UI_METHOD *method))(UI*) { if (method) return method->ui_open_session; else return NULL; }int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*) { if (method) return method->ui_write_string; else return NULL; }int (*UI_method_get_flusher(UI_METHOD *method))(UI*) { if (method) return method->ui_flush; else return NULL; }int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*) { if (method) return method->ui_read_string; else return NULL; }int (*UI_method_get_closer(UI_METHOD *method))(UI*) { if (method) return method->ui_close_session; else return NULL; }enum UI_string_types UI_get_string_type(UI_STRING *uis) { if (!uis) return UIT_NONE; return uis->type; }int UI_get_input_flags(UI_STRING *uis) { if (!uis) return 0; return uis->input_flags; }const char *UI_get0_output_string(UI_STRING *uis) { if (!uis) return NULL; return uis->out_string; }const char *UI_get0_action_string(UI_STRING *uis) { if (!uis) return NULL; switch(uis->type) { case UIT_PROMPT: case UIT_BOOLEAN: return uis->_.boolean_data.action_desc; default: return NULL; } }const char *UI_get0_result_string(UI_STRING *uis) { if (!uis) return NULL; switch(uis->type) { case UIT_PROMPT: case UIT_VERIFY: return uis->result_buf; default: return NULL; } }const char *UI_get0_test_string(UI_STRING *uis) { if (!uis) return NULL; switch(uis->type) { case UIT_VERIFY: return uis->_.string_data.test_buf; default: return NULL; } }int UI_get_result_minsize(UI_STRING *uis) { if (!uis) return -1; switch(uis->type) { case UIT_PROMPT: case UIT_VERIFY: return uis->_.string_data.result_minsize; default: return -1; } }int UI_get_result_maxsize(UI_STRING *uis) { if (!uis) return -1; switch(uis->type) { case UIT_PROMPT: case UIT_VERIFY: return uis->_.string_data.result_maxsize; default: return -1; } }int UI_set_result(UI *ui, UI_STRING *uis, const char *result) { int l = strlen(result); ui->flags &= ~UI_FLAG_REDOABLE; if (!uis) return -1; switch (uis->type) { case UIT_PROMPT: case UIT_VERIFY: { char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1]; char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1]; BIO_snprintf(number1, sizeof(number1), "%d", uis->_.string_data.result_minsize); BIO_snprintf(number2, sizeof(number2), "%d", uis->_.string_data.result_maxsize); if (l < uis->_.string_data.result_minsize) { ui->flags |= UI_FLAG_REDOABLE; UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL); ERR_add_error_data(5,"You must type in ", number1," to ",number2," characters"); return -1; } if (l > uis->_.string_data.result_maxsize) { ui->flags |= UI_FLAG_REDOABLE; UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE); ERR_add_error_data(5,"You must type in ", number1," to ",number2," characters"); return -1; } } if (!uis->result_buf) { UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER); return -1; } BUF_strlcpy(uis->result_buf, result, uis->_.string_data.result_maxsize + 1); break; case UIT_BOOLEAN: { const char *p; if (!uis->result_buf) { UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER); return -1; } uis->result_buf[0] = '\0'; for(p = result; *p; p++) { if (strchr(uis->_.boolean_data.ok_chars, *p)) { uis->result_buf[0] = uis->_.boolean_data.ok_chars[0]; break; } if (strchr(uis->_.boolean_data.cancel_chars, *p)) { uis->result_buf[0] = uis->_.boolean_data.cancel_chars[0]; break; } } default: break; } } return 0; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -