示例#1
0
文件: tree.c 项目: amirsalah/cs2007
int parse_xslt(elcgen *gen, xmlNodePtr parent, expression *pnode)
{
  xmlNodePtr n;
  int r = 1;
  expression **cptr = &pnode->r.children;
  for (n = parent->children; n && r; n = n->next) {
    expression *newnode = NULL;
    if (ignore_node(n))
      continue;
    if (XML_ELEMENT_NODE == n->type) {
      if (n->ns && !xmlStrcmp(n->ns->href,XSLT_NS)) {
        if (!xmlStrcmp(n->name,"output")) {
          newnode = new_xsltnode(n,XSLT_OUTPUT);
        }
        else if (!xmlStrcmp(n->name,"strip-space")) {
          newnode = new_xsltnode(n,XSLT_STRIP_SPACE);
        }
        else if (!xmlStrcmp(n->name,"function")) {
          newnode = new_xsltnode(n,XSLT_FUNCTION);
          r = r && parse_name(gen,n,newnode,1);
        }
        else if (!xmlStrcmp(n->name,"template")) {
          newnode = new_xsltnode(n,XSLT_TEMPLATE);
          newnode->orig = xmlGetProp(n,"match");
          r = r && parse_expr_attr(gen,n,"match",&newnode->r.left,0,newnode);
          r = r && parse_name(gen,n,newnode,0);
        }
        else if (!xmlStrcmp(n->name,"param")) {
          newnode = new_xsltnode(n,XSLT_PARAM);
          r = r && parse_name(gen,n,newnode,1);
        }
        else if (!xmlStrcmp(n->name,"when")) {
          newnode = new_xsltnode(n,XSLT_WHEN);
          newnode->orig = xmlGetProp(n,"test");
          r = r && parse_expr_attr(gen,n,"test",&newnode->r.left,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"otherwise")) {
          newnode = new_xsltnode(n,XSLT_OTHERWISE);
        }
        else if (!xmlStrcmp(n->name,"variable")) {
          newnode = new_xsltnode(n,XSLT_VARIABLE);
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,0,newnode);
          r = r && parse_name(gen,n,newnode,1);
        }
        else if (!xmlStrcmp(n->name,"sequence")) {
          newnode = new_xsltnode(n,XSLT_SEQUENCE);
          newnode->orig = xmlGetProp(n,"select");
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"value-of")) {
          newnode = new_xsltnode(n,XSLT_VALUE_OF);
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,0,newnode);
        }
        else if (!xmlStrcmp(n->name,"text")) {
          char *str = xmlNodeListGetString(gen->parse_doc,n->children,1);
          if (!strncmp(str,"#S",2) && gen->ispattern) {
            newnode = new_xsltnode(n,XSLT_DSVAR_TEXTINSTR);
            newnode->str = strdup((char*)str+1);
            free(str);
          }
          else {
            newnode = new_xsltnode(n,XSLT_TEXT);
            newnode->str = str;
          }
        }
        else if (!xmlStrcmp(n->name,"for-each")) {
          newnode = new_xsltnode(n,XSLT_FOR_EACH);
          newnode->orig = xmlGetProp(n,"select");
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"if")) {
          newnode = new_xsltnode(n,XSLT_IF);
          newnode->orig = xmlGetProp(n,"test");
          r = r && parse_expr_attr(gen,n,"test",&newnode->r.left,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"choose")) {
          newnode = new_xsltnode(n,XSLT_CHOOSE);
        }
        else if (!xmlStrcmp(n->name,"element")) {
          newnode = new_xsltnode(n,XSLT_ELEMENT);
          newnode->orig = xmlGetProp(n,"name");
          r = r && parse_avt(gen,n,"name",&newnode->r.name_avt,1,newnode);
          r = r && parse_avt(gen,n,"namespace",&newnode->r.namespace_avt,0,newnode);
        }
        else if (!xmlStrcmp(n->name,"attribute")) {
          newnode = new_xsltnode(n,XSLT_ATTRIBUTE);
          newnode->orig = xmlGetProp(n,"name");
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,0,newnode);
          r = r && parse_avt(gen,n,"name",&newnode->r.name_avt,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"namespace")) {
          newnode = new_xsltnode(n,XSLT_NAMESPACE);
          newnode->orig = xmlGetProp(n,"name");
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,0,newnode);
          r = r && parse_avt(gen,n,"name",&newnode->r.name_avt,1,newnode);
        }
        else if (!xmlStrcmp(n->name,"apply-templates")) {
          newnode = new_xsltnode(n,XSLT_APPLY_TEMPLATES);
          newnode->orig = xmlGetProp(n,"select");
          r = r && parse_expr_attr(gen,n,"select",&newnode->r.left,0,newnode);
        }
        else if (!strncmp((char*)n->name,"_Y",2) && gen->ispattern) {
          newnode = new_xsltnode(n,XSLT_DSVAR_LITELEM);
/*           newnode->str = strdup((char*)n->name+1); */
          newnode->str = strdup("Y::"); /* FIXME: hack */
        }
        else {
          r = gen_error(gen,"Unsupported XSLT instruction: %s",n->name);
        }
      }
      else {
        newnode = new_xsltnode(n,XSLT_LITERAL_RESULT_ELEMENT);
        newnode->qn.uri = n->ns ? strdup((char*)n->ns->href) : strdup("");
        newnode->qn.prefix = (n->ns && n->ns->prefix) ? strdup((char*)n->ns->prefix) : strdup("");
        newnode->qn.localpart = strdup((char*)n->name);
        r = r && parse_attributes(gen,n,newnode);
      }
    }
    else if (XML_TEXT_NODE == n->type) {
      if (!strncmp((char*)n->content,"#I",2) && gen->ispattern) {
        newnode = new_xsltnode(n,XSLT_DSVAR_INSTRUCTION);
        newnode->str = strdup((char*)n->content+1);
      }
      else if (!strncmp((char*)n->content,"#S",2) && gen->ispattern) {
        newnode = new_xsltnode(n,XSLT_DSVAR_TEXT);
        newnode->str = strdup((char*)n->content+1);
      }
      else {
        newnode = new_xsltnode(n,XSLT_LITERAL_TEXT_NODE);
        newnode->str = strdup((char*)n->content);
      }
    }
    if (newnode) {

      *cptr = newnode;
      cptr = &newnode->next;

      if ((XSLT_TEXT != newnode->type) && (XSLT_DSVAR_TEXTINSTR != newnode->type)) {
        if (!parse_xslt(gen,n,newnode))
          return 0;
      }
    }
  }
  return r;
}
示例#2
0
void softlist_parser::parse_data_start(const char *tagname, const char **attributes)
{
	// get the current part; error if none
	if (m_current_part == nullptr)
	{
		parse_error("Tag %s found outside of part context", tagname);
		return;
	}

	// <rom name='' size='' crc='' sha1='' offset='' value='' status='' loadflag=''>
	if (strcmp(tagname, "rom") == 0)
	{
		static const char *attrnames[] = { "name", "size", "crc", "sha1", "offset", "value", "status", "loadflag" };
		auto attrvalues = parse_attributes(attributes, attrnames);

		std::string &name = attrvalues[0];
		const std::string &sizestr = attrvalues[1];
		const std::string &crc = attrvalues[2];
		const std::string &sha1 = attrvalues[3];
		const std::string &offsetstr = attrvalues[4];
		std::string &value = attrvalues[5];
		const std::string &status = attrvalues[6];
		const std::string &loadflag = attrvalues[7];
		if (!sizestr.empty() && !offsetstr.empty())
		{
			UINT32 length = strtol(sizestr.c_str(), nullptr, 0);
			UINT32 offset = strtol(offsetstr.c_str(), nullptr, 0);

			if (loadflag == "reload")
				add_rom_entry("", "", offset, length, ROMENTRYTYPE_RELOAD | ROM_INHERITFLAGS);
			else if (loadflag == "reload_plain")
				add_rom_entry("", "", offset, length, ROMENTRYTYPE_RELOAD);
			else if (loadflag == "continue")
				add_rom_entry("", "", offset, length, ROMENTRYTYPE_CONTINUE | ROM_INHERITFLAGS);
			else if (loadflag == "fill")
				add_rom_entry("", std::move(value), offset, length, ROMENTRYTYPE_FILL);
			else if (!name.empty())
			{
				bool baddump = (status == "baddump");
				bool nodump = (status == "nodump");

				std::string hashdata;
				if (nodump)
				{
					hashdata = string_format("%s", NO_DUMP);
					if (!crc.empty() && !sha1.empty())
						parse_error("No need for hash definition");
				}
				else
				{
					if (!crc.empty() && !sha1.empty())
						hashdata = string_format("%c%s%c%s%s", util::hash_collection::HASH_CRC, crc, util::hash_collection::HASH_SHA1, sha1, (baddump ? BAD_DUMP : ""));
					else
						parse_error("Incomplete rom hash definition");
				}

				// Handle loadflag attribute
				int romflags = 0;
				if (loadflag == "load16_word_swap")
					romflags = ROM_GROUPWORD | ROM_REVERSE;
				else if (loadflag == "load16_byte")
					romflags = ROM_SKIP(1);
				else if (loadflag == "load32_word_swap")
					romflags = ROM_GROUPWORD | ROM_REVERSE | ROM_SKIP(2);
				else if (loadflag == "load32_word")
					romflags = ROM_GROUPWORD | ROM_SKIP(2);
				else if (loadflag == "load32_byte")
					romflags = ROM_SKIP(3);

				add_rom_entry(std::move(name), std::move(hashdata), offset, length, ROMENTRYTYPE_ROM | romflags);
			}
			else
				parse_error("Rom name missing");
		}
		else if (!sizestr.empty() && !loadflag.empty() && loadflag == "ignore")
		{
			UINT32 length = strtol(sizestr.c_str(), nullptr, 0);
			add_rom_entry("", "", 0, length, ROMENTRYTYPE_IGNORE | ROM_INHERITFLAGS);
		}
		else
			parse_error("Incomplete rom definition");
	}

	// <rom name='' sha1='' status='' writeable=''>
	else if (strcmp(tagname, "disk") == 0)
	{
		static const char *attrnames[] = { "name", "sha1", "status", "writeable" };
		auto attrvalues = parse_attributes(attributes, attrnames);

		std::string &name = attrvalues[0];
		const std::string &sha1 = attrvalues[1];
		const std::string &status = attrvalues[2];
		const std::string &writeablestr = attrvalues[3];
		if (!name.empty() && !sha1.empty())
		{
			const bool baddump = (status == "baddump");
			const bool nodump = (status == "nodump" );
			const bool writeable = (writeablestr == "yes");
			std::string hashdata = string_format("%c%s%s", util::hash_collection::HASH_SHA1, sha1, (nodump ? NO_DUMP : (baddump ? BAD_DUMP : "")));

			add_rom_entry(std::move(name), std::move(hashdata), 0, 0, ROMENTRYTYPE_ROM | (writeable ? DISK_READWRITE : DISK_READONLY));
		}
		else if (status.empty() || (status == "nodump")) // a no_dump chd is not an incomplete entry
			parse_error("Incomplete disk definition");
	}

	// <dipvalue>
	else if (strcmp(tagname, "dipvalue") == 0)
		;
	else
		unknown_tag(tagname);
}
示例#3
0
static void
dissect_ipp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
    proto_tree  *ipp_tree;
    proto_item  *ti;
    int          offset     = 0;
    gboolean     is_request = (pinfo->destport == pinfo->match_uint);
    /* XXX - should this be based on the HTTP header? */
    guint16      status_code;
    const gchar *status_fmt;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPP");
    if (is_request)
        col_set_str(pinfo->cinfo, COL_INFO, "IPP request");
    else
        col_set_str(pinfo->cinfo, COL_INFO, "IPP response");

    if (tree) {
        ti = proto_tree_add_item(tree, proto_ipp, tvb, offset, -1, ENC_NA);
        ipp_tree = proto_item_add_subtree(ti, ett_ipp);

        proto_tree_add_text(ipp_tree, tvb, offset, 2, "Version: %u.%u",
                            tvb_get_guint8(tvb, offset),
                            tvb_get_guint8(tvb, offset + 1));
        offset += 2;

        if (is_request) {
            proto_tree_add_text(ipp_tree, tvb, offset, 2, "Operation-id: %s",
                                val_to_str(tvb_get_ntohs(tvb, offset), operation_vals,
                                           "Unknown (0x%04x)"));
        } else {
            status_code = tvb_get_ntohs(tvb, offset);
            switch (status_code & STATUS_TYPE_MASK) {

            case STATUS_SUCCESSFUL:
                status_fmt = "Successful (0x%04x)";
                break;

            case STATUS_INFORMATIONAL:
                status_fmt = "Informational (0x%04x)";
                break;

            case STATUS_REDIRECTION:
                status_fmt = "Redirection (0x%04x)";
                break;

            case STATUS_CLIENT_ERROR:
                status_fmt = "Client error (0x%04x)";
                break;

            case STATUS_SERVER_ERROR:
                status_fmt = "Server error (0x%04x)";
                break;

            default:
                status_fmt = "Unknown (0x%04x)";
                break;
            }
            proto_tree_add_text(ipp_tree, tvb, offset, 2, "Status-code: %s",
                                val_to_str(status_code, status_vals, status_fmt));
        }
        offset += 2;

        proto_tree_add_text(ipp_tree, tvb, offset, 4, "Request ID: %u",
                            tvb_get_ntohl(tvb, offset));
        offset += 4;

        offset = parse_attributes(tvb, offset, ipp_tree);

        if (tvb_offset_exists(tvb, offset)) {
            call_dissector(data_handle,
                           tvb_new_subset_remaining(tvb, offset), pinfo,
                           ipp_tree);
        }
    }
}
示例#4
0
/*****************************************************************************
 * dreme > model > background
 *
 *  type            is the alphabet DNA or RNA (optional when custom alphabet specified)
 *  <symbol>        frequency of <symbol> from core alphabet
 *  from            from the negative dataset or a background file
 *  file            the background file (optional)
 *  last_mod_date   the last modified date of the background file (optional)
 ****************************************************************************/
