Calling the Printer Client Function
The following code could be used to call the get_address_of_printer() routine shown above.
char* printer_server;
printer_server = get_address_of_printer
"thisorgunit/service/printer/colorful",
"onc_bsdaddr");
|
Server
Using the XFN APIs, print servers can advertise their services. Example 3-3 illustrates a
host, labpc, that would like to advertise the binding
for the color printer colorful. The FNS name for this
printer is thisorgunit/service/printer/colorful.
The main tasks are to obtain the composite name for the printer name,
to generate the binding (reference) for the printer, and to bind the name
and references to the FNS namespace.
Example 3-3 Print Server Source
#include <stdio.h>
#include <xfn/xfn.h>
#include <string.h>
/*
* Routine to export the printer binding to the FNS name space.
* This routine takes the printer name along with its
* reference type, address type, and address. Returns the status.
*/
int
export_printer_to_fns(const char *printer_name,
const char *reference_type,
const char *address_type,
const char *address_data)
{
int return_status;
FN_composite_name_t *printer_name_comp;
FN_identifier_t ref_id, addr_id;
FN_status_t *status;
FN_ref_t *printer_ref;
FN_ref_addr_t *address;
FN_ctx_t *initial_context;
/* Obtain the initial context */
status = fn_status_create();
initial_context = fn_ctx_handle_from_initial(0, status);
/* Check status for any error messages */
if ((return_status = fn_status_code(status)) != FN_SUCCESS) {
fprintf(stderr, "Unable to obtain the initial context\n");
return (return_status);
}
/* Construct the composite name for the printer name */
printer_name_comp = fn_composite_name_from_string(
(unsigned char *)printer_name);
/* Construct the printer address */
addr_id.format = FN_ID_STRING;
addr_id.length = strlen(address_type);
addr_id.contents = (void *) address_type;
address = fn_ref_addr_create(&addr_id,
strlen(address_data), (const void *) address_data);
/* Construct the printer reference */
ref_id.format = FN_ID_STRING;
ref_id.length = strlen(reference_type);
ref_id.contents = (void *) reference_type;
printer_ref = fn_ref_create(&ref_id);
/* Add the printer address to the printer reference */
fn_ref_append_addr(printer_ref, address);
/* Bind the reference to the context */
fn_ctx_bind(initial_context, printer_name_comp, printer_ref, 0,
status);
/* Check the error status and return */
return_status = fn_status_code(status);
fn_composite_name_destroy(printer_name_comp);
fn_ref_addr_destroy(address);
fn_ref_destroy(printer_ref);
fn_status_destroy(status);
fn_ctx_handle_destroy(initial_context);
return (return_status);
}
|
Calling the Printer Server Function
The following code could be used to call the export_printer_to_fns() routine shown above.
export_printer_to_fns
"thisorgunit/service/printer/colorful",
"onc_printers",
"onc_bsdaddr",
"labpc");
|