示例#1
0
/** Parse data into a linked list of blobs.
 */
struct Blob* parse_all_blobs(struct Parser* const p) {
  struct Blob* b = 0;
  struct Blob* last = 0;
  b = parse_blob(p); //parse a first
  for( last=b; 
       p->cur - p->data < p->len; 
       last=last->next ) {
    last->next = parse_blob(p);
    if (last->next == 0)
      break;
  }
  return b;
}
示例#2
0
文件: object.c 项目: ahappyforest/git
struct object *parse_object(unsigned char *sha1)
{
	unsigned long mapsize;
	void *map = map_sha1_file(sha1, &mapsize);
	if (map) {
		char type[100];
		unsigned long size;
		void *buffer = unpack_sha1_file(map, mapsize, type, &size);
		if (!buffer)
			return NULL;
		if (check_sha1_signature(sha1, buffer, size, type) < 0)
			printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
		munmap(map, mapsize);
		if (!strcmp(type, "blob")) {
			struct blob *ret = lookup_blob(sha1);
			parse_blob(ret);
			return &ret->object;
		} else if (!strcmp(type, "tree")) {
			struct tree *ret = lookup_tree(sha1);
			parse_tree(ret);
			return &ret->object;
		} else if (!strcmp(type, "commit")) {
			struct commit *ret = lookup_commit(sha1);
			parse_commit(ret);
			return &ret->object;
		} else if (!strcmp(type, "tag")) {
			struct tag *ret = lookup_tag(sha1);
			parse_tag(ret);
			return &ret->object;
		} else {
			return NULL;
		}
	}
	return NULL;
}
示例#3
0
Value *Parser::parse_value(void) {
    int c;
    Value *value;
    c = read_byte();
    switch (c) {
    case trace::TYPE_NULL:
        value = new Null;
        break;
    case trace::TYPE_FALSE:
        value = new Bool(false);
        break;
    case trace::TYPE_TRUE:
        value = new Bool(true);
        break;
    case trace::TYPE_SINT:
        value = parse_sint();
        break;
    case trace::TYPE_UINT:
        value = parse_uint();
        break;
    case trace::TYPE_FLOAT:
        value = parse_float();
        break;
    case trace::TYPE_DOUBLE:
        value = parse_double();
        break;
    case trace::TYPE_STRING:
        value = parse_string();
        break;
    case trace::TYPE_ENUM:
        value = parse_enum();
        break;
    case trace::TYPE_BITMASK:
        value = parse_bitmask();
        break;
    case trace::TYPE_ARRAY:
        value = parse_array();
        break;
    case trace::TYPE_STRUCT:
        value = parse_struct();
        break;
    case trace::TYPE_BLOB:
        value = parse_blob();
        break;
    case trace::TYPE_OPAQUE:
        value = parse_opaque();
        break;
    default:
        std::cerr << "error: unknown type " << c << "\n";
        exit(1);
    case -1:
        value = NULL;
        break;
    }
#if TRACE_VERBOSE
    if (value) {
        std::cerr << "\tVALUE " << value << "\n";
    }
#endif
    return value;
}
示例#4
0
static void
pro_message_available (PROFILE_INSTANCE *pi) {
    int                  result,
                         size;
    char                *buffer,
                        *payload,
                        *response;
    FRAME               *f;
    struct configobj    *appconfig = bp_get_config (pi -> channel -> conn);
    PRO_LOCALDATA       *il = (PRO_LOCALDATA *) pi -> user_ptr1;

    result = SASL_ALREADY_DONE;

    if (!(f = bpc_query_message (pi -> channel, BLU_QUERY_ANYTYPE,
                                 BLU_QUERY_ANYMSG, BLU_QUERY_ANYANS)))
        return;

    if (pro_debug) {
        fprintf (stderr,
                 "%s message_available: type=%c number=%ld answer=%ld size=%ld\n",
                 pro_name (pi -> channel -> profile_registration -> uri),
                 f -> msg_type, f -> message_number, f -> answer_number,
                 f -> size);
        fprintf (stderr, f -> size > 150 ? "%-150.150s...\n" : "%s\n",
                 f -> payload);
        fflush (stderr);
    }

    size = bpc_frame_aggregate (pi -> channel, f, &buffer);
    if (buffer == NULL) {
        bp_log (pi -> channel -> conn, LOG_PROF, 5,
                "%s message_available: out of memory aggregating message",
                 pro_name (pi -> channel -> profile_registration -> uri));
        bpc_frame_destroy (pi -> channel, f);
        return;
    }

    switch (il -> pl_task) {
        case PRO_CLIENT_ANON:
            break;

        case PRO_CLIENT_OTP:
            if (il -> pl_sent != 2)
                break;

            if (strstr (buffer, "<error") != NULL)
                sasl_error (pi, buffer, size);
            else {
                parse_blob (buffer, &il -> pl_sdb);
                if (!strcmp (il -> pl_sdb.parse_blob_status, "complete"))
                    sasl_set_local_success (pi);
                else
                    sasl_set_local_failure (pi, NULL);
            }
            break;

        case PRO_SERVER_ANON:
            if (il -> pl_sent != 0)
                break;

            if ((result = sasl_anonymous_server_guts (buffer, &il -> pl_sdb))
                    == SASL_COMPLETE)
                config_set (appconfig, SASL_REMOTE_USERNAME,
                            il -> pl_sdb.parse_blob_data);
            break;

        case PRO_SERVER_OTP:
            switch (il -> pl_sent) {
                case 0:
                    result = sasl_otp_server_guts_1 (buffer, &il -> pl_sdb);
                    break;

                case 1:
                    if ((result = sasl_otp_server_guts_2 (buffer, &il -> pl_sdb))
                            == SASL_COMPLETE) {
                        config_set (appconfig, SASL_REMOTE_USERNAME,
                                    il -> pl_sdb.authenID);
                            config_set (appconfig, SASL_REMOTE_TARGET,
                                        (il -> pl_sdb.authorID[0] != '\0')
                                            ? il -> pl_sdb.authorID
                                            : il -> pl_sdb.authenID);
                    }
                    break;
            }
            break;
    }

    bpc_buffer_destroy (pi -> channel, buffer);

    switch (il -> pl_task) {
        case PRO_CLIENT_ANON:
        case PRO_CLIENT_OTP:
            response = NULL;
            break;

        case PRO_SERVER_ANON:
        case PRO_SERVER_OTP:
            response = sasl_response (pi, result);
            break;
    }

    if (f -> msg_type == BLU_FRAME_TYPE_MSG) {
        payload = response ? response
                           : "<error code='521'>Client-side only</error>";
        size = strlen (payload) + sizeof DEFAULT_CONTENT_TYPE - 1;

        if ((buffer = bpc_buffer_allocate(pi -> channel, size)) != NULL) {
            sprintf (buffer, "%s%s", DEFAULT_CONTENT_TYPE, payload);

            bpc_send (pi -> channel,
                      (payload[1] == 'e')
                          ? BLU_FRAME_TYPE_ERR : BLU_FRAME_TYPE_RPY,
                      f -> message_number, f -> answer_number,
                      BLU_FRAME_COMPLETE, buffer, size);
            il -> pl_sent++;
        } else
            bp_log (pi -> channel -> conn, LOG_PROF, 5,
                    "%s message: out of memory sending response",
                    pro_name (pi -> channel -> profile_registration -> uri));
    }

    bpc_frame_destroy (pi -> channel, f);
}
示例#5
0
static void
pro_start_confirmation (void             *clientData,
                        PROFILE_INSTANCE *pi,
                        PROFILE          *po) {
    int                  problem,
                         size;
    char                *buffer,
                        *payload;
    PRO_LOCALDATA       *il = clientData;
    struct configobj    *appconfig = bp_get_config (pi -> channel -> conn);

    if (pro_debug) {
        fprintf (stderr, "%s start_confirmation: piggyback=\"%s\"\n",
                 pro_name (po -> uri),
                 po -> piggyback ? po -> piggyback : "<NULL>");
        fflush (stderr);
    }

    pi -> user_ptr1 = il;

    il -> pl_flags &= ~(PRO_STARTING | PRO_CLOSED);
    il -> pl_channel = pi -> channel;

    if (po -> piggyback_length == 0) {
        il -> pl_status = bp_diagnostic_new (pi -> channel -> conn, 504, NULL,
                                             "expecting blob element");
        return;
    }

    if (strstr (po -> piggyback, "<error")) {
        sasl_error (pi, po -> piggyback, po -> piggyback_length);
        return;
    }
    
    switch (il -> pl_task) {
        case PRO_CLIENT_ANON:
            parse_blob (po -> piggyback, &il -> pl_sdb);
            if (!strcmp (il -> pl_sdb.parse_blob_status, "complete"))
                sasl_set_local_success (pi);
            else
                sasl_set_local_failure (pi, NULL);
            break;

        case PRO_CLIENT_OTP:
            if (!(payload = sasl_otp_client_guts_2
                                (po -> piggyback,
                                 config_get (appconfig, SASL_LOCAL_PASSPHRASE),
                                 &problem, &il -> pl_sdb))) {
                if (problem == SASL_ERROR_ALGORITHM) {
                    config_set (appconfig, SASL_LOCAL_CODE, "504");
                    config_set (appconfig, SASL_LOCAL_REASON,
                                "unsupported algorithm");
                } else {
                    config_set (appconfig, SASL_LOCAL_CODE, "501");
                    config_set (appconfig, SASL_LOCAL_REASON,
                                "unable to parse blob");
                }

                payload = "<blob status='abort' />";
            }
            size = strlen (payload) + sizeof DEFAULT_CONTENT_TYPE - 1;
            if ((buffer = bpc_buffer_allocate (pi -> channel, size)) != NULL) {
                sprintf (buffer, "%s%s", DEFAULT_CONTENT_TYPE, payload);

                bpc_send (pi -> channel, BLU_FRAME_TYPE_MSG,
                          BLU_FRAME_MSGNO_UNUSED, BLU_FRAME_IGNORE_ANSNO,
                          BLU_FRAME_COMPLETE, buffer, size);
                il -> pl_sent++;
            } else
                bp_log (pi -> channel -> conn, LOG_PROF, 5,
                        "%s start_confirmation: out of memory",
                        pro_name (po -> uri));
            break;
    }
}
std::vector<std::string *> SQL_ROW::parse_row(std::string &s) {
  // parses a SQL row of the format "value,value,value,value", 
  // where value can be of the form:
  //   number      (i.e. 10)
  //   "string"
  //   'string'
  //   LIST{value,value,value}
  //   ROW(value,value,value)::typename
  // the passed string is consumed by this routine.
  // WARNING: NOT THREAD SAFE
  std::string::size_type comma,dquote,quote,p;
  std::vector<std::string *>::iterator i;
  std::vector<std::string *> rv;
  static bool outer=true;

  while (s.size()) {  // While there's still bits of string left to process
    // get rid of leading spaces and commas
    while (isspace(s[0]) && s.size()) s.erase(0,1);
    while (s[0]==',') s.erase(0,1);

    // Handle the special cases first...
    if (s.find("LIST")==0) {
      // only parse a LIST if the entire string passed to parse_row was a list
      if (outer) {
        outer=false;
        std::vector<std::string *> tmprow(parse_list(s));
        for (i=tmprow.begin();i<tmprow.end();i++) {
          rv.push_back(*i);
        }
      } else {
        rv.push_back(string_delimited(s,'L','}'));
      }
    } else if (s.find("ROW")==0) {
      // only parse a LIST if the entire string passed to parse_row was a ROW
      // type
      if (outer) {
        outer=false;
        std::vector<std::string *> tmprow(parse_type(s));
        for (i=tmprow.begin();i<tmprow.end();i++) {
          rv.push_back(*i);
        }
      } else {
        rv.push_back(string_delimited(s,'R',')'));
      }
    } else if (s.find("<BYTE")==0) {
      rv.push_back(parse_blob(s));
    } else {
    // now for the non-special cases...  We need to find the delimiting
    // commas for the item at the head of the line...
      comma=s.find(',');
    // but beware that the item we're parsing might be a string
      quote=s.find('\'');
      dquote=s.find('\"');
      p=std::min(std::min(comma,quote),dquote);
    // if we found none of the above, we're done.
      if (!found(p)) {
        rv.push_back(new std::string(s));
#ifdef DEBUG_ALLOCATIONS
        fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
        fflush(stderr);
#endif
	s.erase();
      } else {
        switch (s[p]) {
        case ',':  // if we found a comma, this is a non quoted entry
	  rv.push_back(new std::string(s,0,p));
#ifdef DEBUG_ALLOCATIONS
          fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
          fflush(stderr);
#endif
	  s.erase(0,p+1);
          break;
	case '\'': // if we found a quote we need to find the close quote 
          quote=s.find('\'',p+1);
	  if (found(quote)) {
	    // if we found it, use the quoted entity
	    rv.push_back(new std::string(s,p+1,quote-p-1));
#ifdef DEBUG_ALLOCATIONS
            fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
            fflush(stderr);
#endif
	    s.erase(0,quote+2); // Assume that the character after our quote is
	                        // our comma.
	  } else {
	    // if we didn't find it, we guess that everything up to the next 
	    // comma is OK.
	    rv.push_back(new std::string(s,0,comma));
#ifdef DEBUG_ALLOCATIONS
            fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
            fflush(stderr);
#endif
	    s.erase(0,comma+1);
	  }
	  break;
	case '\"': // if we found a dquote we need to find the close quote 
          dquote=s.find('\"',p+1);
	  if (found(dquote)) {
	    // if we found it, use the quoted entity
	    rv.push_back(new std::string(s,p+1,dquote-p-1));
#ifdef DEBUG_ALLOCATIONS
            fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
            fflush(stderr);
#endif
	    s.erase(0,dquote+2); // Assume that the character after our quote is
	                        // our comma.
	  } else {
	    // if we didn't find it, we guess that everything up to the next 
	    // comma is OK.
	    rv.push_back(new std::string(s,0,comma));
#ifdef DEBUG_ALLOCATIONS
            fprintf(stderr,"std::string allocated at 0x%p\n",rv[rv.size()-1]);
            fflush(stderr);
#endif
	    s.erase(0,comma+1);
	  }
	  break;
	default:
	  // this should never happen
	  abort();
	}
      }
    }
    outer=false;
  }
  outer=true;
  return rv;
}