static void start_ele_background(PS_T *ps, const xmlChar **attrs) {
  int type, from;
  char *file, *lastmod;

  // set reasonable defaults
  type = DREME_BG_FROM_DATASET;
  from = DREME_ALPH_DNA;
  file = NULL;
  lastmod = NULL;

  char* type_options[2] = {"dna", "rna"};
  int type_values[2] = {DREME_ALPH_DNA, DREME_ALPH_RNA};
  MULTI_T type_multi = {.count = 2, .options = type_options, 
    .outputs = type_values, .target = &(type)};

  char* from_options[2] = {"dataset", "file"};
  int from_values[2] = {DREME_BG_FROM_DATASET, DREME_BG_FROM_FILE};
  MULTI_T from_multi = {.count = 2, .options = from_options, 
    .outputs = from_values, .target = &(from)};

  char* names[4] = {"file", "from", "last_mod_date", "type"};
  int (*parsers[4])(char*, void*) = {ld_str, ld_multi, ld_str, ld_multi};
  void *data[4] = {&file, &from_multi, &lastmod, &type_multi};
  BOOLEAN_T required[4] = {FALSE, TRUE, FALSE, FALSE};
  BOOLEAN_T done[4];

  required[3] = !ps->seen_alphabet;
  parse_attributes(dreme_attr_parse_error, ps, "background", attrs, 4, names, parsers, data, required, done);

  if (from == DREME_BG_FROM_FILE) {
    if (!done[0]) dreme_attr_parse_error(ps, PARSE_ATTR_MISSING, "background", "file", NULL);
    if (!done[2]) dreme_attr_parse_error(ps, PARSE_ATTR_MISSING, "background", "last_mod_date", NULL);
  }

  // if we haven't seen the alphabet then we must define it from the type
  if (!ps->seen_alphabet) {
    int idx = 0;
    rbtree_make(ps->alph_ids, "A", &idx); idx++;
    rbtree_make(ps->alph_ids, "C", &idx); idx++;
    rbtree_make(ps->alph_ids, "G", &idx); idx++;
    rbtree_make(ps->alph_ids, (type == DREME_ALPH_DNA ? "T" : "U"), &idx);
  }
  parse_freq_attrs(ps, "background", attrs);

  if (ps->callbacks->handle_background && ps->state != PS_ERROR) {
    ps->callbacks->handle_background(ps->user_data, rbtree_size(ps->alph_ids), ps->freqs, from, file, lastmod);
  }
}

