Ejemplo n.º 1
0
tree
xml_html_parser::parse_public () {
  s += 6;
  tree st= tuple ("public");
  skip_space ();
  st << parse_quoted ();
  skip_space ();
  st << parse_quoted ();
  return st;
}
Ejemplo n.º 2
0
static int search_prompt(char *withdef, char *withoutdef)
{
    char buffer[80];
    int len;

    if (!get_str(last_search ? withdef : withoutdef, buffer, TRUE))
	return 0;		       /* user break */
    if (!last_search && !*buffer) {
	strcpy (message, "Search aborted.");
	return 0;
    }

    if (!*buffer) {
	len = last_search->len;
    } else {
	len = parse_quoted (buffer);
	if (len == -1) {
	    display_beep();
	    strcpy (message, "Invalid escape sequence in search string");
	    return 0;
	}
	if (last_search)
	    free_search(last_search);
	last_search = build_search (buffer, len);
    }

    return 1;
}
Ejemplo n.º 3
0
void
xml_html_parser::parse_entity_decl () {
  s += 8;
  skip_space ();
  bool parameter= test (s, "%");
  if (parameter) { s += 1; skip_space (); }
  string name= parse_name ();
  if (parameter) name= "%" * name * ";";
  else name= "&" * name * ";";
  skip_space ();

  if (test (s, "SYSTEM") || test (s, "PUBLIC")) {
    // TODO: allow for loading of external entities using wget
    if (test (s, "SYSTEM")) (void) parse_system ();
    else (void) parse_public ();
    skip_space ();
    if (test (s, "NDATA")) {
      s += 5;
      skip_space ();
      (void) parse_name ();
    }
  }
  else {
    string val= parse_quoted ();
    val= expand_entities (val);
    entities (name) = val;
    // cout << name << " := " << val << "\n";
  }

  skip_space ();
  if (test (s, ">")) s += 1;
}
Ejemplo n.º 4
0
tree
xml_html_parser::parse_system () {
  s += 6;
  tree st= tuple ("system");
  skip_space ();
  st << parse_quoted ();
  return st;
}
Ejemplo n.º 5
0
/*
 * Parse a digest parameter
 */
