| 398 | */ |
| 399 | |
| 400 | cups_sc_status_t /* O - Status of first query of @code CUPS_SC_STATUS_OK@ on success */ |
| 401 | cupsSideChannelSNMPWalk( |
| 402 | const char *oid, /* I - First numeric OID to query */ |
| 403 | double timeout, /* I - Timeout for each query in seconds */ |
| 404 | cups_sc_walk_func_t cb, /* I - Function to call with each value */ |
| 405 | void *context) /* I - Application-defined pointer to send to callback */ |
| 406 | { |
| 407 | cups_sc_status_t status; /* Status of command */ |
| 408 | cups_sc_command_t rcommand; /* Response command */ |
| 409 | char *real_data; /* Real data buffer for response */ |
| 410 | int real_datalen; /* Real length of data buffer */ |
| 411 | size_t real_oidlen, /* Length of returned OID string */ |
| 412 | oidlen; /* Length of first OID */ |
| 413 | const char *current_oid; /* Current OID */ |
| 414 | char last_oid[2048]; /* Last OID */ |
| 415 | |
| 416 | |
| 417 | DEBUG_printf(("cupsSideChannelSNMPWalk(oid=\"%s\", timeout=%.3f, cb=%p, " |
| 418 | "context=%p)", oid, timeout, cb, context)); |
| 419 | |
| 420 | /* |
| 421 | * Range check input... |
| 422 | */ |
| 423 | |
| 424 | if (!oid || !*oid || !cb) |
| 425 | return (CUPS_SC_STATUS_BAD_MESSAGE); |
| 426 | |
| 427 | if ((real_data = _cupsBufferGet(_CUPS_SC_MAX_BUFFER)) == NULL) |
| 428 | return (CUPS_SC_STATUS_TOO_BIG); |
| 429 | |
| 430 | /* |
| 431 | * Loop until the OIDs don't match... |
| 432 | */ |
| 433 | |
| 434 | current_oid = oid; |
| 435 | oidlen = strlen(oid); |
| 436 | last_oid[0] = '\0'; |
| 437 | |
| 438 | do |
| 439 | { |
| 440 | /* |
| 441 | * Send the request to the backend and wait for a response... |
| 442 | */ |
| 443 | |
| 444 | if (cupsSideChannelWrite(CUPS_SC_CMD_SNMP_GET_NEXT, CUPS_SC_STATUS_NONE, |
| 445 | current_oid, (int)strlen(current_oid) + 1, timeout)) |
| 446 | { |
| 447 | _cupsBufferRelease(real_data); |
| 448 | return (CUPS_SC_STATUS_TIMEOUT); |
| 449 | } |
| 450 | |
| 451 | real_datalen = _CUPS_SC_MAX_BUFFER; |
| 452 | if (cupsSideChannelRead(&rcommand, &status, real_data, &real_datalen, |
| 453 | timeout)) |
| 454 | { |
| 455 | _cupsBufferRelease(real_data); |
| 456 | return (CUPS_SC_STATUS_TIMEOUT); |
| 457 | } |