#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "krb5.h"
#include "vardlg.h"
#include "gic.h"
gic_data *gd;
static BOOL
gic_dialog_init(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
vardlg_config(hwnd, gd->width, gd->banner, gd->num_prompts,
gd->prompts, (WORD)(gd->id));
return FALSE;
}
static void
gic_dialog_command(HWND hwnd, int cid, HWND hwndCtl, UINT codeNotify)
{
int n;
WORD id;
if (codeNotify != BN_CLICKED)
return;
if (cid != IDOK && cid != IDCANCEL)
return;
if (cid == IDCANCEL) {
EndDialog(hwnd, IDCANCEL);
return;
}
id = (gd->id + 2);
for (n = 0 ; n < gd->num_prompts ; n++) {
Edit_GetText(GetDlgItem(hwnd, id), gd->prompts[n].reply->data,
gd->prompts[n].reply->length);
gd->prompts[n].reply->length = strlen(gd->prompts[n].reply->data);
id += 2;
}
EndDialog(hwnd, IDOK);
}
static BOOL CALLBACK
gic_dialog(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
HANDLE_MSG(hwnd, WM_INITDIALOG, gic_dialog_init);
HANDLE_MSG(hwnd, WM_COMMAND, gic_dialog_command);
}
return FALSE;
}
krb5_error_code KRB5_CALLCONV
gic_prompter(krb5_context ctx, void *data, const char *name,
const char *banner, int num_prompts, krb5_prompt prompts[])
{
int rc;
void *dlg;
gd = data;
gd->banner = banner;
gd->num_prompts = num_prompts;
gd->prompts = prompts;
if (gd->width == 0)
gd->width = 450;
dlg = vardlg_build((WORD)(gd->width), name, gd->banner,
(WORD)num_prompts, prompts, (WORD)(gd->id));
rc = DialogBoxIndirect(gd->hinstance, (LPDLGTEMPLATE)dlg, gd->hwnd, gic_dialog);
if (rc != IDOK)
return 1;
return 0;
}