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

« back to all changes in this revision

Viewing changes to unix/xc/extras/FreeType/contrib/ftos2/ifi/ftmem.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
/*           ** This is part of the FreeType/2 project! **             */
 
3
/* A small utility to display online memory usage stats for FreeType/2 */
 
4
/*                                                                     */
 
5
/* The method used to keep the window float on top may be completely   */
 
6
/* stupid but I found no other way (except putting WinSetWindowPos()   */
 
7
/* in the timer code which looks odd).                                 */
 
8
/*                                                                     */
 
9
/*                Copyright (C) 1998 by M. Necasek                     */
 
10
 
 
11
#define INCL_DOSMISC
 
12
#define INCL_WINTIMER
 
13
#define INCL_PM
 
14
#include <os2.h>
 
15
#include <stdio.h>
 
16
 
 
17
#define ID_TIMER  42
 
18
#define IDM_FLOAT 155
 
19
 
 
20
 
 
21
/* name of shared memory used for memory usage reporting  */
 
22
#define MEM_NAME  "\\sharemem\\freetype"
 
23
 
 
24
typedef struct _INFOSTRUCT {
 
25
  ULONG  signature;      /* signature (0x46524545, 'FREE') */
 
26
  ULONG  used;           /* bytes actually used */
 
27
  ULONG  maxused;        /* maximum amount ever used */
 
28
  ULONG  num_err;        /* number of (de)allocation errors */
 
29
} INFOSTRUCT, *PINFOSTRUCT;
 
30
 
 
31
/* structure (in named shared memory) pointing to the above struct */
 
32
typedef struct _INFOPTR {
 
33
  PINFOSTRUCT  address;        /* pointer to actual memory info  */
 
34
} INFOPTR, *PINFOPTR;
 
35
 
 
36
HAB          hab;
 
37
HWND         hwndFrame;
 
38
PINFOSTRUCT  meminfo;
 
39
PINFOPTR     memptr;
 
40
ULONG        bFloat = TRUE;
 
41
HWND         hwndSysSubmenu;
 
42
 
 
43
VOID AddFloat(HWND hwndFrame) {
 
44
   MENUITEM  mi;
 
45
   HWND      hwndSysMenu;
 
46
   SHORT     sMenuID;
 
47
 
 
48
   /* add Float option to system menu */
 
49
   hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
 
50
   sMenuID = (SHORT)WinSendMsg(hwndSysMenu, MM_ITEMIDFROMPOSITION,
 
51
                               MPFROMSHORT(0), MPVOID);
 
52
   WinSendMsg(hwndSysMenu, MM_QUERYITEM, MPFROMSHORT(sMenuID),
 
53
              MPFROMP(&mi));
 
54
   hwndSysSubmenu = mi.hwndSubMenu;
 
55
   mi.iPosition = MIT_END;
 
56
   mi.afStyle = MIS_SEPARATOR;
 
57
   mi.afAttribute = 0;
 
58
   mi.id = -1;
 
59
   mi.hwndSubMenu = 0;
 
60
   mi.hItem = 0;
 
61
   WinSendMsg(hwndSysSubmenu, MM_INSERTITEM, MPFROMP (&mi), NULL);
 
62
   mi.afStyle = MIS_TEXT;
 
63
   mi.afAttribute = MIA_CHECKED;
 
64
   mi.id = IDM_FLOAT;
 
65
   WinSendMsg(hwndSysSubmenu, MM_INSERTITEM, MPFROMP (&mi), "~Float on top");
 
66
}
 
