Tải bản đầy đủ (.pdf) (69 trang)

Common UNIX Printing System Sweet phần 9 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.31 MB, 69 trang )

< previous page page_511 next page >
Page 511
http_t *http; http = httpConnect(cupsServer(), ippPort());
See Also
httpClose(), httpConnectEncrypt(), httpGet(), httpGets(), httpPost(), httpRead(), httpWrite()
httpConnectEncrypt()
Usage
http_t * httpConnectEncrypt(const char *hostname, int port, http_encryption_t encryption);
Arguments
Argument Type Description
hostname const char * The hostname or IP address of the server that is to be contacted
port int The port number that is to be used
encryption http_encryption_t The type of encryption that is to be used
Returns
A pointer to an HTTP connection structure or NULL if the connection could not be made.
Description
The httpConnectEncrypt() function opens an HTTP connection to the specified server and port using the
specified encryption mode.
Example
#include <cups/http.h> http_t *http; http = httpConnectEncrypt(cupsServer(), ippPort(),
HTTP_ENCRYPT_REQUIRED);
< previous page page_511 next page >
< previous page page_512 next page >
Page 512
See Also
httpClose(), httpConnect(), httpGet(), httpGets(), httpPost(), httpRead(), httpWrite()
httpDecode64()
Usage
char * httpDecode64(char *out, const char *in);
Arguments
Argument Type Description


