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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
34 #include <papi_impl.h>
37 papiServiceCreate(papi_service_t
*handle
, char *service_name
,
38 char *user_name
, char *password
,
39 int (*authCB
)(papi_service_t svc
, void *app_data
),
40 papi_encryption_t encryption
, void *app_data
)
42 service_t
*svc
= NULL
;
46 return (PAPI_BAD_ARGUMENT
);
48 if ((*handle
= svc
= calloc(1, sizeof (*svc
))) == NULL
)
49 return (PAPI_TEMPORARY_ERROR
);
51 svc
->md
= mconnect(path
, 0, 0);
52 if (svc
->md
== NULL
) {
54 gettext("can't connect to spooler for %s: %s"),
55 (service_name
? service_name
: ""), strerror(errno
));
56 return (PAPI_SERVICE_UNAVAILABLE
);
59 svc
->msgbuf_size
= MSGMAX
;
60 if ((svc
->msgbuf
= calloc(1, svc
->msgbuf_size
)) == NULL
)
61 return (PAPI_TEMPORARY_ERROR
);
63 if (service_name
!= NULL
)
64 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_EXCL
,
65 "service-name", service_name
);
67 (void) papiServiceSetUserName(svc
, user_name
);
68 (void) papiServiceSetPassword(svc
, password
);
69 (void) papiServiceSetAuthCB(svc
, authCB
);
70 (void) papiServiceSetAppData(svc
, app_data
);
71 (void) papiServiceSetEncryption(svc
, encryption
);
77 papiServiceDestroy(papi_service_t handle
)
79 service_t
*svc
= handle
;
85 papiAttributeListFree(svc
->attributes
);
91 papiServiceSetUserName(papi_service_t handle
, char *user_name
)
93 service_t
*svc
= handle
;
96 return (PAPI_BAD_ARGUMENT
);
98 return (papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_REPLACE
,
99 "user-name", user_name
));
103 papiServiceSetPassword(papi_service_t handle
, char *password
)
105 service_t
*svc
= handle
;
108 return (PAPI_BAD_ARGUMENT
);
110 return (papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_REPLACE
,
111 "password", password
));
115 papiServiceSetEncryption(papi_service_t handle
,
116 papi_encryption_t encryption
)
118 service_t
*svc
= handle
;
121 return (PAPI_BAD_ARGUMENT
);
123 return (papiAttributeListAddInteger(&svc
->attributes
, PAPI_ATTR_REPLACE
,
124 "encryption", (int)encryption
));
128 papiServiceSetAuthCB(papi_service_t handle
,
129 int (*authCB
)(papi_service_t svc
, void *app_data
))
131 service_t
*svc
= handle
;
134 return (PAPI_BAD_ARGUMENT
);
136 svc
->authCB
= (int (*)(papi_service_t svc
, void *app_data
))authCB
;
142 papiServiceSetAppData(papi_service_t handle
, void *app_data
)
144 service_t
*svc
= handle
;
147 return (PAPI_BAD_ARGUMENT
);
149 svc
->app_data
= (void *)app_data
;
155 papiServiceGetServiceName(papi_service_t handle
)
157 service_t
*svc
= handle
;
161 papiAttributeListGetString(svc
->attributes
, NULL
,
162 "service-name", &result
);
168 papiServiceGetUserName(papi_service_t handle
)
170 service_t
*svc
= handle
;
174 papiAttributeListGetString(svc
->attributes
, NULL
,
175 "user-name", &result
);
181 papiServiceGetPassword(papi_service_t handle
)
183 service_t
*svc
= handle
;
187 papiAttributeListGetString(svc
->attributes
, NULL
,
188 "password", &result
);
194 papiServiceGetEncryption(papi_service_t handle
)
196 service_t
*svc
= handle
;
197 papi_encryption_t result
= PAPI_ENCRYPT_NEVER
;
200 papiAttributeListGetInteger(svc
->attributes
, NULL
,
201 "encryption", (int *)&result
);
207 papiServiceGetAppData(papi_service_t handle
)
209 service_t
*svc
= handle
;
213 result
= svc
->app_data
;
219 papiServiceGetAttributeList(papi_service_t handle
)
221 service_t
*svc
= handle
;
222 papi_attribute_t
**result
= NULL
;
225 lpsched_service_information(&svc
->attributes
);
226 result
= svc
->attributes
;
233 papiServiceGetStatusMessage(papi_service_t handle
)
235 service_t
*svc
= handle
;
239 papiAttributeListGetString(svc
->attributes
, NULL
,
240 "detailed-status-message", &result
);
246 detailed_error(service_t
*svc
, char *fmt
, ...)
248 if ((svc
!= NULL
) && (fmt
!= NULL
)) {
251 char *message
= alloca(BUFSIZ
);
255 * fill in the message. If the buffer is too small, allocate
256 * one that is large enough and fill it in.
258 if ((size
= vsnprintf(message
, BUFSIZ
, fmt
, ap
)) >= BUFSIZ
)
259 if ((message
= alloca(size
)) != NULL
)
260 vsnprintf(message
, size
, fmt
, ap
);
263 papiAttributeListAddString(&svc
->attributes
, PAPI_ATTR_APPEND
,
264 "detailed-status-message", message
);