]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/help.c
4 * On-line help CGI for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for CGI.
30 * Include necessary headers...
33 #include "cgi-private.h"
37 * 'main()' - Main entry for CGI.
40 int /* O - Exit status */
41 main(int argc
, /* I - Number of command-line arguments */
42 char *argv
[]) /* I - Command-line arguments */
44 help_index_t
*hi
, /* Help index */
45 *si
; /* Search index */
46 help_node_t
**n
; /* Current help node */
47 int i
, j
; /* Looping vars */
48 const char *query
; /* Search query */
49 const char *server_root
; /* CUPS_SERVERROOT environment variable */
50 const char *docroot
; /* CUPS_DOCROOT environment variable */
51 const char *helpfile
; /* Current help file */
52 const char *topic
; /* Current topic */
53 char topic_data
[1024]; /* Topic form data */
54 const char *section
; /* Current section */
55 char filename
[1024], /* Filename */
56 directory
[1024]; /* Directory */
57 cups_file_t
*fp
; /* Help file */
58 char line
[1024]; /* Line from file */
62 * Get any form variables...
68 * Set the web interface section...
71 cgiSetVariable("SECTION", "help");
74 * Load the help index...
77 if ((server_root
= getenv("CUPS_SERVERROOT")) == NULL
)
78 server_root
= CUPS_SERVERROOT
;
80 snprintf(filename
, sizeof(filename
), "%s/help.index", server_root
);
82 if ((docroot
= getenv("CUPS_DOCROOT")) == NULL
)
83 docroot
= CUPS_DOCROOT
;
85 snprintf(directory
, sizeof(directory
), "%s/help", docroot
);
87 fprintf(stderr
, "DEBUG: helpLoadIndex(filename=\"%s\", directory=\"%s\")\n",
90 hi
= helpLoadIndex(filename
, directory
);
96 cgiSetVariable("ERROR", "Unable to load help index!");
97 cgiCopyTemplateLang("error.tmpl");
103 fprintf(stderr
, "hi->num_nodes=%d\n", hi
->num_nodes
);
106 * See if we are viewing a file...
109 for (i
= 0; i
< argc
; i
++)
110 fprintf(stderr
, "argv[%d]=\"%s\"\n", i
, argv
[i
]);
112 if ((helpfile
= getenv("PATH_INFO")) != NULL
)
114 else if (strstr(argv
[0], "help.cgi"))
122 * Verify that the help file exists and is part of the index...
125 snprintf(filename
, sizeof(filename
), "%s/help/%s", docroot
, helpfile
);
127 fprintf(stderr
, "DEBUG: helpfile=\"%s\", filename=\"%s\"\n",
130 if (access(filename
, R_OK
))
134 cgiStartHTML("Help");
135 cgiSetVariable("ERROR", "Unable to access help file!");
136 cgiCopyTemplateLang("error.tmpl");
142 if ((n
= helpFindNode(hi
, helpfile
, NULL
)) == NULL
)
144 cgiStartHTML("Help");
145 cgiSetVariable("ERROR", "Help file not in index!");
146 cgiCopyTemplateLang("error.tmpl");
153 * Set the page title and save the help file...
156 cgiSetVariable("HELPFILE", helpfile
);
157 cgiSetVariable("HELPTITLE", n
[0]->text
);
160 * Send a standard page header...
163 cgiStartHTML(n
[0]->text
);
168 * Send a standard page header...
171 cgiStartHTML("Help");
175 * Do a search as needed...
178 query
= cgiGetVariable("QUERY");
179 topic
= cgiGetVariable("TOPIC");
180 si
= helpSearchIndex(hi
, query
, topic
, helpfile
);
184 help_node_t
**nn
; /* Parent node */
187 fprintf(stderr
, "si=%p, si->num_nodes=%d, si->sorted=%p\n", si
,
188 si
->num_nodes
, si
->sorted
);
190 for (i
= 0, n
= si
->sorted
; i
< si
->num_nodes
; i
++, n
++)
192 if (helpfile
&& n
[0]->anchor
)
193 snprintf(line
, sizeof(line
), "#%s", n
[0]->anchor
);
194 else if (n
[0]->anchor
)
195 snprintf(line
, sizeof(line
), "/help/%s?QUERY=%s#%s", n
[0]->filename
,
196 query
? query
: "", n
[0]->anchor
);
198 snprintf(line
, sizeof(line
), "/help/%s?QUERY=%s", n
[0]->filename
,
201 cgiSetArray("QTEXT", i
, n
[0]->text
);
202 cgiSetArray("QLINK", i
, line
);
204 if (!helpfile
&& n
[0]->anchor
)
206 nn
= helpFindNode(hi
, n
[0]->filename
, NULL
);
208 snprintf(line
, sizeof(line
), "/help/%s?QUERY=%s", nn
[0]->filename
,
211 cgiSetArray("QPTEXT", i
, nn
[0]->text
);
212 cgiSetArray("QPLINK", i
, line
);
216 cgiSetArray("QPTEXT", i
, "");
217 cgiSetArray("QPLINK", i
, "");
220 fprintf(stderr
, "DEBUG: [%d] = \"%s\" @ \"%s\"\n", i
, n
[0]->text
, line
);
227 * OK, now list the bookmarks within the index...
230 for (i
= hi
->num_nodes
, j
= 0, n
= hi
->sorted
, section
= NULL
;
238 * Add a section link as needed...
242 (!section
|| strcmp(n
[0]->section
, section
)))
245 * Add a link for this node...
248 snprintf(line
, sizeof(line
), "/help/?TOPIC=%s&QUERY=%s",
249 cgiFormEncode(topic_data
, n
[0]->section
, sizeof(topic_data
)),
251 cgiSetArray("BMLINK", j
, line
);
252 cgiSetArray("BMTEXT", j
, n
[0]->section
);
253 cgiSetArray("BMINDENT", j
, "0");
256 section
= n
[0]->section
;
259 if (!topic
|| strcmp(n
[0]->section
, topic
))
263 * Add a link for this node...
266 snprintf(line
, sizeof(line
), "/help/%s?TOPIC=%s&QUERY=%s", n
[0]->filename
,
267 cgiFormEncode(topic_data
, n
[0]->section
, sizeof(topic_data
)),
269 cgiSetArray("BMLINK", j
, line
);
270 cgiSetArray("BMTEXT", j
, n
[0]->text
);
271 cgiSetArray("BMINDENT", j
, "1");
275 if (helpfile
&& !strcmp(helpfile
, n
[0]->filename
))
277 int ii
; /* Looping var */
278 help_node_t
**nn
; /* Pointer to sub-node */
281 for (ii
= hi
->num_nodes
, nn
= hi
->sorted
; ii
> 0; ii
--, nn
++)
282 if (nn
[0]->anchor
&& !strcmp(helpfile
, nn
[0]->filename
))
285 * Add a link for this node...
288 snprintf(line
, sizeof(line
), "#%s", nn
[0]->anchor
);
289 cgiSetArray("BMLINK", j
, line
);
290 cgiSetArray("BMTEXT", j
, nn
[0]->text
);
291 cgiSetArray("BMINDENT", j
, "2");
299 * Show the search and bookmark content...
302 cgiCopyTemplateLang("help-header.tmpl");
305 * If we are viewing a file, copy it in now...
310 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
312 int inbody
; /* Are we inside the body? */
317 while (cupsFileGets(fp
, line
, sizeof(line
)))
321 if (!strncasecmp(line
, "</BODY>", 7))
324 printf("%s\n", line
);
326 else if (!strncasecmp(line
, "<BODY", 5))
335 cgiSetVariable("ERROR", "Unable to open help file.");
336 cgiCopyTemplateLang("error.tmpl");
341 * Send a standard trailer...
347 * Delete the index...
353 * Return with no errors...