out char * The output string
in const char * The input string
Returns
A pointer to the decoded string.
Description
The httpDecode64() function decodes a base-64 encoded string to the original string.
Example
#include <cups/http.h> char encoded_string[255]; char original_string[255]; httpDecode64
(original_string, encoded_string);
See Also
httpEncode64()
< previous page page_512 next page >
< previous page page_513 next page >
Page 513
httpDelete()
Usage
int httpDelete(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI that is to be deleted
Returns
0 on success, non-zero on failure.
Description
The httpDelete() function sends an HTTP DELETE request to the server.
Example
#include <cups/http.h> http_t *http; httpDelete(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpEncode64()

Usage
char * httpEncode64(char *out, const char *in);
< previous page page_513 next page >
< previous page page_514 next page >
Page 514
Arguments
Argument Type Description
out char * The output string
in const char * The input string
Returns
A pointer to the encoded string.
Description
The httpEncode64() function decodes a base-64 encoded string to the original string.
Example
#include <cups/http.h> char encoded_string[255]; char original_string[255]; httpEncode64
(encoded_string, original_string);
See Also
httpDecode64()
httpEncryption()
Usage
void httpEncryption(http_t *http, http_encryption_t encryption);
Arguments
Argument Type Description
http http_t * The HTTP connection
encryption http_encryption_t The type of encryption that is to be used
< previous page page_514 next page >
< previous page page_515 next page >
Page 515
Description
The httpEncryption() function sets the type of encryption that is to be used on the connection to the HTTP

server. This function may close and reconnect to the server to establish the new type of encryption.
Example
#include <cups/http.h> http_t *http; httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
See Also
httpConnectEncrypt()
httpError()
Usage
int httpError(http_t *http);
Arguments
Argument Type Description
http http_t * The HTTP connection
Returns
The last error that occurred or 0 if no error has occurred.
Description
The httpError() function returns the last error that occurred on the HTTP connection.
Example
#include <cups/http.h> http_t *http;
< previous page page_515 next page >
< previous page page_516 next page >
Page 516
if (httpError(http)) { show an error message }
See Also
httpConnect()
httpFlush()
Usage
void httpFlush(http_t *http);
Arguments
Argument Type Description
http http_t * The HTTP connection
Description

The httpFlush() function flushes any remaining data left from a GET or POST operation.
Example
#include <cups/http.h> http_t *http; httpFlush(http);
See Also
httpConnect()
< previous page page_516 next page >
< previous page page_517 next page >
Page 517
httpGet()
Usage
int httpGet(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to GET
Returns
0 on success, non-zero on failure.
Description
The httpGet() function sends an HTTP GET request to the server.
Example
#include <cups/http.h> http_t *http; httpGet(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpGetDateString()
Usage
const char * httpGetDateString(time_t time);
< previous page page_517 next page >
< previous page page_518 next page >
Page 518
Arguments

Argument Type Description
time time_t The Unix date/time value
Returns
A pointer to a static string containing the HTTP date/time string for the specified Unix time value.
Description
The httpGetDateString() function generates a date/time string suitable for HTTP requests from a Unix
time value. The date/time string is overwritten with each call.
Example
#include <cups/http.h> puts(httpGetDateString(time(NULL)));
See Also
httpGetDateTime()
httpGetDateTime()
Usage
time_t httpGetDateTime(const char *date);
Arguments
Argument Type Description
date const char * The HTTP date/time string
Returns
A Unix time value.
< previous page page_518 next page >
< previous page page_519 next page >
Page 519
Description
The httpGetDateTime() function converts an HTTP date/time string to a Unix time value.
Example
#include <cups/http.h> printf(''%d\n", httpGetDateTime("Fri, 30 June 2000 12:34:56 GMT"));
See Also
httpGetDateString()
httpGetField()
Usage

const char * httpGetField(http_t *http, http_field_t field);
Arguments
Argument Type Description
http http_t * The HTTP connection
field http_field_t The HTTP field
Returns
A pointer to the field value string.
Description
The httpGetField() function returns the current value for the specified HTTP field. An empty field is
represented by a string of 0 length.
Example
#include <cups/http.h> http_t *http;
< previous page page_519 next page >
< previous page page_520 next page >
Page 520
httpGet(http, ''/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE); puts(httpGetField(http,
HTTP_FIELD_CONTENT_TYPE));
See Also
httpGetSubField(), httpSetField()
httpGetLength()
Usage
int httpGetLength(http_t *http);
Arguments
Argument Type Description
http http_t * The HTTP connection
Returns
The content length of the GET or POST data.
Description
The httpGetLength() function returns the number of bytes returned by a GET or POST request.
Example

#include <cups/http.h> http_t *http; httpGet(http, "/some/uri"); while (httpUpdate(http) ==
HTTP_CONTINUE); printf("Content length = %d\n", httpGetLength(http));
< previous page page_520 next page >
< previous page page_521 next page >
Page 521
See Also
httpConnect()
httpGets()
Usage
char * httpGets(char *line, int length, http_t *http)
Arguments
Argument Type Description
line char * The line buffer
length int The size of the line buffer in bytes
http http_t * The HTTP connection
Returns
A pointer to the string or NULL if no line could be retrieved.
Description
The httpGets() function is used to read a request line from the HTTP connection. It is not normally used
by a client program.
Example
#include <cups/http.h> http_t *http; char line[1024]; if (httpGets(line, sizeof(line), http)) { process
the line }
< previous page page_521 next page >
< previous page page_522 next page >
Page 522
See Also
httpConnect(), httpUpdate()
httpGetSubField()
Usage