static inline int parse_digest_param(str* _s, dig_cred_t* _c)
{
	dig_par_t t;
	str* ptr;
	str dummy;

	     /* Get type of the parameter */
	if (parse_param_name(_s, &t) < 0) {
		return -1;
	}

	_s->s++;  /* skip = */
	_s->len--;

	     /* Find the begining of body */
	trim_leading(_s);

	if (_s->len == 0) {
		return -2;
	}

	     /* Decide in which attribute the
	      * body content will be stored
	      */
	switch(t) {
	case PAR_USERNAME:  ptr = &_c->username.whole;  break;
	case PAR_REALM:     ptr = &_c->realm;           break;
	case PAR_NONCE:     ptr = &_c->nonce;           break;
	case PAR_URI:       ptr = &_c->uri;             break;
	case PAR_RESPONSE:  ptr = &_c->response;        break;
	case PAR_CNONCE:    ptr = &_c->cnonce;          break;
	case PAR_OPAQUE:    ptr = &_c->opaque;          break;
	case PAR_QOP:       ptr = &_c->qop.qop_str;     break;
	case PAR_NC:        ptr = &_c->nc;              break;
	case PAR_ALGORITHM: ptr = &_c->alg.alg_str;     break;
	case PAR_OTHER:     ptr = &dummy;               break;
	default:            ptr = &dummy;               break;
	}

	     /* If the first character is quote, it is
	      * a quoted string, otherwise it is a token
	      */
	if (_s->s[0] == '\"') {
		if (parse_quoted(_s, ptr) < 0) {
			return -3;
		}
	} else {
		if (parse_token(_s, ptr) < 0) {
			return -4;
		}
	}
	
	return 0;
}
Ejemplo n.º 6
0
tree
xml_html_parser::parse_attribute () {
  string attr= parse_name (), val;
  bool no_val= false;
  skip_space ();
  if (test (s, "=")) s += 1;
  skip_space ();
  if (test (s, "\42") || test (s, "'"))
    val= parse_quoted ();
  else { // for Html
    string r;
    while (s) {
      if (is_space (s[0]) || (s[0]=='<') || (s[0]=='>')) break;
      r << s->read (1);
    }
    val   = r;
    no_val= N(r) == 0;
  }
  if (!no_val) return tuple ("attr", attr, val);
  else if (attr != "") return tuple ("attr", attr);
  else return tuple ("attr");
}
Ejemplo n.º 7
0
// Pre-parse logmsg line for args and to determine some possible type of
// event.
//
// Returns an allocated event_args_t struct, which should be freed by the
// main thread after it's no longer needed.  Note that this struct gets
// passed to (possibly) multiple hooks.
event_args_t *parse_event_args(const char *logline) {
	event_args_t *args;
	char *cp, *begin, *end;
	int len;

	// Create and init the event_args struct.
	args=(event_args_t *) malloc(sizeof(event_args_t));
	if(!args) 
		return(NULL);
	memset(args, 0, sizeof(*args));

	// Make a copy of the logline, as we're going to be setting NULLs in
	// the string to mark ends of various substrings.
	args->buf=strdup(logline);
	if(!args->buf) 
		return(NULL);
	cp=args->buf;

	// Grab the player name and attributes, or "world" or "team" name, ie:
	//    Joe<15><785><CT>
	//    World
	//    Team "CT"
	args->player=parse_player(cp, &len);
	cp+=len;

	// Look for one of several pre-determined actions that we recognize.

	// ... triggered "some action" ...
	// ie:   "Joe<15><785><CT>" triggered "Killed_A_Hostage"
	if(strnmatch(cp, "triggered ", 10)) {
		cp+=10;
		args->action=parse_quoted(cp, &len);
		cp+=len;
	}
	// ... killed Joe<15><785><CT> ...
	// ie:    "Joe<15><785><CT>" killed "Sam<17><197><TERRORIST>" with "sg552"
	else if(strnmatch(cp, "killed ", 7)) {
		cp+=7;
		args->target=parse_player(cp, &len);
		if(strmatch(args->player->team, args->target->team)) {
			args->action="team_kill";
			args->evtype=EV_TEAM_KILL;
		}
		else {
			args->action="kill";
		}
		cp+=len;
	}
	// ... committed suicide ...
	// ie:   "Joe<15><785><CT>" committed suicide with "worldspawn"
	else if(strnmatch(cp, "committed suicide", 17)) {
		cp+=17;
		args->action="suicide";
		cp+=strspn(cp, " ");
		args->evtype=EV_PLAYER_SUICIDE;
	}
	// ... joined team "someteam" ...
	// ie:   "Joe<15><785><>" joined team "CT"
	else if(strnmatch(cp, "joined team ", 12)) {
		cp+=12;
		args->action="join_team";
		args->target=(event_player_t *) malloc(sizeof(event_player_t));
		// Note:
		//    old team is in:   args->player->team
		//    new team is in:   args->target->team
		if(args->target) {
			memset(args->target, 0, sizeof(event_player_t));
			args->target->team=parse_quoted(cp, &len);
			cp+=len;
		}
		args->evtype=EV_PLAYER_JOIN_TEAM;
	}
	// ... changed role to "something" ...
	// from TFC, ie:   "Joe<15><785><Red>" changed role to "Pyro"
	else if(strnmatch(cp, "changed role to ", 16)) {
		cp+=16;
		args->action="change_role";
		// Note:
		//    new role is in:   args->with
		args->with=parse_quoted(cp, &len);
		cp+=len;
		args->evtype=EV_PLAYER_CHANGE_ROLE;
	}
	// ... scored ...
	// ie: Team "CT" scored "7" with "2" players
	else if(strnmatch(cp, "scored ", 7)) {
		cp+=7;
		if(args->player && args->player->team && !args->player->name) {
			args->action="team_score";
			args->evtype=EV_TEAM_SCORE;
		}
		else {
			args->action="score";
		}
		cp+=strspn(cp, " ");
	}
	// anything else...
	// Consider any words up to a quote (") to be the 'action'.
	else {
		begin=cp;
		end=strchr(begin, '"')-1;
		len=end-begin;
		if(len > 0) {
			*end='\0';
			args->action=begin;
			cp=end+1;
			cp+=strspn(cp, " ");
		}
	}

	// Look for associated phrases...

	// ... against ...
	// ie:   "Joe<15><785><Red>" triggered "Medic_Heal" against "Bob<27><954><Red>"
	if(strnmatch(cp, "against ", 8)) {
		cp+=8;
		args->target=parse_player(cp, &len);
		cp+=len;
	}

	// ... with ...
	// ie:    "Joe<15><785><CT>" killed "Sam<17><197><TERRORIST>" with "sg552"
	// or:    "Joe<15><785><Blue>" triggered "Sentry_Destroyed" against "Sam<17><197><Red>" with "mirvgrenade"
	if(strnmatch(cp, "with ", 5)) {
		cp+=5;
		args->with=parse_quoted(cp, &len);
		if(strmatch(args->action, "kill")) {
			args->action="weapon_kill";
			args->evtype=EV_WEAPON_KILL;
		}
		cp+=len;
	}

	return(args);
}