/*****************************************************************************
 * dreme > model > stop
 *
 *  evalue          the stopping evalue (returned as log10).
 *  count           the stopping count.
 *  time            the stopping time.
 ****************************************************************************/
static void start_ele_stop(PS_T *ps, const xmlChar **attrs) {
  int count, time;
  double log10evalue;

  char* names[3] = {"count", "evalue", "time"};
  int (*parsers[3])(char*, void*) = {ld_int, ld_log10_ev, ld_int};
  void *data[3] = {&count, &log10evalue, &time};
  BOOLEAN_T required[3] = {FALSE, FALSE, FALSE};
  BOOLEAN_T done[3];

  parse_attributes(dreme_attr_parse_error, ps, "stop", attrs, 3, names, parsers, data, required, done);

  if (ps->callbacks->handle_stop && ps->state != PS_ERROR) {
    ps->callbacks->handle_stop(ps->user_data, &log10evalue, &count, &time);
  }
}

/*****************************************************************************
 * dreme > model > /ngen
 * the number of generations to check (or something like that).
 ****************************************************************************/
static void end_ele_ngen(PS_T *ps) {
  int ngen;

  if (ld_int(ps->characters.buffer, &ngen)) {
    error(ps, "Bad value \"%s\" for ngen.\n", ps->characters.buffer);
  }

  if (ps->callbacks->handle_ngen && ps->state != PS_ERROR) {
    ps->callbacks->handle_ngen(ps->user_data, ngen);
  }
}
示例#5
0
void softlist_parser::parse_part_start(const char *tagname, const char **attributes)
{
	// get the current part; error if none
	if (m_current_part == nullptr)
	{
		parse_error("Tag %s found outside of part context", tagname);
		return;
	}

	// <dataarea name='' size=''>
	if (strcmp(tagname, "dataarea") == 0)
	{
		static const char *attrnames[] = { "name", "size", "width", "endianness" };
		auto attrvalues = parse_attributes(attributes, attrnames);

		if (!attrvalues[0].empty() && !attrvalues[1].empty())
		{
			// handle region attributes
			const std::string &width = attrvalues[2];
			const std::string &endianness = attrvalues[3];
			UINT32 regionflags = ROMENTRYTYPE_REGION;

			if (!width.empty())
			{
				if (width == "8")
					regionflags |= ROMREGION_8BIT;
				else if (width == "16")
					regionflags |= ROMREGION_16BIT;
				else if (width == "32")
					regionflags |= ROMREGION_32BIT;
				else if (width == "64")
					regionflags |= ROMREGION_64BIT;
				else
					parse_error("Invalid dataarea width");
			}
			if (!endianness.empty())
			{
				if (endianness == "little")
					regionflags |= ROMREGION_LE;
				else if (endianness == "big")
					regionflags |= ROMREGION_BE;
				else
					parse_error("Invalid dataarea endianness");
			}

			add_rom_entry(std::move(attrvalues[0]), "", 0, strtol(attrvalues[1].c_str(), nullptr, 0), regionflags);
		}
		else
			parse_error("Incomplete dataarea definition");
	}

	// <diskarea name=''>
	else if (strcmp(tagname, "diskarea") == 0)
	{
		static const char *attrnames[] = { "name" };
		auto attrvalues = parse_attributes(attributes, attrnames);

		if (!attrvalues[0].empty())
			add_rom_entry(std::move(attrvalues[0]), "", 0, 1, ROMENTRYTYPE_REGION | ROMREGION_DATATYPEDISK);
		else
			parse_error("Incomplete diskarea definition");
	}

	// <feature name='' value=''>
	else if (strcmp(tagname, "feature") == 0)
	{
		std::string featname, featvalue;

		if (parse_name_and_value(attributes, featname, featvalue))
			m_current_part->m_featurelist.emplace_back(std::move(featname), std::move(featvalue));
		else
			parse_error("Incomplete feature definition");
	}

	// <dipswitch>
	else if (strcmp(tagname, "dipswitch") == 0)
		;
	else
		unknown_tag(tagname);
}
示例#6
0
/*****************************************************************************
 * dreme > model > negatives
 *
 *  name            the name of the negative dataset
 *  count           the number of sequences in the negative dataset
 *  from            the source of the negative dataset (eg shuffled positives)
 *  file            the file containing the negative dataset (optional)
 *  last_mod_date   the last modified date of the file (optional)
 ****************************************************************************/
