genscreen.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** --- BEGIN COPYRIGHT BLOCK ---
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. --- END COPYRIGHT BLOCK --- */
  38. /*
  39. * Generate a screen.
  40. */
  41. #include "dsgw.h"
  42. static int dsgw_genscreen_begin( char *fname, FILE **fpp,
  43. char *stop_at_directive, int erropts );
  44. static int dsgw_genscreen_continue( FILE **fpp, char *stop_at_directive,
  45. int erropts );
  46. static LDAP *ld = NULL;
  47. main( argc, argv, env )
  48. int argc;
  49. char *argv[];
  50. #ifdef DSGW_DEBUG
  51. char *env[];
  52. #endif
  53. {
  54. char *p, *tmplname, *buf;
  55. context=dsgw_ch_strdup("pb");
  56. /*CHANGE THIS*/
  57. (void)dsgw_init( argc, argv, DSGW_METHOD_GET );
  58. dsgw_send_header();
  59. #ifdef DSGW_DEBUG
  60. dsgw_logstringarray( "env", env );
  61. #endif
  62. /*
  63. * If the QUERY_STRING is non-NULL, it looks like this:
  64. *
  65. * template &CONTEXT=context [ &INFO=infostring ]
  66. *
  67. * where:
  68. * "template" is the name of the HTML template to render
  69. * "infostring" is a message used to replace DS_LAST_OP_INFO directives
  70. *
  71. * If the QUERY_STRING is NULL, the name of this program is used as the
  72. * template.
  73. */
  74. if (( tmplname = getenv( "QUERY_STRING" )) == NULL ) {
  75. tmplname = progname;
  76. } else {
  77. tmplname = dsgw_ch_strdup( tmplname );
  78. if (( p = strrchr( tmplname, '&' )) != NULL ) {
  79. *p++ = '\0';
  80. if ( strncasecmp( p, "info=", 5 ) == 0 ) {
  81. dsgw_last_op_info = dsgw_ch_strdup( p + 5 );
  82. dsgw_form_unescape( dsgw_last_op_info );
  83. }
  84. }
  85. }
  86. buf = dsgw_ch_malloc( strlen( tmplname ) + 6 ); /* room for ".html\0" */
  87. sprintf( buf, "%s.html", tmplname );
  88. dsgw_genscreen_begin( buf, NULL, NULL, DSGW_ERROPT_EXIT );
  89. exit( 0 );
  90. }
  91. static int
  92. dsgw_genscreen_begin( char *fname, FILE **fpp, char *stop_at_directive,
  93. int erropts )
  94. {
  95. FILE *html;
  96. if ( fpp == NULL ) {
  97. fpp = &html;
  98. }
  99. if (( *fpp = dsgw_open_html_file( fname, erropts )) == NULL ) {
  100. *fpp = NULL;
  101. return( -1 );
  102. }
  103. return( dsgw_genscreen_continue( fpp, stop_at_directive, erropts ));
  104. }
  105. static int
  106. dsgw_genscreen_continue( FILE **fpp, char *stop_at_directive, int erropts )
  107. {
  108. char **argv, line[ BIG_LINE ];
  109. int argc;
  110. while ( dsgw_next_html_line( *fpp, line )) {
  111. if ( dsgw_parse_line( line, &argc, &argv, 0, dsgw_simple_cond_is_true,
  112. NULL )) {
  113. if ( stop_at_directive != NULL &&
  114. dsgw_directive_is( line, stop_at_directive )) {
  115. return( 0 );
  116. }
  117. if ( dsgw_directive_is( line, DRCT_DS_LOCATIONPOPUP )) {
  118. dsgw_emit_location_popup( ld, argc, argv, erropts );
  119. }
  120. }
  121. }
  122. fclose( *fpp );
  123. *fpp = NULL;
  124. return( 0 );
  125. }