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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/Xprint/ps/PsCache.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
 
 
3
Copyright 1996, 1998  The Open Group
 
4
 
 
5
Permission to use, copy, modify, distribute, and sell this software and its
 
6
documentation for any purpose is hereby granted without fee, provided that
 
7
the above copyright notice appear in all copies and that both that
 
8
copyright notice and this permission notice appear in supporting
 
9
documentation.
 
10
 
 
11
The above copyright notice and this permission notice shall be included in
 
12
all copies or substantial portions of the Software.
 
13
 
 
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
17
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
18
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
19
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
20
 
 
21
Except as contained in this notice, the name of The Open Group shall not be
 
22
used in advertising or otherwise to promote the sale, use or other dealings
 
23
in this Software without prior written authorization from The Open Group.
 
24
 
 
25
*/
 
26
/*
 
27
 * (c) Copyright 1996 Hewlett-Packard Company
 
28
 * (c) Copyright 1996 International Business Machines Corp.
 
29
 * (c) Copyright 1996, 2000 Sun Microsystems, Inc.  All Rights Reserved.
 
30
 * (c) Copyright 1996 Novell, Inc.
 
31
 * (c) Copyright 1996 Digital Equipment Corp.
 
32
 * (c) Copyright 1996 Fujitsu Limited
 
33
 * (c) Copyright 1996 Hitachi, Ltd.
 
34
 *
 
35
 * Permission is hereby granted, free of charge, to any person obtaining
 
36
 * a copy of this software and associated documentation files (the
 
37
 * "Software"), to deal in the Software without restriction, including
 
38
 * without limitation the rights to use, copy, modify, merge, publish,
 
39
 * distribute, sublicense, and/or sell copies of the Software, and to
 
40
 * permit persons to whom the Software is furnished to do so, subject
 
41
 * to the following conditions:
 
42
 *
 
43
 * The above copyright notice and this permission notice shall be included
 
44
 * in all copies or substantial portions of the Software.
 
45
 *
 
46
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
47
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
48
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
49
 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
50
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 
51
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
52
 * SOFTWARE.
 
53
 *
 
54
 * Except as contained in this notice, the names of the copyright holders
 
55
 * shall not be used in advertising or otherwise to promote the sale, use
 
56
 * or other dealings in this Software without prior written authorization
 
57
 * from said copyright holders.
 
58
 */
 
59
 
 
60
/*******************************************************************
 
61
**
 
62
**    *********************************************************
 
63
**    *
 
64
**    *  File:          PsCache.c
 
65
**    *
 
66
**    *  Contents:      Character-caching routines
 
67
**    *
 
68
**    *  Created By:    Jay Hobson (Sun MicroSystems)
 
69
**    *
 
70
**    *  Copyright:     Copyright 1996 The Open Group, Inc.
 
71
**    *
 
72
**    *********************************************************
 
73
**
 
74
********************************************************************/
 
75
 
 
76
#include "Ps.h"
 
77
#include "gcstruct.h"
 
78
#include "windowstr.h"
 
79
#include "fntfil.h"
 
80
#include "fntfilst.h"
 
81
 
 
82
#define  GET  0
 
83
#define  RESET    1
 
84
 
 
85
struct bm_cache_list {
 
86
  struct bm_cache_list *next;
 
87
  struct bm_cache_list *prev;
 
88
        int                   height;
 
89
  long                  id;
 
90
        char                 *pBuffer;
 
91
};
 
92
 
 
93
struct bm_cache_head {
 
94
  struct bm_cache_list *head;
 
95
  int           width;
 
96
  struct bm_cache_head *next;
 
97
        struct bm_cache_head *prev;
 
98
};
 
99
 
 
100
static struct bm_cache_head *bm_cache = NULL;
 
101
 
 
102
static long
 
103
PsBmUniqueId(int func)
 
104
{
 
105
    static long unique_id = 0;
 
106
 
 
107
    if(func == RESET)
 
108
    {
 
109
  unique_id = 0;
 
110
  return 0;
 
111
    }
 
112
    else
 
113
  return ++unique_id;
 
114
}
 
115
 
 
116
int
 
117
PsBmIsImageCached(
 
118
    int gWidth,
 
119
    int gHeight,
 
120
    char *pBuffer)
 
121
{
 
122
    int return_val = 0;
 
123
    struct bm_cache_head *pList = bm_cache;
 
124
 
 
125
    while(pList != NULL && !return_val)
 
126
    {
 
127
        if(pList->width == gWidth)
 
128
        {
 
129
      struct bm_cache_list *pItem = pList->head;
 
130
 
 
131
      while(pItem != NULL)
 
132
      {
 
133
          if(pItem->height == gHeight)
 
134
          {
 
135
          int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
 
136
 
 
137
              if(!memcmp(pItem->pBuffer, pBuffer, sizeof(char)*length))
 
138
              {
 
139
              return_val = pItem->id;
 
140
              break;
 
141
              }
 
142
          }
 
143
      else if(pItem->height > gHeight)
 
144
          break;
 
145
 
 
146
          pItem = pItem->next;
 
147
      }
 
148
        }
 
149
  else if(pList->width > gWidth)
 
150
      break;
 
151
 
 
152
        pList = pList->next;
 
153
    }
 
154
    return return_val;
 
155
}
 
156
 
 
157
int
 
