1 /* -*- Mode: C++-C -*-
2 *
3 *
4 * Copyright 1994 Christopher B. Liebman
5 *
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and that
9 * both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name Christopher B. Liebman not
11 * be used in advertising or publicity pertaining to distribution of this
12 * software without specific, written prior permission.
13 *
14 * THIS SOFTWARE IS PROVIDED `AS-IS'. CHRISTOPHER B. LIEBMAN, DISCLAIMS
15 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
16 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL CHRISTOPHER
18 * B. LIEBMAN, BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING SPECIAL,
19 * INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, OR
20 * PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
21 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF
22 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 *
24 *
25 *
26 * Author : Chris Liebman
27 * Created On : Sat Jan 29 15:17:46 1994
28 * Last Modified By: Chris Liebman
29 * Last Modified On: Sat Feb 19 22:55:49 1994
30 * Update Count : 60
31 * Status : Released
32 *
33 * HISTORY
34 * 13-Feb-1994 Chris Liebman
35 * Last Modified: Sat Feb 12 23:28:52 1994 #42 (Chris Liebman)
36 * Added FormatCommand support.
37 *
38 *
39 * PURPOSE
40 * Resource search.
41 */
42
43 #ifndef lint
44 static char *RCSid = "$Id: face_search_resource.c,v 1.4 1994/03/07 20:26:32 liebman Exp $";
45 #endif
46
47 #include "faces.h"
48 #include "face_search.h"
49
50 static int
FaceSearchResourceWork(fullname,fullclass,item,data)51 FaceSearchResourceWork(fullname, fullclass, item, data)
52 char* fullname;
53 char* fullclass;
54 MailItem* item;
55 FaceSearchData* data;
56 {
57 int ret = 0;
58 XrmDatabase db;
59 String type = NULL;
60 XrmValue value;
61
62 #ifdef RESOURCE_DEBUG
63 fprintf(stderr, "FaceSearchResourceWork: looking for: <%s>/<%s>.\n",
64 fullname, fullclass);
65 #endif
66
67 #if (XtSpecificationRelease > 4)
68 db = XtScreenDatabase(XtScreen(TheTopLevel));
69 #else
70 db = XtDatabase(XtDisplay(TheTopLevel));
71 #endif
72
73 if (XrmGetResource(db, fullname, fullclass, &type, &value) &&
74 (strcmp(type, XtRString) == 0))
75 {
76 ret = FaceSearchLoad(value.addr, item, data);
77 }
78
79 return ret;
80 }
81
82 static int
FaceSearchResource(item,data)83 FaceSearchResource(item, data)
84 MailItem* item;
85 FaceSearchData* data;
86 {
87 char* fullname;
88 char* fullclass;
89 char* appname = XtName(TheTopLevel);
90 char* typename;
91 char* typeclass;
92 int reallen = 0;
93
94 switch(data->format)
95 {
96 case FormatImage:
97 typename = "image";
98 typeclass = "Image";
99 break;
100
101 case FormatAudio:
102 typename = "sound";
103 typeclass = "Sound";
104 break;
105
106 case FormatCommand:
107 typename = "command";
108 typeclass = "Command";
109 break;
110
111 default:
112 return 0;
113 }
114
115 /*
116 * Make a buffer for resource name construction.
117 */
118
119 if (item->realhost != NULL)
120 {
121 reallen = strlen(item->realhost);
122 }
123
124 fullname = XtMalloc(strlen(appname) + strlen(typename) +
125 strlen(item->user) + strlen(item->host) +
126 reallen + 9);
127 fullclass = XtMalloc(strlen(XFACES_CLASS) + strlen(typeclass) +
128 strlen("User@Host") + 9);
129
130 /*
131 * Build a resource name for this sucker.
132 */
133
134 sprintf(fullname, "%s.%s.%s@%s",
135 appname, typename, item->user, item->host);
136 sprintf(fullclass, "%s.%s.User@Host",
137 XFACES_CLASS, typeclass);
138
139 /*
140 * Try to load the thing in.
141 */
142
143 if (FaceSearchResourceWork(fullname, fullclass, item, data))
144 {
145 XtFree(fullname);
146 XtFree(fullclass);
147 return 1;
148 }
149
150 /*
151 * try the real (looked up) hostname.
152 */
153
154 if (item->realhost != NULL)
155 {
156
157 sprintf(fullname, "%s.%s.%s@%s",
158 appname, typename, item->user, item->realhost);
159
160 /*
161 * Try to load the thing in.
162 */
163
164 if (FaceSearchResourceWork(fullname, fullclass, item, data))
165 {
166 XtFree(fullname);
167 XtFree(fullclass);
168 return 1;
169 }
170 }
171
172 /*
173 * Oh well. Lets try for just the user name.
174 */
175
176 sprintf(fullname, "%s.%s.%s", appname, typename, item->user);
177 sprintf(fullclass, "%s.%s.User", XFACES_CLASS, typeclass);
178
179 if (FaceSearchResourceWork(fullname, fullclass, item, data))
180 {
181 XtFree(fullname);
182 XtFree(fullclass);
183 return 1;
184 }
185
186 /*
187 * Oh well. Lets try for just the host name.
188 */
189
190 sprintf(fullname, "%s.%s.%s", appname, typename, item->host);
191 sprintf(fullclass, "%s.%s.Host", XFACES_CLASS, typeclass);
192
193 if (FaceSearchResourceWork(fullname, fullclass, item, data))
194 {
195 XtFree(fullname);
196 XtFree(fullclass);
197 return 1;
198 }
199
200 /*
201 * Oh well. Lets try for just the real (looked up) host name.
202 */
203
204 if (item->realhost != NULL)
205 {
206 sprintf(fullname, "%s.%s.%s", appname, typename, item->realhost);
207
208 if (FaceSearchResourceWork(fullname, fullclass, item, data))
209 {
210 XtFree(fullname);
211 XtFree(fullclass);
212 return 1;
213 }
214 }
215
216 XtFree(fullname);
217 XtFree(fullclass);
218
219 /*
220 * Oh well...
221 */
222
223 return(0);
224 }
225
226 static FaceSearchType resource =
227 {
228 "resource",
229 FaceSearchResource,
230 NULL,
231 NULL,
232 };
233
234 void
FaceSearchResourceInit()235 FaceSearchResourceInit()
236 {
237 FaceSearchTypeRegister(&resource);
238 }
239