static void start_ele_negatives(PS_T *ps, const xmlChar **attrs) {
  char *name, *file, *lastmod;
  long count;
  int from;

  file = NULL;
  lastmod = NULL;

  char* from_options[2] = {"file", "shuffled"};
  int from_values[2] = {DREME_NEG_FILE, DREME_NEG_SHUFFLED};
  MULTI_T from_multi = {.count = 2, .options = from_options, .outputs = from_values, .target = &(from)};

  char* names[5] = {"count", "file", "from", "last_mod_date", "name"};
  int (*parsers[5])(char*, void*) = {ld_long, ld_str, ld_multi, ld_str, ld_str};
  void *data[5] = {&count, &file, &from_multi, &lastmod, &name};
  BOOLEAN_T required[5] = {TRUE, FALSE, TRUE, FALSE, TRUE};
  BOOLEAN_T done[5];

  parse_attributes(dreme_attr_parse_error, ps, "negatives", attrs, 5, names, parsers, data, required, done);

  if (ps->state != PS_ERROR && from == DREME_NEG_FILE) {
    if (file == NULL) {
      dreme_attr_parse_error(ps, PARSE_ATTR_MISSING, "negatives", "file", NULL);
    } 
    if (lastmod == NULL) {
      dreme_attr_parse_error(ps, PARSE_ATTR_MISSING, "negatives", "last_mod_date", NULL);
    }
  }

  if (ps->callbacks->handle_negatives && ps->state != PS_ERROR) {
    ps->callbacks->handle_negatives(ps->user_data, name, count, (DREME_NEG_EN)from, file, lastmod);
  }
}

