Debian Codegraph @

listings/chapter-11/server.h

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #ifndef SERVER_H
8 #define SERVER_H
9
10 #include <netinet/in.h>
11 #include <sys/types.h>
12
13 /*** Symbols defined in common.c. ************************************/
14
15 /* The name of this program. */
16 extern const char* program_name;
17
18 /* If non-zero, print verbose messages. */
19 extern int verbose;
20
21 /* Like malloc, except aborts the program if allocation fails. */
22 extern void* xmalloc (size_t size);
23
24 /* Like realloc, except aborts the program if allocation fails. */
25 extern void* xrealloc (void* ptr, size_t size);
26
27 /* Like strdup, except aborts the program if allocation fails. */
28 extern char* xstrdup (const char* s);
29
30 /* Print an error message for a failed call OPERATION, using the value
31 of errno, and end the program. */
32 extern void system_error (const char* operation);
33
34 /* Print an error message for failure involving CAUSE, including a
35 descriptive MESSAGE, and end the program. */
36 extern void error (const char* cause, const char* message);
37
38 /* Return the directory containing the running program's executable.
39 The return value is a memory buffer which the caller must deallocate
40 using free. This function calls abort on failure. */
41 extern char* get_self_executable_directory ();
42
43
44 /*** Symbols defined in module.c **************************************/
45
46 /* An instance of a loaded server module. */
47 struct server_module {
48 /* The shared library handle corresponding to the loaded module. */
49 void* handle;
50 /* A name describing the module. */
51 const char* name;
52 /* The function which generates the HTML results for this module. */
53 void (* generate_function) (int);
54 };
55
56 /* The directory from which modules are loaded. */
57 extern char* module_dir;
58
59 /* Attempt to load a server module with the name MODULE_PATH. If a
60 server module exists with this path, loads the module and returns a
61 server_module structure representing it. Otherwise, returns NULL. */
62 extern struct server_module* module_open (const char* module_path);
63
64 /* Close a server module and deallocate the MODULE object. */
65 extern void module_close (struct server_module* module);
66
67
68 /*** Symbols defined in server.c. ************************************/
69
70 /* Run the server on LOCAL_ADDRESS and PORT. */
71 extern void server_run (struct in_addr local_address, uint16_t port);
72
73
74 #endif /* SERVER_H */