158
PsBmPutImageInCache(
 
159
    int gWidth,
 
160
    int gHeight,
 
161
    char *pBuffer)
 
162
{
 
163
    int return_val = 0;
 
164
    struct bm_cache_head *pList = bm_cache;
 
165
    struct bm_cache_list *pNew;
 
166
    int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
 
167
 
 
168
    if(gWidth == 1 && gHeight == 1 && pBuffer[0] == 0)
 
169
        return return_val;
 
170
 
 
171
    pNew = (struct bm_cache_list *)malloc(sizeof(struct bm_cache_list));
 
172
    pNew->next    = NULL;
 
173
    pNew->prev    = NULL;
 
174
    pNew->height  = gHeight;
 
175
    pNew->id      = PsBmUniqueId(GET);
 
176
    pNew->pBuffer = (char *)malloc(sizeof(char)*length);
 
177
 
 
178
    memcpy(pNew->pBuffer, pBuffer, length);
 
179
 
 
180
    while(pList != NULL)
 
181
    {
 
182
        if(pList->width == gWidth)
 
183
  {
 
184
      struct bm_cache_list *pItem = pList->head;
 
185
 
 
186
      while(pItem != NULL)
 
187
      {
 
188
      if(pItem->height >= gHeight)
 
189
      {
 
190
          pNew->next = pItem;
 
191
          pNew->prev = pItem->prev;
 
192
          if(pItem->prev != NULL)
 
193
             pItem->prev->next = pNew;
 
194
                    else
 
195
             pList->head = pNew;
 
196
                    pItem->prev = pNew;
 
197
 
 
198
          return_val = pNew->id;
 
199
 
 
200
          break;
 
201
      }
 
202
      else if(pItem->next == NULL)
 
203
      {
 
204
          pNew->prev = pItem;
 
205
          pItem->next = pNew;
 
206
 
 
207
          return_val = pNew->id;
 
208
 
 
209
          break;
 
210
      }
 
211
 
 
212
      pItem = pItem->next;
 
213
      }
 
214
 
 
215
      break;
 
216
        }
 
217
 
 
218
        pList = pList->next;
 
219
    }
 
220
 
 
221
    if(pList == NULL)
 
222
    {
 
223
        struct bm_cache_head *pNewList;
 
224
 
 
225
        pNewList = (struct bm_cache_head *)malloc(sizeof(struct bm_cache_head));
 
226
 
 
227
        pNewList->next  = NULL;
 
228
        pNewList->prev  = NULL;
 
229
        pNewList->width = gWidth;
 
230
        pNewList->head  = pNew;
 
231
 
 
232
        if(bm_cache == NULL)
 
233
        {
 
234
      bm_cache = pNewList;
 
235
      return_val = pNew->id;
 
236
        }
 
237
        else
 
238
        {
 
239
      pList = bm_cache;
 
240
 
 
241
      while(pList != NULL)
 
242
      {
 
243
          if(pList->width > gWidth)
 
244
      {
 
245
          pNewList->next  = pList;
 
246
          pNewList->prev  = pList->prev;
 
247
 
 
248
          if(pList->prev != NULL)
 
249
             pList->prev->next = pNewList;
 
250
                    else
 
251
             bm_cache = pNewList;
 
252
          pList->prev = pNewList;
 
253
 
 
254
          return_val = pNew->id;
 
255
 
 
256
          break;
 
257
      }
 
258
      else if(pList->next == NULL)
 
259
                {
 
260
          pNewList->prev  = pList;
 
261
          pList->next = pNewList;
 
262
 
 
263
          return_val = pNew->id;
 
264
 
 
265
          break;
 
266
      }
 
267
 
 
268
      pList = pList->next;
 
269
      }
 
270
        }
 
271
    }
 
272
 
 
273
    return return_val;
 
274
}
 
275
 
 
276
 
 
277
static void
 
278
PsBmClearImageCacheItem(
 
279
    struct bm_cache_list *pItem)
 
280
{
 
281
    if(pItem != NULL)
 
282
    {
 
283
  if(pItem->pBuffer != NULL)
 
284
     free(pItem->pBuffer);
 
285
        pItem->pBuffer = NULL;
 
286
 
 
287
  if(pItem->next)
 
288
     PsBmClearImageCacheItem(pItem->next);
 
289
        pItem->next = NULL;
 
290
 
 
291
  free(pItem);
 
292
  pItem = NULL;
 
293
    }
 
294
}
 
295
 
 
296
static void
 
297
PsBmClearImageCacheList(
 
298
    struct bm_cache_head *pList)
 
299
{
 
300
    if(pList != NULL)
 
301
    {
 
302
  if(pList->head)
 
303
      PsBmClearImageCacheItem(pList->head);
 
304
        pList->head = NULL;
 
305
 
 
306
  if(pList->next)
 
307
      PsBmClearImageCacheList(pList->next);
 
308
        pList->next = NULL;
 
309
 
 
310
  free(pList);
 
311
  pList = NULL;
 
312
    }
 
313
}
 
314
 
 
315
void
 
316
PsBmClearImageCache()
 
317
{
 
318
   PsBmClearImageCacheList(bm_cache);
 
319
 
 
320
   bm_cache = NULL;
 
321
 
 
322
   PsBmUniqueId(RESET);
 
323
}
 
324