/*****************************************************************************
 * DREME > model > alphabet
 ****************************************************************************/
static void start_ele_alphabet(PS_T *ps, const xmlChar **attrs) {
  char *name;
  int extends;

  char* extends_options[3] = {"dna", "protein", "rna"};
  int extends_values[3] = {ALPH_FLAG_EXTENDS_DNA, ALPH_FLAG_EXTENDS_PROTEIN, ALPH_FLAG_EXTENDS_RNA};
  MULTI_T extends_multi = {.count = 3, .options = extends_options, 
    .outputs = extends_values, .target = &(extends)};

  char* names[2] = {"like", "name"};
  int (*parsers[2])(char*, void*) = {ld_multi, ld_str};
  void *data[2] = {&extends_multi, &name};
  BOOLEAN_T required[2] = {FALSE, FALSE};
  BOOLEAN_T done[2];
  // just so we know later on when reading the background which used to set the alphabet
  ps->seen_alphabet = true;

  // defaults
  name = NULL;
  extends = 0;
  parse_attributes(dreme_attr_parse_error, ps, "alphabet", attrs, 2, names, parsers, data, required, done);

  if (ps->callbacks->start_alphabet && ps->state != PS_ERROR) {
    ps->callbacks->start_alphabet(ps->user_data, name, extends);
  }
  dreme_push_es(ps, PS_IN_ALPHABET_LETTER, ES_ONE_OR_MORE);
}

/*****************************************************************************
 * DREME > model > /alphabet
 ****************************************************************************/
static void end_ele_alphabet(PS_T *ps) {
  if (ps->callbacks->end_alphabet && ps->state != PS_ERROR) {
    ps->callbacks->end_alphabet(ps->user_data);
  }
}

/*****************************************************************************
 * DREME > model > alphabet > letter
 ****************************************************************************/
static void start_ele_alphabet_letter(PS_T *ps, const xmlChar **attrs) {
  char *aliases, *id, *name, *equals, symbol, complement;
  int colour, idx;

  char* names[7] = {"aliases", "colour", "complement", "equals", "id", "name", "symbol"};
  int (*parsers[7])(char*, void*) = {ld_str, ld_hex, ld_char, ld_str, ld_str, ld_str, ld_char};
  void *data[7] = {&aliases, &colour, &complement, &equals, &id, &name, &symbol};
  BOOLEAN_T required[7] = {FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE};
  BOOLEAN_T done[7];

  aliases = NULL;
  name = NULL;
  equals = NULL;
  complement = '\0';
  colour = -1;
  parse_attributes(dreme_attr_parse_error, ps, "letter", attrs, 7, names, parsers, data, required, done);

  if (ps->seen_ambig) {
    if (equals == NULL) {
      error(ps, "All core symbols must appear before any ambigous symbols.\n");
    }
  } else if (equals == NULL) {
    idx = rbtree_size(ps->alph_ids);
    rbtree_make(ps->alph_ids, id, &idx);
  } else {
    ps->seen_ambig = true;
  }

  if (ps->callbacks->handle_alphabet_letter && ps->state != PS_ERROR) {
    ps->callbacks->handle_alphabet_letter(ps->user_data, id, symbol, aliases, complement, equals, name, colour);
  }
}
示例#7
0
/**
 * ipsec pool --delattr <type> - delete attribute entry
 */
