~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/input/jamstudio/js_x.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002 by Brian Goines (bgoines78@comcast.net)
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software and its
 
5
 * documentation for any purpose is  hereby granted without fee, provided that
 
6
 * the  above copyright   notice appear  in   all  copies and  that both  that
 
7
 * copyright  notice   and   this  permission   notice  appear  in  supporting
 
8
 * documentation, and that   the  name of  Brian Goines not  be  used  in
 
9
 * advertising or publicity pertaining to distribution of the software without
 
10
 * specific,  written      prior  permission.     Brian Goines  makes  no
 
11
 * representations about the suitability of this software for any purpose.  It
 
12
 * is provided "as is" without express or implied warranty.                   
 
13
 *                                                                            
 
14
 * BRIAN GOINES DISCLAIMS ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
 
15
 * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
 
16
 * EVENT  SHALL FREDERIC  LEPIED BE   LIABLE   FOR ANY  SPECIAL, INDIRECT   OR
 
17
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
18
 * DATA  OR PROFITS, WHETHER  IN  AN ACTION OF  CONTRACT,  NEGLIGENCE OR OTHER
 
19
 * TORTIOUS  ACTION, ARISING    OUT OF OR   IN  CONNECTION  WITH THE USE    OR
 
20
 * PERFORMANCE OF THIS SOFTWARE.
 
21
 *
 
22
 */
 
23
/* $XFree86: xc/programs/Xserver/hw/xfree86/input/jamstudio/js_x.c,v 1.2 2002/11/15 16:05:25 tsi Exp $ */
 
24
 
 
25
#include <sys/types.h>
 
26
#include "xf86Version.h"
 
27
#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(3,9,0,0,0)
 
28
#define XFREE86_V4 1
 
29
#endif
 
30
#include "misc.h"
 
31
#include "xf86.h"
 
32
#include "xf86_ansic.h"
 
33
#include "xf86_OSproc.h"
 
34
#include "xf86Xinput.h"
 
35
#include "exevents.h"           /* Needed for InitValuator/Proximity stuff */
 
36
#include "mipointer.h"
 
37
 
 
38
#ifdef XFree86LOADER
 
39
#include "xf86Module.h"
 
40
#endif
 
41
 
 
42
#define JSX_XCOORD      65584
 
43
#define JSX_YCOORD      65585
 
44
#define JSX_PRESS               852016
 
45
#define JSX_BTN         852034
 
46
 
 
47
#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
 
48
 
 
49
#ifdef XFREE86_V4
 
50
 
 
51
struct hiddev_event
 
52
{
 
53
   unsigned hid;
 
54
   signed int value;
 
55
};
 
56
 
 
57
typedef struct
 
58
{
 
59
   int jsxFd;
 
60
   int jsxTimeout;
 
61
   char *jsxDevice;
 
62
   int jsxOldX;
 
63
   int jsxOldY;
 
64
   int jsxOldPress;
 
65
   int jsxOldBtn;
 
66
   int jsxOldNotify;
 
67
   int jsxMaxX;
 
68
   int jsxMaxY;
 
69
   int jsxMinX;
 
70
   int jsxMinY;
 
71
   int jsxPressMax;
 
72
   int jsxPressMin;
 
73
   int jsxPressDiv;
 
74
}
 
75
JS_XDevRec, *JS_XDevPtr;
 
76
 
 
77
static void
 
78
xf86JS_XReadInput(LocalDevicePtr local)
 
