dtcm: Coverity 88107
[oweals/cde.git] / cde / programs / dtpdmd / setup.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23
24 /******************************************************************************
25  ******************************************************************************
26  **
27  ** File:         setup.c
28  ** RCS:          $TOG: setup.c /main/4 1997/06/18 17:33:23 samborn $
29  **
30  ** Description:
31  **
32  ** (c) Copyright 1995, Hewlett-Packard Company, all rights reserved.
33  **
34  ******************************************************************************
35  *****************************************************************************/
36
37 #define SETUP_DOT_C
38
39 #include "dtpdmdP.h"
40
41
42 /*********************************************************************
43  *
44  * Setup PDM_MANAGER selection and TYPE atoms
45  */
46 Bool _PdmMgrSetup( Display *sel_display, Window sel_window, Bool security_flag )
47 {
48     enum { XA_PDM_START, XA_PDM_REPLY, XA_TARGETS, XA_TIMESTAMP,
49            XA_MULTIPLE, XA_PDM_START_OK, XA_PDM_START_VXAUTH,
50            XA_PDM_START_PXAUTH, XA_PDM_START_ERROR, XA_PDM_EXIT_OK,
51            XA_PDM_EXIT_CANCEL, XA_PDM_EXIT_VXAUTH, XA_PDM_EXIT_PXAUTH,
52            XA_PDM_EXIT_ERROR, XA_PDM_MBOX, XA_PDM_MAIL, NUM_ATOMS };
53     static char *atom_names[] = { 
54            "PDM_START", "PDM_REPLY", "TARGETS", "TIMESTAMP",
55            "MULTIPLE", "PDM_START_OK", "PDM_START_VXAUTH",
56            "PDM_START_PXAUTH", "PDM_START_ERROR", "PDM_EXIT_OK",
57            "PDM_EXIT_CANCEL", "PDM_EXIT_VXAUTH", "PDM_EXIT_PXAUTH",
58            "PDM_EXIT_ERROR", "PDM_MBOX", "PDM_MAIL" };
59
60     int i;
61     Atom atoms[XtNumber(atom_names)];
62
63     /*
64      * Create PDM_MANAGER atoms.
65      */
66     XInternAtoms( sel_display, atom_names, XtNumber(atom_names), False, atoms );
67
68     g.pdm_selection = XInternAtom( sel_display, g.alt_selection, False );
69     g.pdm_start     = atoms[XA_PDM_START];
70     g.pdm_reply     = atoms[XA_PDM_REPLY];
71     g.pdm_targets   = atoms[XA_TARGETS];
72     g.pdm_timestamp = atoms[XA_TIMESTAMP];
73     g.pdm_multiple  = atoms[XA_MULTIPLE];
74
75     g.pdm_start_ok      = atoms[XA_PDM_START_OK];
76     g.pdm_start_vxauth  = atoms[XA_PDM_START_VXAUTH];
77     g.pdm_start_pxauth  = atoms[XA_PDM_START_PXAUTH];
78     g.pdm_start_error   = atoms[XA_PDM_START_ERROR];
79
80     g.pdm_exit_ok      = atoms[XA_PDM_EXIT_OK];
81     g.pdm_exit_cancel  = atoms[XA_PDM_EXIT_CANCEL];
82     g.pdm_exit_vxauth  = atoms[XA_PDM_EXIT_VXAUTH];
83     g.pdm_exit_pxauth  = atoms[XA_PDM_EXIT_PXAUTH];
84     g.pdm_exit_error   = atoms[XA_PDM_EXIT_ERROR];
85
86     if (security_flag){
87         g.pdm_mbox = atoms[XA_PDM_MBOX];
88         g.pdm_mail = atoms[XA_PDM_MAIL];
89     }
90     else {
91         g.pdm_mbox = (Atom) 0;
92         g.pdm_mail = (Atom) 0;
93     }
94
95     if ( XGetSelectionOwner(sel_display, g.pdm_selection) != None ) {
96         /*
97          * Someone else already owns the selection.
98          */
99         return( /* cannot become owner */ False );
100     }
101     else {
102         /*
103          * Claim ownership of the selection.
104          */
105         i=0;
106         while ((XGetSelectionOwner(sel_display, g.pdm_selection)!=sel_window)) {
107             if ( i++ > 100 )
108                 return( /* cannot become owner */ False );
109
110             XSetSelectionOwner( sel_display, g.pdm_selection, sel_window,
111                                 CurrentTime );
112         }
113     }
114     return( /* became owner */ True );
115 }
116