void del_attr(char *name, char *pool, char *identity,
			  char *value, value_type_t value_type)
{
	configuration_attribute_type_t type, type_ip6, type_db;
	u_int pool_id = 0, identity_id = 0;
	char id_pool_str[128] = "";
	chunk_t blob, blob_db;
	u_int id;
	enumerator_t *query;
	bool found = FALSE;

	if (pool)
	{
		pool_id = get_attr_pool(pool);
		if (pool_id == 0)
		{
			exit(EXIT_FAILURE);
		}

		if (identity)
		{
			identification_t *id;

			id = identification_create_from_string(identity);
			identity_id = get_identity(id);
			id->destroy(id);
			if (identity_id == 0)
			{
				exit(EXIT_FAILURE);
			}
			snprintf(id_pool_str, sizeof(id_pool_str),
					 " for '%s' in pool '%s'", identity, pool);
		}
		else
		{
			snprintf(id_pool_str, sizeof(id_pool_str), " in pool '%s'", pool);
		}
	}

	if (!parse_attributes(name, value, &value_type, &type, &type_ip6, &blob))
	{
		exit(EXIT_FAILURE);
	}

	if (blob.len > 0)
	{
		query = db->query(db,
					"SELECT id, type, value FROM attributes "
					"WHERE identity = ? AND pool = ? AND type = ? AND value = ?",
					DB_UINT, identity_id, DB_UINT, pool_id, DB_INT, type,
					DB_BLOB, blob, DB_UINT, DB_INT, DB_BLOB);
	}
	else if (type_ip6 == 0)
	{
		query = db->query(db,
					"SELECT id, type, value FROM attributes "
					"WHERE identity = ? AND pool = ? AND type = ?",
					DB_UINT, identity_id, DB_UINT, pool_id, DB_INT, type,
					DB_UINT, DB_INT, DB_BLOB);
	}
	else
	{
		query = db->query(db,
					"SELECT id, type, value FROM attributes "
					"WHERE identity = ? AND pool = ? AND (type = ? OR type = ?)",
					DB_UINT, identity_id, DB_UINT, pool_id, DB_INT, type,
					DB_INT, type_ip6, DB_UINT, DB_INT, DB_BLOB);
	}

	if (!query)
	{
		fprintf(stderr, "deleting '%s' attribute (%N)%s failed.\n",
				name, configuration_attribute_type_names, type, id_pool_str);
		free(blob.ptr);
		exit(EXIT_FAILURE);
	}

	while (query->enumerate(query, &id, &type_db, &blob_db))
	{
		host_t *server = NULL;

		found = TRUE;

		if (value_type == VALUE_ADDR)
		{
			int family = (type_db == type_ip6) ? AF_INET6 : AF_INET;

			server = host_create_from_chunk(family, blob_db, 0);
		}

		if (db->execute(db, NULL,
					"DELETE FROM attributes WHERE id = ?",
					 DB_UINT, id) != 1)
		{
			if (server)
			{
				fprintf(stderr, "deleting %s server %H%s failed\n",
						name, server, id_pool_str);
				server->destroy(server);
			}
			else if (value_type == VALUE_STRING)
			{
				fprintf(stderr, "deleting %s attribute (%N) with value '%.*s'%s failed.\n",
						 		name, configuration_attribute_type_names, type,
								(int)blob_db.len, blob_db.ptr, id_pool_str);
			}

			else
			{
				fprintf(stderr, "deleting %s attribute (%N) with value %#B%s failed.\n",
						 		name, configuration_attribute_type_names, type,
								&blob_db, id_pool_str);
			}
			query->destroy(query);
			free(blob.ptr);
			exit(EXIT_FAILURE);
		}
		if (server)
		{
			printf("deleted %s server %H%s\n", name, server, id_pool_str);
			server->destroy(server);
		}
		else if (value_type == VALUE_STRING)
		{
			printf("deleted %s attribute (%N) with value '%.*s'%s.\n",
				   name, configuration_attribute_type_names, type,
				   (int)blob_db.len, blob_db.ptr, id_pool_str);
		}
		else
		{
			printf("deleted %s attribute (%N) with value %#B%s.\n",
				   name, configuration_attribute_type_names, type,
				   &blob_db, id_pool_str);
		}
	}
	query->destroy(query);

	if (!found)
	{
	 	if (blob.len == 0)
		{
			if (type_ip6 == 0)
			{
				fprintf(stderr, "no %s attribute (%N) was found%s.\n", name,
						configuration_attribute_type_names, type, id_pool_str);
			}
			else
			{
				fprintf(stderr, "no %s attribute%s was found.\n",
						name, id_pool_str);
			}
		}
		else
		{
			if (value_type == VALUE_ADDR)
			{
				host_t *server = host_create_from_chunk(AF_UNSPEC, blob, 0);

				fprintf(stderr, "the %s server %H%s was not found.\n", name,
								 server, id_pool_str);
				server->destroy(server);
			}
			else
			{
				fprintf(stderr, "the %s attribute (%N) with value '%.*s'%s "
								"was not found.\n", name,
								 configuration_attribute_type_names, type,
								 (int)blob.len, blob.ptr, id_pool_str);
			}
		}
	}
	free(blob.ptr);
}
示例#8
0
/**
 * ipsec pool --addattr <type> - add attribute entry
 */
void add_attr(char *name, char *pool, char *identity,
			  char *value, value_type_t value_type)
{
	configuration_attribute_type_t type, type_ip6;
	u_int pool_id = 0, identity_id = 0;
	char id_pool_str[128] = "";
	chunk_t blob;
	bool success;

	if (pool)
	{
		pool_id = get_attr_pool(pool);
		if (pool_id == 0)
		{
			exit(EXIT_FAILURE);
		}

		if (identity)
		{
			identification_t *id;

			id = identification_create_from_string(identity);
			identity_id = get_identity(id);
			id->destroy(id);
			if (identity_id == 0)
			{
				exit(EXIT_FAILURE);
			}
			snprintf(id_pool_str, sizeof(id_pool_str),
					 " for '%s' in pool '%s'", identity, pool);
		}
		else
		{
			snprintf(id_pool_str, sizeof(id_pool_str), " in pool '%s'", pool);
		}
	}

	if (value_type == VALUE_NONE)
	{
		fprintf(stderr, "the value of the %s attribute is missing.\n", name);
		usage();
	}
	if (!parse_attributes(name, value, &value_type, &type, &type_ip6, &blob))
	{
		exit(EXIT_FAILURE);
	}

	success = db->execute(db, NULL,
				"INSERT INTO attributes (identity, pool, type, value) "
				"VALUES (?, ?, ?, ?)", DB_UINT, identity_id, DB_UINT, pool_id,
				DB_INT, type, DB_BLOB, blob) == 1;
	free(blob.ptr);

	if (success)
	{
		printf("added %s attribute (%N)%s.\n", name,
			   configuration_attribute_type_names, type, id_pool_str);
	}
	else
	{
		fprintf(stderr, "adding %s attribute (%N)%s failed.\n", name,
						configuration_attribute_type_names, type, id_pool_str);
	}
}
示例#9
0
文件: m3u8.c 项目: jwzl/ossbuild
/*
 * @data: a m3u8 playlist text data, taking ownership
 */