79
{
 
80
   JS_XDevPtr priv = local->private;
 
81
   struct hiddev_event event;
 
82
   int x = priv->jsxOldX, y = priv->jsxOldY, press = priv->jsxOldPress;
 
83
   int btn = priv->jsxOldBtn, len = 0;
 
84
   int btn_notify = priv->jsxOldNotify;
 
85
 
 
86
#if 0
 
87
   SYSCALL(len = read(local->fd, &event, sizeof(struct hiddev_event)));
 
88
   if (len < sizeof(struct hiddev_event))
 
89
      return;
 
90
#endif
 
91
   while ((len = read(local->fd, &event, sizeof(struct hiddev_event)))
 
92
          == sizeof(struct hiddev_event)) {
 
93
      switch (event.hid) {
 
94
      case JSX_XCOORD:
 
95
         x = event.value;
 
96
         break;
 
97
      case JSX_YCOORD:
 
98
         y = event.value;
 
99
         break;
 
100
      case JSX_PRESS:
 
101
         press = event.value / priv->jsxPressDiv;
 
102
         break;
 
103
      case JSX_BTN:
 
104
         priv->jsxOldBtn = btn = event.value;
 
105
         break;
 
106
      }
 
107
   }
 
108
   x = x > 0 ? x : 0;
 
109
   x = x < priv->jsxMaxX ? x : priv->jsxMaxX;
 
110
   y = y > 0 ? y : 0;
 
111
   y = y < priv->jsxMaxY ? y : priv->jsxMaxY;
 
112
   press = press > 0 ? press : 0;
 
113
   press = press < priv->jsxPressMax ? press : priv->jsxPressMax;
 
114
 
 
115
   if ((press > priv->jsxPressMin) && (btn == 1))
 
116
      btn_notify = 1;
 
117
   else
 
118
      btn_notify = 0;
 
119
 
 
120
   if ((x != priv->jsxOldX) || (y != priv->jsxOldY)
 
121
       || (press != priv->jsxOldPress)) {
 
122
      xf86PostMotionEvent(local->dev, 1, 0, 3, x, y, press);
 
123
      priv->jsxOldX = x;
 
124
      priv->jsxOldY = y;
 
125
      priv->jsxOldPress = press;
 
126
   }
 
127
   if (btn_notify != priv->jsxOldNotify) {
 
128
      xf86PostButtonEvent(local->dev, 0, 1, btn_notify, 0, 3, x, y, press);
 
129
      priv->jsxOldNotify = btn_notify;
 
130
   }
 
131
}
 
132
 
 
133
static int
 
134
xf86JS_XConnect(DeviceIntPtr pJS_X)
 
135
{
 
136
   LocalDevicePtr local = (LocalDevicePtr) pJS_X->public.devicePrivate;
 
137
   JS_XDevPtr priv = local->private;
 
138
 
 
139
   local->fd = xf86OpenSerial(local->options);
 
140
   InitValuatorAxisStruct(pJS_X, 0, priv->jsxMinX, priv->jsxMaxX,
 
141
                          priv->jsxMaxX / 7.5, 0, priv->jsxMaxX / 7.5);
 
142
   InitValuatorAxisStruct(pJS_X, 1, priv->jsxMinY, priv->jsxMaxY,
 
143
                          priv->jsxMaxY / 5.5, 0, priv->jsxMaxY / 5.5);
 
144
   InitValuatorAxisStruct(pJS_X, 2, priv->jsxPressMin, priv->jsxPressMax,
 
145
                          128, 0, 128);
 
146
   return (local->fd > 0);
 
147
}
 
148
 
 
149
static Bool
 
150
xf86JS_XConvert(LocalDevicePtr local, int first, int num, int v0, int v1,
 
151
                int v2, int v3, int v4, int v5, int *x, int *y)
 
152
{
 
153
   JS_XDevPtr priv = local->private;
 
154
   int width, height;
 
155
   int deltaX, deltaY;
 
156
 
 
157
   width = miPointerCurrentScreen()->width;
 
158
   height = miPointerCurrentScreen()->height;
 
159
/*
 
160
deltaX=(float)width/priv->jsxMaxX; deltaY=(float)height/priv->jsxMaxY;
 
161
*/
 
162
   deltaX = priv->jsxMaxX / width;
 
163
   deltaY = priv->jsxMaxY / height;
 
164
   *x = v0 / deltaX;
 
165
   *y = v1 / deltaY;
 
166
   xf86XInputSetScreen(local, 0, *x, *y);
 
167
   return TRUE;
 
168
}
 
169
 
 
170
static void
 
171
xf86JS_XControlProc(DeviceIntPtr device, PtrCtrl * ctrl)
 
172
{
 
173
   return;
 
174
}
 
175
 
 
176
static int
 
177
xf86JS_XProc(DeviceIntPtr pJS_X, int operation)
 
