Ejemplo n.º 1
0
static bool parse_manifest(struct uae_prefs *p, unzFile uz, const char *manifest)
{
  bool bResult = false;
  char buffer[MAX_MANIFEST_ENTRY];
  
  xmlDocPtr doc = xmlReadMemory(manifest, strlen(manifest), NULL, NULL, 0);;
  if(doc != NULL) 
  {
    xmlNode *root_element = xmlDocGetRootElement(doc);
    xmlNode *rp9 = get_node(root_element, "rp9");
    if(rp9 != NULL)
    {
      xmlNode *app = get_node(rp9, "application");
      if(app != NULL)
      {
        int rom = -1;
        xmlNode *tmp = get_node(app, "description");
        if(tmp != NULL && get_value(tmp, "systemrom", buffer, MAX_MANIFEST_ENTRY))
          rom = atoi(buffer);
        
        tmp = get_node(app, "configuration");
        if(tmp != NULL && get_value(tmp, "system", buffer, MAX_MANIFEST_ENTRY))
        {
          set_default_system(p, buffer, rom);
          
          parse_compatibility(p, tmp);
          parse_ram(p, tmp);
          parse_clip(p, tmp);
          parse_peripheral(p, tmp);
          parse_boot(p, tmp);
          extract_media(p, uz, app);
          bResult = true;
        }
      }
    }
    xmlFreeDoc(doc);
  }
  
  return bResult;
}
Ejemplo n.º 2
0
/* process_packet:
 * Callback which processes a packet captured by libpcap. */
void process_packet(u_char *user, const struct pcap_pkthdr *hdr, const u_char *pkt)
{
    struct tcphdr tcp;
    int off, len, delta;
    connection *C, c;
    struct sockaddr_storage src, dst;
    struct sockaddr *s, *d;
    uint8_t proto;
    
    s = (struct sockaddr *)&src;
    d = (struct sockaddr *)&dst;

    if (handle_link_layer(&datalink_info, pkt, hdr->caplen, &proto, &off))
    	return;
	
    if (layer3_find_tcp(pkt, proto, &off, s, d, &tcp))
    	return;

    len = hdr->caplen - off;

    /* XXX fragmented packets and other nasties. */

    /* try to find the connection slot associated with this. */
    C = find_connection(s, d);

    /* no connection at all, so we need to allocate one. */
    if (!C) {
        log_msg(LOG_INFO, "new connection: %s", connection_string(s,d));
        C = alloc_connection();
        *C = connection_new(s, d);
        /* This might or might not be an entirely new connection (SYN flag
         * set). Either way we need a sequence number to start at. */
        (*C)->isn = ntohl(tcp.th_seq);
    }

    /* Now we need to process this segment. */
    c = *C;
    delta = 0;/*tcp.syn ? 1 : 0;*/

    /* NB (STD0007):
     *    SEG.LEN = the number of octets occupied by the data in the
     *    segment (counting SYN and FIN) */
#if 0
    if (tcp.syn)
        /* getting a new isn. */
        c->isn = htonl(tcp.seq);
#endif

    if (tcp.th_flags & TH_RST) {
        /* Looks like this connection is bogus, and so might be a
         * connection going the other way. */
        log_msg(LOG_INFO, "connection reset: %s", connection_string(s, d));

        connection_delete(c);
        *C = NULL;

        if ((C = find_connection(d, s))) {
            connection_delete(*C);
            *C = NULL;
        }

        return;
    }

    if (len > 0) {
        /* We have some data in the packet. If this data occurred after
         * the first data we collected for this connection, then save it
         * so that we can look for images. Otherwise, discard it. */
        unsigned int offset;

        offset = ntohl(tcp.th_seq);

        /* Modulo 2**32 arithmetic; offset = seq - isn + delta. */
        if (offset < (c->isn + delta))
            offset = 0xffffffff - (c->isn + delta - offset);
        else
            offset -= c->isn + delta;

        if (offset > c->len + WRAPLEN) {
            /* Out-of-order packet. */
            log_msg(LOG_INFO, "out of order packet: %s", connection_string(s, d));
        } else {
            connection_push(c, pkt + off, offset, len);
            extract_media(c);
        }
    }
    if (tcp.th_flags & TH_FIN) {
        /* Connection closing; mark it as closed, but let sweep_connections
         * free it if appropriate. */
        log_msg(LOG_INFO, "connection closing: %s, %d bytes transferred", connection_string(s, d), c->len);
        c->fin = 1;
    }

    /* sweep out old connections */
    sweep_connections();
}