static gboolean
gst_m3u8_update (GstM3U8 * self, gchar * data, gboolean * updated)
{
    gint val, duration;
    gchar *title, *end;
//  gboolean discontinuity;
    GstM3U8 *list;

    g_return_val_if_fail (self != NULL, FALSE);
    g_return_val_if_fail (data != NULL, FALSE);
    g_return_val_if_fail (updated != NULL, FALSE);

    *updated = TRUE;

    /* check if the data changed since last update */
    if (self->last_data && g_str_equal (self->last_data, data)) {
        GST_DEBUG ("Playlist is the same as previous one");
        *updated = FALSE;
        g_free (data);
        return TRUE;
    }

    if (!g_str_has_prefix (data, "#EXTM3U")) {
        GST_WARNING ("Data doesn't start with #EXTM3U");
        g_free (data);
        return FALSE;
    }

    g_free (self->last_data);
    self->last_data = data;

    if (self->files) {
        g_list_foreach (self->files, (GFunc) gst_m3u8_media_file_free, NULL);
        g_list_free (self->files);
        self->files = NULL;
    }

    list = NULL;
    duration = -1;
    title = NULL;
    data += 7;
    while (TRUE) {
        end = g_utf8_strchr (data, -1, '\n');       /* FIXME: support \r\n */
        if (end)
            *end = '\0';

        if (data[0] != '#') {
            if (duration < 0 && list == NULL) {
                GST_LOG ("%s: got line without EXTINF or EXTSTREAMINF, dropping", data);
                goto next_line;
            }

            if (!gst_uri_is_valid (data)) {
                gchar *slash;
                if (!self->uri) {
                    GST_WARNING ("uri not set, can't build a valid uri");
                    goto next_line;
                }
                slash = g_utf8_strrchr (self->uri, -1, '/');
                if (!slash) {
                    GST_WARNING ("Can't build a valid uri");
                    goto next_line;
                }

                *slash = '\0';
                data = g_strdup_printf ("%s/%s", self->uri, data);
                *slash = '/';
            } else
                data = g_strdup (data);

            if (list != NULL) {
                if (g_list_find_custom (self->lists, data,
                                        (GCompareFunc) _m3u8_compare_uri)) {
                    GST_DEBUG ("Already have a list with this URI");
                    gst_m3u8_free (list);
                    g_free (data);
                } else {
                    gst_m3u8_set_uri (list, data);
                    self->lists = g_list_append (self->lists, list);
                }
                list = NULL;
            } else {
                GstM3U8MediaFile *file;
                file =
                    gst_m3u8_media_file_new (data, title, duration,
                                             self->mediasequence++);
                duration = -1;
                title = NULL;
                self->files = g_list_append (self->files, file);
            }

        } else if (g_str_has_prefix (data, "#EXT-X-ENDLIST")) {
            self->endlist = TRUE;
        } else if (g_str_has_prefix (data, "#EXT-X-VERSION:")) {
            if (int_from_string (data + 15, &data, &val))
                self->version = val;
        } else if (g_str_has_prefix (data, "#EXT-X-STREAM-INF:")) {
            gchar *v, *a;

            if (list != NULL) {
                GST_WARNING ("Found a list without a uri..., dropping");
                gst_m3u8_free (list);
            }

            list = gst_m3u8_new ();
            data = data + 18;
            while (data && parse_attributes (&data, &a, &v)) {
                if (g_str_equal (a, "BANDWIDTH")) {
                    if (!int_from_string (v, NULL, &list->bandwidth))
                        GST_WARNING ("Error while reading BANDWIDTH");
                } else if (g_str_equal (a, "PROGRAM-ID")) {
                    if (!int_from_string (v, NULL, &list->program_id))
                        GST_WARNING ("Error while reading PROGRAM-ID");
                } else if (g_str_equal (a, "CODECS")) {
                    g_free (list->codecs);
                    list->codecs = g_strdup (v);
                } else if (g_str_equal (a, "RESOLUTION")) {
                    if (!int_from_string (v, &v, &list->width))
                        GST_WARNING ("Error while reading RESOLUTION width");
                    if (!v || *v != '=') {
                        GST_WARNING ("Missing height");
                    } else {
                        v = g_utf8_next_char (v);
                        if (!int_from_string (v, NULL, &list->height))
                            GST_WARNING ("Error while reading RESOLUTION height");
                    }
                }
            }
        } else if (g_str_has_prefix (data, "#EXT-X-TARGETDURATION:")) {
            if (int_from_string (data + 22, &data, &val))
                self->targetduration = val;
        } else if (g_str_has_prefix (data, "#EXT-X-MEDIA-SEQUENCE:")) {
            if (int_from_string (data + 22, &data, &val))
                self->mediasequence = val;
        } else if (g_str_has_prefix (data, "#EXT-X-DISCONTINUITY")) {
            /* discontinuity = TRUE; */
        } else if (g_str_has_prefix (data, "#EXT-X-PROGRAM-DATE-TIME:")) {
            /* <YYYY-MM-DDThh:mm:ssZ> */
            GST_DEBUG ("FIXME parse date");
        } else if (g_str_has_prefix (data, "#EXT-X-ALLOW-CACHE:")) {
            g_free (self->allowcache);
            self->allowcache = g_strdup (data + 19);
        } else if (g_str_has_prefix (data, "#EXTINF:")) {
            if (!int_from_string (data + 8, &data, &val)) {
                GST_WARNING ("Can't read EXTINF duration");
                goto next_line;
            }
            duration = val;
            if (duration > self->targetduration)
                GST_WARNING ("EXTINF duration > TARGETDURATION");
            if (!data || *data != ',')
                goto next_line;
            data = g_utf8_next_char (data);
            if (data != end) {
                g_free (title);
                title = g_strdup (data);
            }
        } else {
            GST_LOG ("Ignored line: %s", data);
        }

next_line:
        if (!end)
            break;
        data = g_utf8_next_char (end);      /* skip \n */
    }

    /* redorder playlists by bitrate */
    if (self->lists)
        self->lists =
            g_list_sort (self->lists,
                         (GCompareFunc) gst_m3u8_compare_playlist_by_bitrate);

    return TRUE;
}
示例#10
0
void start_ele_sequence_filtering(CISML_PARSER_T *ps, const xmlChar **attrs) {
  int is_filtered;
  char *program = NULL;

  char* filter_options[2] = {"off", "on"};
  int filter_values[2] = {FALSE, TRUE};
  MULTI_T filter_multi = {.count = 2, .options = filter_options, .outputs = filter_values, .target = &(is_filtered)};

  char* names[2] = {"on-off", "type"};
  int (*parsers[2])(char*, void*) = {ld_multi, ld_str};
  void *data[2] = {&filter_multi, &program};
  BOOLEAN_T required[2] = {TRUE, FALSE};

  parse_attributes(cisml_attr_parse_error, ps, "sequence-filtering", attrs, 2, names, parsers, data, required, NULL);

  if (ps->callbacks->handle_sequence_filtering) {
    ps->callbacks->handle_sequence_filtering(ps->invoker_state, is_filtered, program);
  }
}