178
{
 
179
   LocalDevicePtr local = (LocalDevicePtr) pJS_X->public.devicePrivate;
 
180
   int nbaxes = 3;                      /* X Y Pressure */
 
181
   int nbuttons = 1;                    /* This this is necessary for most apps to work. */
 
182
   CARD8 map[2] = { 0, 1 };
 
183
 
 
184
   switch (operation) {
 
185
   case DEVICE_INIT:
 
186
      if (InitButtonClassDeviceStruct(pJS_X, nbuttons, map) == FALSE)
 
187
         return !Success;
 
188
      if (InitFocusClassDeviceStruct(pJS_X) == FALSE)
 
189
         return !Success;
 
190
      if (InitPtrFeedbackClassDeviceStruct(pJS_X, xf86JS_XControlProc) ==
 
191
          FALSE)
 
192
         return !Success;
 
193
      if (InitProximityClassDeviceStruct(pJS_X) == FALSE)
 
194
         return !Success;
 
195
      if (InitValuatorClassDeviceStruct(pJS_X, nbaxes, xf86GetMotionEvents,
 
196
                                        local->history_size,
 
197
                                        Absolute | OutOfProximity) == FALSE)
 
198
         return !Success;
 
199
      else
 
200
         xf86MotionHistoryAllocate(local);
 
201
      xf86JS_XConnect(pJS_X);
 
202
      break;
 
203
   case DEVICE_ON:
 
204
      if (local->fd == -1)
 
205
         xf86JS_XConnect(pJS_X);
 
206
      xf86AddEnabledDevice(local);
 
207
      pJS_X->public.on = TRUE;
 
208
      break;
 
209
   case DEVICE_OFF:
 
210
      if (local->fd > 0)
 
211
         xf86RemoveEnabledDevice(local);
 
212
   case DEVICE_CLOSE:
 
213
      if (local->fd > 0) {
 
214
         SYSCALL(close(local->fd));
 
215
         local->fd = -1;
 
216
      }
 
217
      break;
 
218
   default:
 
219
      xf86Msg(X_ERROR, "JamStudio: Unhandled operation number %d.\n",
 
220
              operation);
 
221
      break;
 
222
   }
 
223
   return Success;
 
224
}
 
225
 
 
226
static int
 
227
xf86JS_XChangeControl(LocalDevicePtr local, xDeviceCtl * control)
 
228
{
 
229
   return Success;
 
230
}
 
231
 
 
232
static int
 
233
xf86JS_XSwitchMode(ClientPtr client, DeviceIntPtr dev, int mode)
 
234
{
 
235
   return Success;
 
236
}
 
237
 
 
238
static LocalDevicePtr
 
239
xf86JS_XAllocate(InputDriverPtr drv)
 
240
{
 
241
   LocalDevicePtr local = xf86AllocateInput(drv, 0);
 
242
   JS_XDevPtr priv = xalloc(sizeof(JS_XDevRec));
 
243
 
 
244
   memset(priv, 0, sizeof(JS_XDevRec));
 
245
   local->name = "JAMSTUDIO";
 
246
   local->flags = 0;
 
247
   local->device_control = xf86JS_XProc;
 
248
   local->read_input = xf86JS_XReadInput;
 
249
   local->close_proc = NULL;
 
250
   local->control_proc = xf86JS_XChangeControl;
 
251
   local->switch_mode = xf86JS_XSwitchMode;
 
252
   local->conversion_proc = xf86JS_XConvert;
 
253
   local->fd = -1;
 
254
   local->atom = 0;
 
255
   local->dev = NULL;
 
256
   local->private = priv;
 
257
   local->type_name = "JamStudio";
 
258
   local->history_size = 0;
 
259
   local->old_x = local->old_y = -1;
 
260
 
 
261
   priv->jsxFd = -1;
 
262
   priv->jsxTimeout = 0;
 
263
   priv->jsxDevice = NULL;
 
264
   priv->jsxOldX = -1;
 
265
   priv->jsxOldY = -1;
 
266
   priv->jsxOldPress = priv->jsxOldBtn = priv->jsxOldNotify = -1;
 
267
   priv->jsxMaxX = 8000;
 
268
   priv->jsxMaxY = 6000;
 
269
   priv->jsxMinX = 0;
 
270
   priv->jsxMinY = 0;
 
271
   priv->jsxPressMin = 5;
 
272
   priv->jsxPressMax = 127;
 
273
   priv->jsxPressDiv = 2;
 
274
 
 
275
   return local;
 
276
}
 
