4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: service.c 163 2006-05-09 15:07:45Z njacobs $ */
30 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <papi_impl.h>
41 service_fill_in(service_t
*svc
, char *name
)
43 papi_status_t status
= PAPI_OK
;
47 return (PAPI_BAD_ARGUMENT
);
53 * valid URIs are in the form:
54 * lpd://server[:port]/.../queue[#extensions]
55 * rfc-1179://server[:port]/.../queue[#extensions]
56 * any authentication information supplied the URI is ignored.
58 if (uri_from_string((char *)name
, &uri
) != -1) {
59 if ((strcasecmp(uri
->scheme
, "lpd") == 0) ||
60 (strcasecmp(uri
->scheme
, "rfc-1179") == 0)) {
66 status
= PAPI_URI_SCHEME
;
74 papiServiceCreate(papi_service_t
*handle
, char *service_name
,
75 char *user_name
, char *password
,
76 int (*authCB
)(papi_service_t svc
, void *app_data
),
77 papi_encryption_t encryption
, void *app_data
)
80 service_t
*svc
= NULL
;
83 return (PAPI_BAD_ARGUMENT
);
85 if ((*handle
= svc
= (service_t
*)calloc(1, sizeof (*svc
))) == NULL
)
86 return (PAPI_TEMPORARY_ERROR
);
88 if (service_name
!= NULL
)
89 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_EXCL
,
90 "service-name", service_name
);
92 (void) papiServiceSetUserName(svc
, user_name
);
93 (void) papiServiceSetPassword(svc
, password
);
94 (void) papiServiceSetAuthCB(svc
, authCB
);
95 (void) papiServiceSetAppData(svc
, app_data
);
96 (void) papiServiceSetEncryption(svc
, encryption
);
98 status
= service_fill_in(svc
, service_name
);
104 papiServiceDestroy(papi_service_t handle
)
106 if (handle
!= NULL
) {
107 service_t
*svc
= handle
;
110 if (svc
->cache
!= NULL
)
111 cache_free(svc
->cache
);
113 if (svc
->uri
!= NULL
)
115 if (svc
->attributes
!= NULL
)
116 papiAttributeListFree(svc
->attributes
);
122 papiServiceSetUserName(papi_service_t handle
, char *user_name
)
124 service_t
*svc
= handle
;
127 return (PAPI_BAD_ARGUMENT
);
129 return (papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_REPLACE
,
130 "user-name", user_name
));
134 papiServiceSetPassword(papi_service_t handle
, char *password
)
136 service_t
*svc
= handle
;
139 return (PAPI_BAD_ARGUMENT
);
141 return (papiAttributeListAddString(&svc
->attributes
,
142 PAPI_ATTR_REPLACE
, "password", password
));
146 papiServiceSetEncryption(papi_service_t handle
,
147 papi_encryption_t encryption
)
149 service_t
*svc
= handle
;
152 return (PAPI_BAD_ARGUMENT
);
154 return (papiAttributeListAddInteger(&svc
->attributes
, PAPI_ATTR_REPLACE
,
155 "encryption", (int)encryption
));
159 papiServiceSetAuthCB(papi_service_t handle
,
160 int (*authCB
)(papi_service_t svc
, void *app_data
))
162 service_t
*svc
= handle
;
165 return (PAPI_BAD_ARGUMENT
);
167 svc
->authCB
= (int (*)(papi_service_t svc
, void *))authCB
;
173 papiServiceSetAppData(papi_service_t handle
, void *app_data
)
175 service_t
*svc
= handle
;
178 return (PAPI_BAD_ARGUMENT
);
180 svc
->app_data
= (void *)app_data
;
186 papiServiceGetServiceName(papi_service_t handle
)
188 service_t
*svc
= handle
;
192 papiAttributeListGetString(svc
->attributes
, NULL
,
193 "service-name", &result
);
199 papiServiceGetUserName(papi_service_t handle
)
201 service_t
*svc
= handle
;
205 papiAttributeListGetString(svc
->attributes
, NULL
,
206 "user-name", &result
);
213 papiServiceGetPassword(papi_service_t handle
)
215 service_t
*svc
= handle
;
219 papiAttributeListGetString(svc
->attributes
, NULL
,
220 "password", &result
);
226 papiServiceGetEncryption(papi_service_t handle
)
228 service_t
*svc
= handle
;
229 papi_encryption_t result
= PAPI_ENCRYPT_NEVER
;
232 papiAttributeListGetInteger(svc
->attributes
, NULL
,
233 "encryption", (int *)&result
);
239 papiServiceGetAppData(papi_service_t handle
)
241 service_t
*svc
= handle
;
245 result
= svc
->app_data
;
253 papiServiceGetAttributeList(papi_service_t handle
)
255 service_t
*svc
= handle
;
256 papi_attribute_t
**result
= NULL
;
259 result
= svc
->attributes
;
265 papiServiceGetStatusMessage(papi_service_t handle
)
267 service_t
*svc
= handle
;
271 papiAttributeListGetString(svc
->attributes
, NULL
,
272 "detailed-status-message", &result
);
279 detailed_error(service_t
*svc
, char *fmt
, ...)
281 if ((svc
!= NULL
) && (fmt
!= NULL
)) {
284 char *message
= alloca(BUFSIZ
);
288 * fill in the message. If the buffer is too small, allocate
289 * one that is large enough and fill it in.
291 if ((size
= vsnprintf(message
, BUFSIZ
, fmt
, ap
)) >= BUFSIZ
)
292 if ((message
= alloca(size
)) != NULL
)
293 vsnprintf(message
, size
, fmt
, ap
);
296 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_APPEND
,
297 "detailed-status-message", message
);