Changeset 22 for trunk/samba/source/printing/print_cups.c
- Timestamp:
- Mar 25, 2007, 3:18:51 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/samba/source/printing/print_cups.c
r1 r22 1199 1199 }; 1200 1200 1201 BOOL cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer) 1202 { 1203 http_t *http = NULL; /* HTTP connection to server */ 1204 ipp_t *request = NULL, /* IPP Request */ 1205 *response = NULL; /* IPP Response */ 1206 ipp_attribute_t *attr; /* Current attribute */ 1207 cups_lang_t *language = NULL; /* Default language */ 1208 char *name, /* printer-name attribute */ 1209 *info, /* printer-info attribute */ 1210 *location; /* printer-location attribute */ 1211 char uri[HTTP_MAX_URI]; 1212 static const char *requested[] =/* Requested attributes */ 1213 { 1214 "printer-name", 1215 "printer-info", 1216 "printer-location" 1217 }; 1218 BOOL ret = False; 1219 1220 DEBUG(5, ("pulling %s location\n", printer->sharename)); 1221 1222 /* 1223 * Make sure we don't ask for passwords... 1224 */ 1225 1226 cupsSetPasswordCB(cups_passwd_cb); 1227 1228 /* 1229 * Try to connect to the server... 1230 */ 1231 1232 if ((http = cups_connect()) == NULL) { 1233 goto out; 1234 } 1235 1236 request = ippNew(); 1237 1238 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES; 1239 request->request.op.request_id = 1; 1240 1241 language = cupsLangDefault(); 1242 1243 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1244 "attributes-charset", NULL, cupsLangEncoding(language)); 1245 1246 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1247 "attributes-natural-language", NULL, language->language); 1248 1249 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s", 1250 lp_cups_server(), printer->sharename); 1251 1252 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, 1253 "printer-uri", NULL, uri); 1254 1255 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME, 1256 "requested-attributes", 1257 (sizeof(requested) / sizeof(requested[0])), 1258 NULL, requested); 1259 1260 /* 1261 * Do the request and get back a response... 1262 */ 1263 1264 if ((response = cupsDoRequest(http, request, "/")) == NULL) { 1265 DEBUG(0,("Unable to get printer attributes - %s\n", 1266 ippErrorString(cupsLastError()))); 1267 goto out; 1268 } 1269 1270 for (attr = response->attrs; attr != NULL;) { 1271 /* 1272 * Skip leading attributes until we hit a printer... 1273 */ 1274 1275 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) 1276 attr = attr->next; 1277 1278 if (attr == NULL) 1279 break; 1280 1281 /* 1282 * Pull the needed attributes from this printer... 1283 */ 1284 1285 name = NULL; 1286 info = NULL; 1287 location = NULL; 1288 1289 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) { 1290 /* Grab the comment if we don't have one */ 1291 if ( (strcmp(attr->name, "printer-info") == 0) 1292 && (attr->value_tag == IPP_TAG_TEXT) 1293 && !strlen(printer->comment) ) 1294 { 1295 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n", 1296 attr->values[0].string.text)); 1297 pstrcpy(printer->comment,attr->values[0].string.text); 1298 } 1299 1300 /* Grab the location if we don't have one */ 1301 if ( (strcmp(attr->name, "printer-location") == 0) 1302 && (attr->value_tag == IPP_TAG_TEXT) 1303 && !strlen(printer->location) ) 1304 { 1305 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n", 1306 attr->values[0].string.text)); 1307 fstrcpy(printer->location,attr->values[0].string.text); 1308 } 1309 1310 attr = attr->next; 1311 } 1312 1313 /* 1314 * See if we have everything needed... 1315 */ 1316 1317 if (name == NULL) 1318 break; 1319 1320 } 1321 1322 ippDelete(response); 1323 response = NULL; 1324 1325 ret = True; 1326 1327 out: 1328 if (response) 1329 ippDelete(response); 1330 1331 if (language) 1332 cupsLangFree(language); 1333 1334 if (http) 1335 httpClose(http); 1336 1337 return ret; 1338 } 1339 1201 1340 #else 1202 1341 /* this keeps fussy compilers happy */
Note: See TracChangeset
for help on using the changeset viewer.