277
 
 
278
static void
 
279
xf86JS_XUnInit(InputDriverPtr drv, LocalDevicePtr local, int flags)
 
280
{
 
281
   JS_XDevPtr priv = local->private;
 
282
 
 
283
   xf86JS_XProc(local->dev, DEVICE_CLOSE);
 
284
   xfree(priv);
 
285
   xf86DeleteInput(local, 0);
 
286
}
 
287
 
 
288
static InputInfoPtr
 
289
xf86JS_XInit(InputDriverPtr drv, IDevPtr dev, int flags)
 
290
{
 
291
   LocalDevicePtr local = NULL;
 
292
   JS_XDevPtr priv = NULL;
 
293
   pointer options;
 
294
 
 
295
   if ((local = xf86JS_XAllocate(drv)) == NULL) {
 
296
      xf86Msg(X_ERROR, "Could not allocate local device.\n");
 
297
      return NULL;
 
298
   }
 
299
   if (local->private == NULL) {
 
300
      xf86Msg(X_ERROR, "Could not allocate private structure.\n");
 
301
      xfree(local);
 
302
      return NULL;
 
303
   }
 
304
   local->conf_idev = dev;
 
305
   xf86CollectInputOptions(local, NULL, NULL);
 
306
   options = local->options;
 
307
   local->name = dev->identifier;
 
308
   priv = (JS_XDevPtr) local->private;
 
309
   priv->jsxDevice = xf86FindOptionValue(options, "Device");
 
310
   xf86ProcessCommonOptions(local, local->options);
 
311
   if (!priv->jsxDevice) {
 
312
      xf86Msg(X_ERROR, "JamStudio: No Device specified.\n");
 
313
      return NULL;
 
314
   }
 
315
   priv->jsxMaxX = xf86SetIntOption(options, "MaxX", 8000);
 
316
   priv->jsxMaxY = xf86SetIntOption(options, "MaxY", 6000);
 
317
   priv->jsxMinX = xf86SetIntOption(options, "MinX", 0);
 
318
   priv->jsxMinY = xf86SetIntOption(options, "MinY", 0);
 
319
   priv->jsxPressMax = xf86SetIntOption(options, "PressMax", 127);
 
320
   priv->jsxPressMin = xf86SetIntOption(options, "PressMin", 5);
 
321
   priv->jsxPressDiv = xf86SetIntOption(options, "PressDiv", 2);
 
322
   local->flags |= XI86_POINTER_CAPABLE | XI86_CONFIGURED;
 
323
   return (local);
 
324
}
 
325
 
 
326
InputDriverRec JAMSTUDIO =
 
327
      { 1, "js_x", NULL, xf86JS_XInit, xf86JS_XUnInit, NULL, 0 };
 
328
 
 
329
#ifdef XFree86LOADER
 
330
 
 
331
static void
 
332
xf86JS_XUnplug(pointer p)
 
333
{
 
334
   return;
 
335
}
 
336
 
 
337
static pointer
 
338
xf86JS_XPlug(pointer module, pointer options, int *errmaj, int *errmin)
 
339
{
 
340
   xf86AddInputDriver(&JAMSTUDIO, module, 0);
 
341
   return module;
 
342
}
 
343
 
 
344
static XF86ModuleVersionInfo xf86JS_XVersionRec = {
 
345
   "js_x",
 
346
   MODULEVENDORSTRING,
 
347
   MODINFOSTRING1,
 
348
   MODINFOSTRING2,
 
349
   XF86_VERSION_CURRENT,
 
350
   1, 0, 0,
 
351
   ABI_CLASS_XINPUT,
 
352
   ABI_XINPUT_VERSION,
 
353
   MOD_CLASS_XINPUT,
 
354
   {0, 0, 0, 0}         /* signature, to be patched into the file by a tool */
 
355
};
 
356
 
 
357
XF86ModuleData js_xModuleData = { &xf86JS_XVersionRec,
 
358
   xf86JS_XPlug,
 
359
   xf86JS_XUnplug
 
360
};
 
361
#endif
 
362
#endif