Esempio n. 1
0
CommandLine::CommandLine(int argc, char* const argv[],
		const char* user, const char* pass, const char* usage_extra) :
CommandLineBase(argc, argv, "hm:p:s:u:D?"),
dtest_mode_(false),
run_mode_(0),
server_(0),
user_(user && *user ? user : 0),
pass_(pass && *pass ? pass : ""),
usage_extra_(usage_extra)
{
	int ch;
	while (successful() && ((ch = parse_next()) != EOF)) {
		switch (ch) {
			case 'm': run_mode_ = atoi(option_argument()); break;
			case 'p': pass_ = option_argument();           break;
			case 's': server_ = option_argument();         break;
			case 'u': user_ = option_argument();           break;
			case 'D': dtest_mode_ = true;                  break;
			default:
				parse_error();
				return;
		}
	}

	finish_parse();
}
Esempio n. 2
0
File: mpfd.C Progetto: Keloran/okws
void
cgi_mpfd_t::ext_parse_cb (int status)
{
  OKDBG4(SVC_MPFD, CHATTER, "cfgi_mpfd_t::ext_parse_cb(%d)", status);
  if (status == HTTP_OK) {
    MPFD_INC_STATE;
    resume ();
  } else {
    finish_parse (status);
  }
}
Esempio n. 3
0
/* ------------------------------------------------------------------------
@NAME       : bt_parse_entry_s()
@INPUT      : entry_text - string containing the entire entry to parse,
                           or NULL meaning we're done, please cleanup
              options    - standard btparse options bitmap
              line       - current line number (if that makes any sense)
                           -- passed to the parser to set zzline, so that
                           lexical and syntax errors are properly localized
@OUTPUT     : *top       - newly-allocated AST for the entry
                           (or NULL if entry_text was NULL, ie. at EOF)
@RETURNS    : 1 with *top set to AST for entry on successful read/parse
              1 with *top==NULL if entry_text was NULL, ie. at EOF
              0 if any serious errors seen in input (*top is still 
                set to the AST, but only for as much of the input as we
                were able to parse)
              (A "serious" error is a lexical or syntax error; "trivial"
              errors such as warnings and notifications count as "success"
              for the purposes of this function's return value.)
@DESCRIPTION: Parses a BibTeX entry contained in a string.
@GLOBALS    : 
@CALLS      : ANTLR
@CREATED    : 1997/01/18, GPW (from code in bt_parse_entry())
@MODIFIED   : 
-------------------------------------------------------------------------- */
AST * bt_parse_entry_s (char *    entry_text,
                        char *    filename,
                        int       line,
                        ushort    options,
                        boolean * status)
{
   AST *        entry_ast = NULL;
   static int * err_counts = NULL;

   if (options & BTO_STRINGMASK)        /* any string options set? */
   {
      usage_error ("bt_parse_entry_s: illegal options "
                   "(string options not allowed");
   }

   InputFilename = filename;
   err_counts = bt_get_error_counts (err_counts);

   if (entry_text == NULL)              /* signal to clean up */
   {
      finish_parse (&err_counts);
      if (status) *status = TRUE;
      return NULL;
   }

   zzast_sp = ZZAST_STACKSIZE;          /* workaround apparent pccts bug */
   start_parse (NULL, entry_text, line);

   entry (&entry_ast);                  /* enter the parser */
   ++zzasp;                             /* why is this done? */

   if (entry_ast == NULL)               /* can happen with very bad input */
   {
      if (status) *status = FALSE;
      return entry_ast;
   }

#if DEBUG
   dump_ast ("bt_parse_entry_s: single entry, after parsing:\n", 
             entry_ast);
#endif
   bt_postprocess_entry (entry_ast,
                         StringOptions[entry_ast->metatype] | options);
#if DEBUG
   dump_ast ("bt_parse_entry_s: single entry, after post-processing:\n",
             entry_ast);
#endif

   if (status) *status = parse_status (err_counts);
   return entry_ast;

} /* bt_parse_entry_s () */
Esempio n. 4
0
void
async_dumper_t::parse_guts ()
{
  int rc = 0;
  while (bp < endp) {
    rc = abuf->dump (bp, endp - bp);
    if (rc < 0)
      break; // EOF or WAIT
    bp += rc;
  }
  if (bp == endp || rc == ABUF_EOFCHAR)
    finish_parse (0);
  // otherwise, we're waiting
}
Esempio n. 5
0
CommandLine::CommandLine(int argc, char* const argv[]) :
CommandLineBase(argc, argv, "hi:o:p:s:t:u:1:?"),
input_(0),
output_(0),
pass_(""),
server_(0),
user_(0),
input_source_(ss_unknown),
output_sink_(ss_unknown)
{
	// Parse the command line
	int ch;
	while (successful() && ((ch = parse_next()) != EOF)) {
		switch (ch) {
			case 'i':
			case 't':
			case '1':
				if (input_) {
					std::cerr << "Warning: overriding previous input "
							"source!  Only last -i, -t or -1 is "
							"effective.\n";
				}
				input_ = option_argument();
				input_source_ =
						(ch == '1' ? ss_ssqls1 :
						 ch == 'i' ? ss_ssqls2 :
						             ss_table);
				break;

			case 'o':
				output_ = option_argument();
				output_sink_ = ss_ssqls2;
				break;

			case 'p':
				pass_ = option_argument();
				break;

			case 's':
				server_ = option_argument();
				break;

			case 'u':
				user_ = option_argument();
				break;

			default:
				parse_error();
		}
	}
	finish_parse();

	// Figure out whether command line makes sense, and if not, tell
	// user about it.
	if (successful()) {
		if (input_source_ == ss_unknown) {
			parse_error("No input source given!  Need -i, -t or -1.");
		}
		else if ((input_source_ != ss_ssqls2) && !output_) {
			parse_error("Need -o if you give -t or -1!");
		}
	}
}
Esempio n. 6
0
/* ------------------------------------------------------------------------
@NAME       : bt_parse_entry()
@INPUT      : infile  - file to read next entry from
              options - standard btparse options bitmap
@OUTPUT     : *top    - AST for the entry, or NULL if no entries left in file
@RETURNS    : same as bt_parse_entry_s()
@DESCRIPTION: Starts (or continues) parsing from a file.
@GLOBALS    : 
@CALLS      : 
@CREATED    : Jan 1997, GPW
@MODIFIED   : 
-------------------------------------------------------------------------- */
AST * bt_parse_entry (FILE *    infile,
                      char *    filename,
                      ushort    options,
                      boolean * status)
{
   AST *         entry_ast = NULL;
   static int *  err_counts = NULL;
   static FILE * prev_file = NULL;

   if (prev_file != NULL && infile != prev_file)
   {
      usage_error ("bt_parse_entry: you can't interleave calls "
                   "across different files");
   }

   if (options & BTO_STRINGMASK)        /* any string options set? */
   {
      usage_error ("bt_parse_entry: illegal options "
                   "(string options not allowed)");
   }

   InputFilename = filename;
   err_counts = bt_get_error_counts (err_counts);

   if (feof (infile))
   {
      if (prev_file != NULL)            /* haven't already done the cleanup */
      {
         prev_file = NULL;
         finish_parse (&err_counts);
      }
      else
      {
         usage_warning ("bt_parse_entry: second attempt to read past eof");
      }

      if (status) *status = TRUE;
      return NULL;
   }

   /* 
    * Here we do some nasty poking about the innards of PCCTS in order to
    * enter the parser multiple times on the same input stream.  This code
    * comes from expanding the macro invokation:
    * 
    *    ANTLR (entry (top), infile);  
    * 
    * When LL_K, ZZINF_LOOK, and DEMAND_LOOK are all undefined, this
    * ultimately expands to
    * 
    *    zzbufsize = ZZLEXBUFSIZE;
    *    {
    *       static char zztoktext[ZZLEXBUFSIZE];
    *       zzlextext = zztoktext; 
    *       zzrdstream (f);
    *       zzgettok();
    *    }
    *    entry (top);
    *    ++zzasp;
    * 
    * (I'm expanding hte zzenterANTLR, zzleaveANTLR, and zzPrimateLookAhead
    * macros, but leaving ZZLEXBUFSIZE -- a simple constant -- alone.)
    * 
    * There are two problems with this: 1) zztoktext is a statically
    * allocated buffer, and when it overflows we just ignore further
    * characters that should belong to that lexeme; and 2) zzrdstream() and
    * zzgettok() are called every time we enter the parser, which means the
    * token left over from the previous entry will be discarded when we
    * parse entries 2 .. N.
    * 
    * I handle the static buffer problem with alloc_lex_buffer() and
    * realloc_lex_buffer() (in lex_auxiliary.c), and by rewriting the ZZCOPY
    * macro to call realloc_lex_buffer() when overflow is detected.
    * 
    * I handle the extra token-read by hanging on to a static file
    * pointer, prev_file, between calls to bt_parse_entry() -- when
    * the program starts it is NULL, and we reset it to NULL on
    * finishing a file.  Thus, any call that is the first on a given
    * file will allocate the lexical buffer and read the first token;
    * thereafter, we skip those steps, and free the buffer on reaching
    * end-of-file.  Currently, this method precludes interleaving
    * calls to bt_parse_entry() on different files -- perhaps I could
    * fix this with the zz{save,restore}_{antlr,dlg}_state()
    * functions?
    */

   zzast_sp = ZZAST_STACKSIZE;          /* workaround apparent pccts bug */

#if defined(LL_K) || defined(ZZINF_LOOK) || defined(DEMAND_LOOK)
# error One of LL_K, ZZINF_LOOK, or DEMAND_LOOK was defined
#endif
   if (prev_file == NULL)               /* only read from input stream if */
   {                                    /* starting afresh with a file */
      start_parse (infile, NULL, 0);
      prev_file = infile;
   }
   assert (prev_file == infile);

   entry (&entry_ast);                  /* enter the parser */
   ++zzasp;                             /* why is this done? */

   if (entry_ast == NULL)               /* can happen with very bad input */
   {
      if (status) *status = FALSE;
      return entry_ast;
   }

#if DEBUG
   dump_ast ("bt_parse_entry(): single entry, after parsing:\n", 
             entry_ast);
#endif
   bt_postprocess_entry (entry_ast,
                         StringOptions[entry_ast->metatype] | options);
#if DEBUG
   dump_ast ("bt_parse_entry(): single entry, after post-processing:\n", 
             entry_ast);
#endif

   if (status) *status = parse_status (err_counts);
   return entry_ast;

} /* bt_parse_entry() */
Esempio n. 7
0
File: mpfd.C Progetto: Keloran/okws
void
cgi_mpfd_t::parse_guts ()
{
  abuf_stat_t r = ABUF_OK;
  str dummy;
  
  bool inc;

  while (r == ABUF_OK) {
    OKDBG4(SVC_MPFD, CHATTER, "cgi_mpfd_t::parse_guts loop "
	   "r=%d, state=%d", int (r), int (state));

    inc = true;

    switch (state) {

    case MPFD_START:
      r = match_boundary ();
      break;

    case MPFD_EOL0:
      r = require_crlf ();
      break;

    case MPFD_KEY:
      r = gobble_crlf ();
      if (r == ABUF_OK) {
	if (to_start) {
	  state = MPFD_START;
	  to_start = false;
	} else 
	  state = MPFD_SEARCH;
	inc = false;
      } else if (r == ABUF_NOMATCH) {
	r = delimit_key (&mpfd_key);
	if (r == ABUF_OK)
	  kt = mpfd_ktmap.lookup (mpfd_key);
      } // else a WAIT or an EOF in gobble_crlf
      break;

    case MPFD_SPC:
      r = abuf->skip_hws (1);
      cdp.reset ();
      break;

    case MPFD_VALUE:
      if (kt == MPFD_DISPOSITION) {
	OKDBG3(SVC_MPFD, CHATTER, "cgi_mpfd_t::parse_guts branch to nested "
	       "content disposition parser");
	cdp.parse (wrap (this, &cgi_mpfd_t::ext_parse_cb));
	OKDBG3(SVC_MPFD, CHATTER, "cgi_mpfd_t::parse_guts return due to "
	       "content disposition parser");
	return;
      }	else if (kt == MPFD_TYPE) {
	r = delimit_val (&content_typ);
	if (r == ABUF_OK) {
	  if (multipart_rxx.match (content_typ)) {
	    add_boundary (multipart_rxx[1]);
	    to_start = true;
	  }
	}
      } else {
	r = delimit_val (&dummy);
      }
      break;

    case MPFD_EOL1A:
      r = require_crlf ();
      break;

    case MPFD_EOL1B:
      if (kt == MPFD_DISPOSITION) {
	if (cdp.typ == CONTDISP_FORMDAT) {
	  cgi_key = cdp.name;
	  filename = cdp.filename;
	  attach = filename;
	} else if (cdp.typ == CONTDISP_ATTACH) {
	  filename = cdp.filename;
	  attach = true;
	} else {
	  r = ABUF_PARSE_ERR;
	}
      }
      state = MPFD_KEY;
      inc = false;
      break;

    case MPFD_SEARCH:
      r = match_boundary (&dat);
      if (r == ABUF_OK) {
	if (cgi_key) {
	  if (attach)
	    finsert (cgi_key, cgi_file_t (filename, content_typ, dat));
	  else
	    insert (cgi_key, dat);
	  cgi_key = NULL;
	}
	// in this case, no more boundaries
      } else if (r == ABUF_PARSE_ERR) { 
	r = ABUF_OK;
	state = MPFD_EOF;
	inc = false;
      }
      break;

    case MPFD_SEARCH2:
      r = parse_2dash ();
      if (r == ABUF_OK) {
	remove_boundary ();
	nxt_state = MPFD_SEARCH;
      } else if (r == ABUF_NOMATCH) {
	r = ABUF_OK;
	nxt_state = MPFD_KEY;
      }
      break;

    case MPFD_SEARCH3:
      r = require_crlf ();
      if (r == ABUF_OK) {
	state = nxt_state;
	inc = false;
      }
      break;

    case MPFD_EOF:
      r = abuf->skip_ws ();
      break;

    default:
      break;

    }
    if (r == ABUF_OK && inc)
      MPFD_INC_STATE;
  }

  OKDBG4(SVC_MPFD, CHATTER, "cgi_mpfd_t::parse_guts exit loop "
	 "r=%d, state=%d", int (r), int (state));

  switch (r) {
  case ABUF_EOF:
    int rc;
    if (state == MPFD_EOF) {
      rc = HTTP_OK;
    } else {
      rc = HTTP_UNEXPECTED_EOF;
      warn ("mpfd EOF in state %d after %d bytes read\n", 
	    int (state), abuf ? abuf->get_ccnt () : -1);
    }
    
    finish_parse (rc);
    break;
  case ABUF_PARSE_ERR:
    finish_parse (HTTP_BAD_REQUEST);
    break;
  default:
    break;
  }
}
Esempio n. 8
0
File: mpfd.C Progetto: Keloran/okws
void
contdisp_parser_t::parse_guts ()
{
  abuf_stat_t r = ABUF_OK;
  bool inc;
  bool flag = true;

  while (r == ABUF_OK && flag) {

    OKDBG4(SVC_MPFD, CHATTER, "contdisp_parser_t::parse_guts loop "
	   "r=%d, state=%d", int (r), int (state));

    inc = true;
    switch (state) {
    case CONTDISP_START:
      r = delimit (&typ_scr, ';', true, true);
      break;
    case CONTDISP_SEP1:
      r = abuf->skip_hws (1);
      if (mystrcmp (typ_scr.cstr(), "form-data")) {
	typ = CONTDISP_FORMDAT;
      } else if (mystrcmp (typ_scr.cstr(), "attachment")) {
	state = CONTDISP_FILENAME_KEY;
	inc = true;
	typ = CONTDISP_ATTACH;
      }
      break;
    case CONTDISP_NAME_KEY:
      r = force_match ("name=\"");
      break;
    case CONTDISP_NAME_VAL:
      r = delimit (&name, '"', false, true);
      break;
    case CONTDISP_SEP2A:
      r = eol ();
      if (r == ABUF_OK) flag = false;
      else if (r == ABUF_NOMATCH) r = ABUF_OK;
      break;
    case CONTDISP_SEP2B:
      r = abuf->requirechar (';');
      break;
    case CONTDISP_SEP2C:
      r = abuf->skip_hws ();
      break;
    case CONTDISP_FILENAME_KEY:
      r = force_match ("filename=\"");
      break;
    case CONTDISP_FILENAME_VAL:
      r = delimit (&filename_scr, '\r', false, false);
      if (r == ABUF_PARSE_ERR)
	r = ABUF_OK; // found '\n' before '\r' -- that's OK
      if (r == ABUF_OK) {
	filename = str (filename_scr.cstr (), filename_scr.len () - 1);
	flag = false;
      }
      break;
    default:
      break;
    }
    if (r == ABUF_OK && inc)
      state = static_cast<contdisp_state_t> (state + 1);
  }

  OKDBG4(SVC_MPFD, CHATTER, "contdisp_parser_t::parse_guts exit loop "
	 "r=%d, state=%d", int (r), int (state));

  switch (r) {
  case ABUF_OK:
    finish_parse (HTTP_OK);
    break;
  case ABUF_EOF:
  case ABUF_PARSE_ERR:
    finish_parse (HTTP_BAD_REQUEST);
    break;
  default:
    break;
  }
}