const char * httpGetSubField(http_t *http, http_field_t field, const char *name, char *value);
Arguments
Argument Type Description
http http_t * The HTTP connection
field http_field_t The HTTP field
name const char * The sub-field name
value char [HTTP_MAX_NAME] The sub-field value
Returns
A pointer to the sub-field value string or NULL if the field is not defined.
Description
The httpGetSubField() function returns a sub-value from the specified HTTP field. If the sub-field is not
present, the value string is cleared and NULL is returned.
Example
#include <cups/http.h> http_t *http; char value[HTTP_MAX_VALUE];
< previous page page_522 next page >
< previous page page_523 next page >
Page 523
httpGet(http, ''/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE); if (httpGetSubField(http,
HTTP_FIELD_WWW_AUTHENTICATE, "realm", value)) printf("please enter password for %s:", value);
See Also
httpGetField()
httpHead()
Usage
int httpHead(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to HEAD
Returns
0 on success, non-zero on failure.

Description
The httpHead() function sends an HTTP HEAD request to the server.
Example
#include <cups/http.h> http_t *http; httpHead(http, "/some/uri");
< previous page page_523 next page >
< previous page page_524 next page >
Page 524
See Also
httpConnect(), httpSetField(), httpUpdate()
httpInitialize()
Usage
void httpInitialize(void);
Description
The httpInitialize() function initializes the networking code as needed by the underlying platform. It is
called automatically by the httpConnect() and httpConnectEncrypt() functions.
Example
#include <cups/http.h> httpInitialize();
See Also
httpConnect(), httpConnectEncrypt()
httpMD5()
Usage
char * httpMD5(const char *username, const char *realm, const char *passwd, char md5[33]);
Arguments
Argument Type Description
username const char * The username for the MD5 sum
realm const char * The realm for the MD5 sum
< previous page page_524 next page >
< previous page page_525 next page >
Page 525
passwd const char * The password for the MD5 sum

md5 char [33] The MD5 sum in hexadecimal
Returns
A pointer to the MD5 sum string.
Description
The httpMD5() function computes the MD5 sum of the username, realm, and password separated by
colons (:).
Example
#include <cups/http.h> char md5[33]; puts(httpMD5(''username", "realm", "password", md5);
See Also
httpMD5Final(), httpMD5String()
httpMD5Final()
Usage
char * httpMD5Final (const char *nonce, const char *method, const char *resource, char md5[33])
< previous page page_525 next page >
< previous page page_526 next page >
Page 526
Arguments
Argument Type Description
nonce const char * The server-supplied nonce string
method const char * The request method string
resource const char * The resource path in the request
md5 char [33] The MD5 sum in hexadecimal
Returns
The MD5 sum string.
Description
The httpMD5Final() function updates the MD5 sum computed by httpMD5() to include the server-supplied
nonce value, the method string (''GET", "POST", and so forth), and the resource path. The output is the
final MD5 sum used for authentication.
Example
#include <cups/http.h> char md5[33]; httpMD5Final("nonce", "GET", "/", md5);

See Also
httpMD5(), httpMD5String()
httpMD5String()
Usage
char * httpMD5String(const md5_byte_t *sum, char md5[33])
< previous page page_526 next page >
< previous page page_527 next page >
Page 527
Arguments
Argument Type Description
sum const md5_byte_t * The raw MD5 sum
md5 char [33] The MD5 sum in hexadecimal
Returns
The MD5 string.
Description
The httpMD5String() function converts a 16-byte raw MD5 sum to a 32-byte hexadecimal string.
Example
#include <cups/http.h> md5_byte_t digest[16]; char md5[33]; puts(httpMD5String(digest, md5));
See Also
httpMD5(), httpMD5Final()
httpOptions()
Usage
int httpOptions(http_t *http, const char *uri);
< previous page page_527 next page >
< previous page page_528 next page >
Page 528
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to check for options

Returns
0 on success, non-zero on failure.
Description
The httpOptions() function sends an HTTP OPTIONS request to the server.
Example
#include <cups/http.h> http_t *http; httpOptions(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpPost()
Usage
int httpPost(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to POST to
< previous page page_528 next page >
< previous page page_529 next page >
Page 529
Returns
0 on success, non-zero on failure.
Description
The httpPost() function sends an HTTP POST request to the server.
Example
#include <cups/http.h> http_t *http; httpPost(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpPrintf()
Usage
int httpPrintf(http_t *http, const char *format, );
Arguments

Argument Type Description
http http_t * The HTTP connection
format const char * A printf-style format string
varies Additional arguments as needed
Returns
The number of bytes written.
< previous page page_529 next page >
< previous page page_530 next page >
Page 530
Description
The httpPrintf() function sends a formatted string to the HTTP connection. Normally, only the CUPS API
and scheduler use it.
Example
#include <cups/http.h> http_t *http; httpPrintf(http, ''GET / HTTP/1.1 \r\n");
See Also
httpConnect()
httpPut()
Usage
int httpPut(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to PUT to
Returns
0 on success, non-zero on failure.
Description
The httpPut() function sends an HTTP PUT request to the server.
Example
#include <cups/http.h>
< previous page page_530 next page >

< previous page page_531 next page >
Page 531
http_t *http; httpPut(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpRead()
Usage
int httpRead(http_t *http, char *buffer, int length);
Arguments
Argument Type Description
http http_t * The HTTP connection
buffer char * The buffer to read into
length int The maximum number of bytes to read
Returns
The number of bytes read or -1 on error.
Description
The httpRead() function reads data from the HTTP connection, possibly the result of a GET or POST
request.
Example
#include <cups/http.h> http_t *http; char buffer[1024]; int bytes;
< previous page page_531 next page >
< previous page page_532 next page >
Page 532
httpGet(http, ''/"); while (httpUpdate(http) != HTTP_CONTINUE); while ((bytes = httpRead(http, buffer,
sizeof(buffer) - 1)) > 0) { buffer[bytes] = '\0'; fputs(buffer, stdout); }
See Also
httpConnect(), httpWrite()
httpReconnect()
Usage
int httpReconnect(http_t *http);

Arguments
Argument Type Description
http http_t * The HTTP connection
Returns
0 on success, non-zero on failure.
Description
The httpReconnect() function reconnects to the HTTP server. This is usually done automatically if the
HTTP functions detect that the server connection has terminated.
Example
#include <cups/http.h> http_t *http; httpReconnect(http);
< previous page page_532 next page >
< previous page page_533 next page >
Page 533
See Also
httpConnect(), httpConnectEncrypt()
httpSeparate()
Usage
void httpSeparate(const char *uri, char *method, char *username, char *host, int *port, char *resource);
Arguments
ArgumentType Description
uri const char* The URI that is to be separated
method char [HTTP_MAX_URI]The method (scheme) of the URI
usernamechar [HTTP_MAX_URI]The username (and password) portion of the URI, if any
host char [HTTP_MAX_URI]The hostname portion of the URI, if any
port int * The port number for the URI, either as specified or as default for
the method/scheme
resource char [HTTP_MAX_URI]The resource string, usually a filename on the server
Description
The httpSeparate() function separates the specified URI into its component parts. The method, username,
hostname and resource strings should be at least HTTP_MAX_URI characters long to avoid potential

buffer overflow problems.
New programs should use the httpSeparateLen() function instead.
Example
char uri[HTTP_MAX_URI]; char method[HTTP_MAX_URI]; char username[HTTP_MAX_URI]; char host
[HTTP_MAX_URI]; char resource[HTTP_MAX_URI];
< previous page page_533 next page >
< previous page page_534 next page >
Page 534
int port; httpSeparate(uri, method, username, host, &port, resource);
See Also
httpConnect(), httpConnectEncrypt()
httpSetField()
Usage
void httpSetField(http_t *http, http_field_t field, const char *value);
Arguments
Argument Type Description
http http_t * The HTTP connection
field http_field_t The HTTP field
value const char * The string value for the field
Description
The httpSetField() function sets the current value for the specified HTTP field.
Example
#include <cups/http.h> http_t *http; httpSetField(http, HTTP_FIELD_AUTHORIZATION, ''Basic
dfdr34453454325")); httpGet(http, "/some/uri"); while (httpUpdate(http) == HTTP_CONTINUE);
See Also
httpConnect(), httpGetField()
< previous page page_534 next page >
< previous page page_535 next page >
Page 535
httpTrace()

Usage
int httpTrace(http_t *http, const char *uri);
Arguments
Argument Type Description
http http_t * The HTTP connection
uri const char * The URI to be traced
Returns
0 on success, non-zero on failure.
Description
The httpTrace() function sends an HTTP TRACE request to the server.
Example
#include <cups/http.h> http_t *http; httpTrace(http, ''/some/uri");
See Also
httpConnect(), httpSetField(), httpUpdate()
httpUpdate()
Usage
http_status_t httpUpdate(http_t *http);
< previous page page_535 next page >

×