67
 
 
68
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 
69
{
 
70
   HPS      hps;
 
71
   RECTL    rcl;
 
72
   static ULONG    i = 1;
 
73
   ULONG    ulMem;
 
74
   char     szBuf[200];
 
75
 
 
76
   switch (msg) {
 
77
      case WM_CREATE:
 
78
         /* use smaller text */
 
79
         WinSetPresParam(hwnd, PP_FONTNAMESIZE, 7, (PVOID)"8.Helv");
 
80
         /* start the timer (ticks each 0.5 sec.) */
 
81
         AddFloat(WinQueryWindow(hwnd, QW_PARENT));
 
82
         WinStartTimer(hab, hwnd, ID_TIMER, 500);
 
83
         break;
 
84
 
 
85
      /* make window always stay on top (if desired) */
 
86
      case WM_VRNENABLED:
 
87
         if (bFloat)
 
88
            WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
 
89
         break;
 
90
 
 
91
      case WM_COMMAND:  /* why doesn't WM_SYSCOMMAND work? */
 
92
         if (LOUSHORT(mp1) == IDM_FLOAT) {
 
93
            bFloat = !bFloat;
 
94
            WinCheckMenuItem(hwndSysSubmenu, IDM_FLOAT, bFloat);
 
95
         }
 
96
         break;
 
97
 
 
98
      case WM_TIMER:
 
99
         if (++i > 13)
 
100
            i = 1;
 
101
         WinInvalidateRect(hwnd, NULL, FALSE);
 
102
         return FALSE;
 
103
 
 
104
      case WM_PAINT:
 
105
         hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
 
106
         /* necessary to avoid incorrectly repainting window */
 
107
         WinQueryWindowRect(hwnd, &rcl);
 
108
 
 
109
/*         sprintf(szBuf, " Current use %dK  Maximum ever used %dK  Errors %d",
 
110
                 meminfo->used / 1024,
 
111
                 meminfo->maxused / 1024, meminfo->num_err);*/
 
112
         sprintf(szBuf, " Current use %dB  Maximum ever used %dK  Errors %d",
 
113
                 meminfo->used,
 
114
                 meminfo->maxused / 1024, meminfo->num_err);
 
115
         WinDrawText(hps, -1, szBuf, &rcl, CLR_BLACK, CLR_WHITE,
 
116
                     DT_CENTER | DT_VCENTER | DT_ERASERECT);
 
117
 
 
118
         WinEndPaint(hps);
 
119
         break;
 
120
   }
 
121
 
 
122
   return WinDefWindowProc(hwnd, msg, mp1, mp2);
 
123
}
 
124
 
 
125
void main (void)
 
126
{
 
127
   QMSG  qmsg;
 
128
   HMQ   hmq;
 
129
   HWND  hwndClient;
 
130
   ULONG flFrameFlags;
 
131
 
 
132
   WinInitialize(0);
 
133
   hmq = WinCreateMsgQueue(hab, 0);
 
134
 
 
135
   /* get access to shared memory */
 
136
   DosGetNamedSharedMem((PVOID*)&memptr, MEM_NAME, PAG_READ);
 
137
   if (!memptr)
 
138
      WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
 
139
                    "  FreeType/2 is not running!",
 
140
                    "Error", 0, MB_OK | MB_ERROR);
 
141
 
 
142
   else {
 
143
      meminfo = memptr->address;
 
144
      if (meminfo->signature != 0x46524545)
 
145
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
 
146
                       "  FreeType/2 is not running!",
 
147
                       "Error", 0, MB_OK | MB_ERROR);
 
148
      else {
 
149
         flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
 
150
                        FCF_TASKLIST ;
 
151
 
 
152
         WinRegisterClass(hab, "MyClass",
 
153
                          (PFNWP) ClientWndProc,
 
154
                          CS_SIZEREDRAW, 0);
 
155
 
 
156
         hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
 
157
                                        WS_VISIBLE,
 
158
                                        &flFrameFlags,
 
159
                                        "MyClass", "FreeType/2 Heap Usage",
 
160
                                        0, (HMODULE) NULL,
 
161
                                        0, &hwndClient);
 
162
 
 
163
         WinSetVisibleRegionNotify(hwndClient, TRUE);
 
164
 
 
165
         /* make titlebar text look better */
 
166
         WinSetPresParam(WinWindowFromID(hwndFrame, FID_TITLEBAR),
 
167
                         PP_FONTNAMESIZE, 9, (PVOID)"8.Helv");
 
168
 
 
169
         WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 350, 42,
 
170
                         SWP_MOVE | SWP_SIZE | SWP_SHOW);
 
171
 
 
172
         while (WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0))
 
173
            WinDispatchMsg(hab, &qmsg);
 
174
 
 
175
         WinSetVisibleRegionNotify(hwndClient, FALSE);
 
176
      }
 
177
   }
 
178
   /* free shared memory block */
 
179
   DosFreeMem(memptr);
 
180
 
 
181
   WinDestroyWindow(hwndFrame);
 
182
   WinDestroyMsgQueue(hmq);
 
183
   WinTerminate(hab);
 
184
}