1/* x11-ssh-askpass.h:  A generic X11-based password dialog for OpenSSH.
2 * created 1999-Nov-17 03:40 Jim Knoble <jmknoble@jmknoble.cx>
3 * autodate: 2001-Feb-14 04:00
4 *
5 * by Jim Knoble <jmknoble@jmknoble.cx>
6 * Copyright (C) 1999,2000,2001 Jim Knoble
7 *
8 * Disclaimer:
9 *
10 * The software is provided "as is", without warranty of any kind,
11 * express or implied, including but not limited to the warranties of
12 * merchantability, fitness for a particular purpose and
13 * noninfringement. In no event shall the author(s) be liable for any
14 * claim, damages or other liability, whether in an action of
15 * contract, tort or otherwise, arising from, out of or in connection
16 * with the software or the use or other dealings in the software.
17 *
18 * Portions of this code are distantly derived from code in xscreensaver
19 * by Jamie Zawinski <jwz@jwz.org>.  That code says:
20 *
21 * --------8<------------------------------------------------8<--------
22 * xscreensaver, Copyright (c) 1991-1999 Jamie Zawinski <jwz@jwz.org>
23 *
24 * Permission to use, copy, modify, distribute, and sell this software and its
25 * documentation for any purpose is hereby granted without fee, provided that
26 * the above copyright notice appear in all copies and that both that
27 * copyright notice and this permission notice appear in supporting
28 * documentation.  No representations are made about the suitability of this
29 * software for any purpose.  It is provided "as is" without express or
30 * implied warranty.
31 * --------8<------------------------------------------------8<--------
32 *
33 * The remainder of this code falls under the same permissions and
34 * provisions as those of the xscreensaver code.
35 */
36
37#ifndef H_X11_SSH_ASKPASS
38#define H_X11_SSH_ASKPASS
39
40#include <X11/Xlib.h>
41#include <X11/Intrinsic.h>
42#include <X11/Shell.h>
43
44#define EXIT_STATUS_ACCEPT	0
45#define EXIT_STATUS_CANCEL	1
46#define EXIT_STATUS_NO_MEMORY	2
47#define EXIT_STATUS_ERROR	3
48#define EXIT_STATUS_TIMEOUT	4
49#define EXIT_STATUS_ANOMALY	127
50
51typedef struct
52{
53   Pixel foreground;
54   Pixel background;
55   Dimension width;
56   Dimension height;
57   Position x;
58   Position y;
59} WidgetInfo;
60
61typedef struct
62{
63   WidgetInfo w;
64   Pixel topShadowColor;
65   Pixel bottomShadowColor;
66   Dimension shadowThickness;
67   Pixel borderColor;
68   Dimension borderWidth;
69   Dimension interiorWidth;
70   Dimension interiorHeight;
71   Dimension horizontalSpacing;
72   Dimension verticalSpacing;
73} Widget3dInfo;
74
75typedef struct TextObjectStruct
76{
77   char *text;
78   int textLength;
79   int direction;
80   int ascent;
81   int descent;
82   XCharStruct overall;
83   struct TextObjectStruct *next;
84} TextObject;
85
86typedef struct
87{
88   char *fullText;
89   XFontStruct *font;
90   XFontStruct *fixedFont;
91   TextObject *multiText;
92   WidgetInfo w;
93} LabelInfo;
94
95typedef struct
96{
97   Widget3dInfo w3;
98   LabelInfo label;
99   Bool pressed;
100} ButtonInfo;
101
102typedef struct
103{
104   Widget3dInfo w3;
105   int count;
106   int current;
107   int minimumCount;
108   int maximumCount;
109} MasterIndicatorInfo;
110
111typedef struct
112{
113   MasterIndicatorInfo *parent;
114   WidgetInfo w;
115   Bool isLit;
116} IndicatorElement;
117
118typedef struct
119{
120   Window dialogWindow;
121
122   XSizeHints *sizeHints;
123   XWMHints *wmHints;
124   XClassHint *classHints;
125   XTextProperty windowName;
126
127   char *title;
128   Widget3dInfo w3;
129
130   LabelInfo label;
131
132   MasterIndicatorInfo indicator;
133   IndicatorElement *indicators;
134
135   ButtonInfo okButton;
136   ButtonInfo cancelButton;
137
138   int pressedButton;
139} DialogInfo;
140
141#define NO_BUTTON	0
142#define OK_BUTTON	1
143#define CANCEL_BUTTON	2
144
145typedef struct
146{
147   char *appName;
148   char *appClass;
149
150   int argc;
151   char **argv;
152
153   pid_t pid;
154
155   char *buf;
156   int bufSize;
157   int bufIndex;
158
159   Display *dpy;
160   Screen *screen;
161   long screen_width;
162   long screen_height;
163   Window rootWindow;
164   Pixel black;
165   Pixel white;
166   Colormap colormap;
167
168   /* Resolution measurements are normalized to dots/meter. */
169   long xResolution;
170   long yResolution;
171   long defaultXResolution;
172   long defaultYResolution;
173   long xFuzz;
174   long yFuzz;
175
176   XtAppContext appContext;
177   Widget toplevelShell;
178   XrmDatabase resourceDb;
179
180   Atom wmDeleteWindowAtom;
181
182   GC fillGC;
183   GC borderGC;
184   GC textGC;
185   GC brightGC;
186   GC dimGC;
187
188   long eventMask;
189
190   Bool grabKeyboard;
191   Bool grabPointer;
192   Bool grabServer;
193   Bool isKeyboardGrabbed;
194   Bool isPointerGrabbed;
195   Bool isServerGrabbed;
196   unsigned int grabFailTimeout;
197   unsigned int grabRetryInterval;
198
199   unsigned long inputTimeout;
200   XtIntervalId inputTimeoutTimerId;
201   Bool inputTimeoutActive;
202
203   DialogInfo *dialog;
204} AppInfo;
205
206void outOfMemory(AppInfo *app, int line);
207void freeIf(void *p);
208void freeFontIf(AppInfo *app, XFontStruct *f);
209
210XFontStruct *getFontResource(AppInfo *app, char *instanceName, char *className);
211char *getStringResourceWithDefault(char *instanceName, char *className,
212				   char *defaultText);
213unsigned int getUnsignedIntegerResource(AppInfo *app, char *instanceName,
214					char *className,
215					unsigned int defaultValue);
216long getResolutionResource(AppInfo *app, char *instanceName, char *className,
217			   char *defaultResolutionSpec);
218
219void calcLabelTextExtents(LabelInfo *label);
220void calcTotalButtonExtents(ButtonInfo *button);
221void calcButtonExtents(ButtonInfo *button);
222void balanceButtonExtents(ButtonInfo *button1, ButtonInfo *button2);
223void calcButtonLabelPosition(ButtonInfo *button);
224
225Dimension scaleXDimension(AppInfo *app, Dimension unscaled);
226Dimension scaleYDimension(AppInfo *app, Dimension unscaled);
227
228void createDialog(AppInfo *app);
229void destroyDialog(AppInfo *app);
230void createDialogWindow(AppInfo *app);
231void createGCs(AppInfo *app);
232void destroyGCs(AppInfo *app);
233
234void paintLabel(AppInfo *app, Drawable draw, LabelInfo label);
235void paintButton(AppInfo *app, Drawable draw, ButtonInfo button);
236void paintIndicator(AppInfo *app, Drawable draw, IndicatorElement indicator);
237void updateIndicatorElement(AppInfo *app, int i);
238void updateIndicators(AppInfo *app, int condition);
239void paintDialog(AppInfo *app);
240
241#define GRAB_KEYBOARD	0
242#define GRAB_POINTER	1
243void performGrab(AppInfo *app, int grabType, char *grabTypeName,
244		 Bool shouldGrab, Bool *isGrabbed);
245
246void grabKeyboard(AppInfo *app);
247void ungrabKeyboard(AppInfo *app);
248void grabPointer(AppInfo *app);
249void ungrabPointer(AppInfo *app);
250void grabServer(AppInfo *app);
251void ungrabServer(AppInfo *app);
252
253void cleanUp(AppInfo *app);
254void exitApp(AppInfo *app, int exitCode);
255
256void acceptAction(AppInfo *app);
257void cancelAction(AppInfo *app);
258
259void backspacePassphrase(AppInfo *app);
260void erasePassphrase(AppInfo *app);
261void addToPassphrase(AppInfo *app, char c);
262
263void handleKeyPress(AppInfo *app, XEvent *event);
264Bool eventIsInsideButton(AppInfo *app, XEvent *event, ButtonInfo button);
265void handleButtonPress(AppInfo *app, XEvent *event);
266void handlePointerMotion(AppInfo *app, XEvent *event);
267
268void handleInputTimeout(XtPointer data, XtIntervalId *timerId);
269void cancelInputTimeout(AppInfo *app);
270
271#endif /* H_X11_SSH_ASKPASS */
272