void end_ele_parameters(CISML_PARSER_T *ps) {
  if (ps->callbacks->end_parameters) {
    ps->callbacks->end_parameters(ps->invoker_state);
  }
}

void start_ele_multi_pattern_scan(CISML_PARSER_T *ps, const xmlChar **attrs) {
  if (ps->multi == MP_UNDECIDED) ps->multi = MP_MULTI_PATTERN;
  else if (ps->multi == MP_SINGLE_PATTERN) {
    DEBUG_MSG(HIGH_VERBOSE, "CISML parser error: when multi-pattern-scan is used, pattern must not be a child of cis-element-search\n");
    ps->state = PS_ERROR;
    return;
  }
  double pvalue;
  double score;

  char* names[2] = {"pvalue", "score"};
  int (*parsers[2])(char*, void*) = {ld_pvalue, ld_double};
  void *data[2] = {&pvalue, &score};
  BOOLEAN_T required[2] = {FALSE, FALSE};
  BOOLEAN_T done[2] = {FALSE, FALSE};

  parse_attributes(cisml_attr_parse_error, ps, "multi-pattern-scan", attrs, 2, names, parsers, data, required, done);

  if (ps->callbacks->start_multi_pattern_scan) {
    ps->callbacks->start_multi_pattern_scan(ps->invoker_state, (done[0] ? &pvalue : NULL), (done[1] ? &score : NULL));
  }
}

void start_ele_pattern(CISML_PARSER_T *ps, const xmlChar **attrs) {
  if (ps->multi == MP_UNDECIDED) ps->multi = MP_SINGLE_PATTERN;
  else if (ps->multi == MP_MULTI_PATTERN) {
    DEBUG_MSG(HIGH_VERBOSE, "CISML parser error: when multi-pattern-scan is used, pattern must not be a child of cis-element-search\n");
    ps->state = PS_ERROR;
    return;
  }
  char *accession = NULL;
  char *name = NULL;
  char *db = NULL;
  char *lsId = NULL;
  double score = 0;
  double pvalue = 0;

  char* names[6] = {"accession", "db", "lsId", "name", "pvalue", "score"};
  int (*parsers[6])(char*, void*) = {ld_str, ld_str, ld_str, ld_str, ld_pvalue, ld_double};
  void *data[6] = {&accession, &db, &lsId, &name, &pvalue, &score};
  BOOLEAN_T required[6] = {TRUE, FALSE, FALSE, TRUE, FALSE, FALSE};
  BOOLEAN_T done[6] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};

  parse_attributes(cisml_attr_parse_error, ps, "pattern", attrs, 6, names, parsers, data, required, done);

  if (ps->callbacks->start_pattern) {
    ps->callbacks->start_pattern(ps->invoker_state, accession, name, db, lsId, 
        (done[4] ? &pvalue : NULL), (done[5] ? &score : NULL));
  }
}

void start_ele_scanned_sequence(CISML_PARSER_T *ps, const xmlChar **attrs) {
  char *accession = NULL;
  char *name = NULL;
  char *db = NULL;
  char *lsId = NULL;
  double score = 0;
  double pvalue = 0;
  long length = 0;

  char* names[7] = {"accession", "db", "length", "lsId", "name", "pvalue", "score"};
  int (*parsers[7])(char*, void*) = {ld_str, ld_str, ld_long, ld_str, ld_str, ld_pvalue, ld_double};
  void *data[7] = {&accession, &db, &length, &lsId, &name, &pvalue, &score};
  BOOLEAN_T required[7] = {TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE};
  BOOLEAN_T done[7] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};

  parse_attributes(cisml_attr_parse_error, ps, "scanned-sequence", attrs, 7, names, parsers, data, required, done);

  if (ps->callbacks->start_scanned_sequence) {
    ps->callbacks->start_scanned_sequence(ps->invoker_state, accession, name, db, lsId, 
        (done[6] ? &score : NULL), (done[5] ? &pvalue : NULL), (done[2] ? &length : NULL));
  }
}