Example #1
0
/**
 * qdict_put_obj(): Put a new QObject into the dictionary
 *
 * Insert the pair 'key:value' into 'qdict', if 'key' already exists
 * its 'value' will be replaced.
 *
 * This is done by freeing the reference to the stored QObject and
 * storing the new one in the same entry.
 *
 * NOTE: ownership of 'value' is transferred to the QDict
 */
void qdict_put_obj(QDict *qdict, const char *key, QObject *value)
{
    unsigned int bucket;
    QDictEntry *entry;

    bucket = tdb_hash(key) % QDICT_BUCKET_MAX;
    entry = qdict_find(qdict, key, bucket);
    if (entry) {
        /* replace key's value */
        qobject_decref(entry->value);
        entry->value = value;
    } else {
        /* allocate a new entry */
        entry = alloc_entry(key, value);
        QLIST_INSERT_HEAD(&qdict->table[bucket], entry, next);
        qdict->size++;
    }
}
Example #2
0
/**
 * qdict_put_obj(): Put a new QObject into the dictionary
 *
 * Insert the pair 'key:value' into 'qdict', if 'key' already exists
 * its 'value' will be replaced.
 *
 * This is done by freeing the reference to the stored QObject and
 * storing the new one in the same entry.
 *
 * NOTE: ownership of 'value' is transferred to the QDict
 */
void qdict_put_obj(QDict *qdict, const char *key, QObject *value)
{
    unsigned int hash;
    QDictEntry *entry;

    hash = tdb_hash(key) % QDICT_HASH_SIZE;
    entry = qdict_find(qdict, key, hash);
    if (entry) {
        /* replace key's value */
        qobject_decref(entry->value);
        entry->value = value;
    } else {
        /* allocate a new entry */
        entry = alloc_entry(key, value);
        QLIST_INSERT_HEAD(&qdict->table[hash], entry, next);
    }

    qdict->size++;
}
Example #3
0
static int getaddr_info_single_addr(const char *service,
				uint32_t addr,
				const struct addrinfo *hints,
				struct addrinfo **res)
{

	struct addrinfo *ai = NULL;
	struct in_addr ip;
	unsigned short port = 0;

	if (service) {
		port = (unsigned short)atoi(service);
	}
	ip.s_addr = htonl(addr);

	ai = alloc_entry(hints, ip, port);
	if (!ai) {
		return EAI_MEMORY;
	}

	/* If we're asked for the canonical name,
	 * make sure it returns correctly. */
	if (!(hints->ai_flags & AI_NUMERICSERV) &&
			hints->ai_flags & AI_CANONNAME) {
		int err;
		if (addr == INADDR_LOOPBACK || addr == INADDR_ANY) {
			ai->ai_canonname = get_my_canon_name(&err);
		} else {
			ai->ai_canonname =
			get_canon_name_from_addr(ip,&err);
		}
		if (ai->ai_canonname == NULL) {
			freeaddrinfo(ai);
			return err;
		}
	}

	*res = ai;
	return 0;
}
static struct entry *update_hotspot_queue(struct smq_policy *mq, dm_oblock_t b, struct bio *bio)
{
	unsigned hi;
	dm_oblock_t hb = to_hblock(mq, b);
	struct entry *e = h_lookup(&mq->hotspot_table, hb);

	if (e) {
		stats_level_accessed(&mq->hotspot_stats, e->level);

		hi = get_index(&mq->hotspot_alloc, e);
		q_requeue(&mq->hotspot, e,
			  test_and_set_bit(hi, mq->hotspot_hit_bits) ?
			  0u : mq->hotspot_level_jump);

	} else {
		stats_miss(&mq->hotspot_stats);

		e = alloc_entry(&mq->hotspot_alloc);
		if (!e) {
			e = q_pop(&mq->hotspot);
			if (e) {
				h_remove(&mq->hotspot_table, e);
				hi = get_index(&mq->hotspot_alloc, e);
				clear_bit(hi, mq->hotspot_hit_bits);
			}

		}

		if (e) {
			e->oblock = hb;
			q_push(&mq->hotspot, e);
			h_insert(&mq->hotspot_table, e);
		}
	}

	return e;
}
Example #5
0
mod2entry *mod2sparse_insert
( mod2sparse *m,
  int row,
  int col
)
{
#ifndef SPARSE_MATRIX_OPT_FOR_LDPC_STAIRCASE
  mod2entry *re, *ce, *ne;
#else
  mod2entry *re, *ce, *ne, *ce2;
#endif

  if (row<0 || row>=mod2sparse_rows(m) || col<0 || col>=mod2sparse_cols(m))
  { fprintf(stderr,"mod2sparse_insert: row or column index out of bounds\n");
    exit(1);
  }

  /* Find old entry and return it, or allocate new entry and insert into row. */

  re = mod2sparse_last_in_row(m,row);

  if (!mod2sparse_at_end(re) && mod2sparse_col(re)==col) 
  { return re;
  }

  if (mod2sparse_at_end(re) || mod2sparse_col(re)<col) 
  { re = re->right;
  }
  else
  {
    re = mod2sparse_first_in_row(m,row);

    for (;;)
    { 
      if (!mod2sparse_at_end(re) && mod2sparse_col(re)==col) 
      { return re;
      }

      if (mod2sparse_at_end(re) || mod2sparse_col(re)>col)
      { break;
      } 

      re = mod2sparse_next_in_row(re);
    }
  }

  ne = alloc_entry(m);

  ne->row = row;
  ne->col = col;

  ne->left = re->left;
  ne->right = re;
  ne->left->right = ne;
  ne->right->left = ne;

  /* Insert new entry into column. */

#ifndef SPARSE_MATRIX_OPT_FOR_LDPC_STAIRCASE
  /* If we find an existing entry here,
     the matrix must be garbled, since we didn't find it in the row. */

  ce = mod2sparse_last_in_col(m,col);

  if (!mod2sparse_at_end(ce) && mod2sparse_row(ce)==row) 
  { fprintf(stderr,"mod2sparse_insert: Garbled matrix\n");
    exit(1);
  }

  if (mod2sparse_at_end(ce) || mod2sparse_row(ce)<row) 
  { ce = ce->down;
  }
  else
  {
#else
    ce2 = &(m->cols[col]);
#endif
    ce = mod2sparse_first_in_col(m,col);

    for (;;)
    { 
      if (!mod2sparse_at_end(ce) && mod2sparse_row(ce)==row) 
      { fprintf(stderr,"mod2sparse_insert: Garbled matrix\n");
        exit(1);
      }

      if (mod2sparse_at_end(ce) || mod2sparse_row(ce)>row)
      { break;
      } 
#ifdef SPARSE_MATRIX_OPT_FOR_LDPC_STAIRCASE
      ce2 = ce;
#endif     
      ce = mod2sparse_next_in_col(ce);
    }    
    
#ifndef SPARSE_MATRIX_OPT_FOR_LDPC_STAIRCASE
  }
  
  ne->up = ce->up;
  ne->down = ce;
  ne->up->down = ne;
  ne->down->up = ne;
#else    
  ne->down = ce;
  ce2->down = ne;
#endif

  /* Return the new entry. */

  return ne;
}
Example #6
0
File: io.c Project: ebichu/dd-wrt
static void accept_new(void)
{
    char buffer[MAX_ATM_ADDR_LEN+1];
    struct sockaddr_atmsvc addr;
    struct atm_qos qos;
    ENTRY *entry;
    VCC *vcc;
    int fd,error;
    socklen_t len,size;

    len = sizeof(addr);
    if ((fd = accept(incoming,(struct sockaddr *) &addr,&len)) < 0) {
	error = errno;
	diag(COMPONENT,DIAG_ERROR,"accept: %s",strerror(errno));
	if (error == EUNATCH) {
	    diag(COMPONENT,DIAG_WARN,"disabling SVCs");
	    (void) close(incoming);
	    incoming = -1;
	}
	return;
    }
    /* the following code probably belongs to arp.c ... */
    if (atm2text(buffer,MAX_ATM_ADDR_LEN+1,(struct sockaddr *) &addr,pretty) <
      0) strcpy(buffer,"<atm2text error>");
    diag(COMPONENT,DIAG_DEBUG,"Incoming call from %s",buffer);
    size = sizeof(qos);
    if (getsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,&size) < 0)
	diag(COMPONENT,DIAG_FATAL,"getsockopt SO_ATMQOS: %s",strerror(errno));
    if (size != sizeof(qos))
	diag(COMPONENT,DIAG_FATAL,"SO_ATMQOS: size %d != %d",size,sizeof(qos));
    if (ioctl(fd,ATMARP_MKIP,qos.txtp.traffic_class == ATM_NONE ? 0 :
      CLIP_DEFAULT_IDLETIMER) < 0) {
        diag(COMPONENT,DIAG_ERROR,"ioctl ATMARP_MKIP: %s",strerror(errno));
        (void) do_close(fd);
        return;
    }
    vcc = alloc_t(VCC);
    vcc->active = 0;
    vcc->connecting = 0;
    vcc->fd = fd;
    if (qos.txtp.traffic_class == ATM_NONE) {
	vcc->entry = NULL;
	incoming_unidirectional(vcc);
	Q_INSERT_HEAD(unidirectional_vccs,vcc);
	return;
    }
    if (merge) {
	ITF *itf;

	for (itf = itfs; itf; itf = itf->next) {
	    entry = lookup_addr(itf,&addr);
	    if (entry) {
		vcc->entry = entry;
		Q_INSERT_HEAD(entry->vccs,vcc);
		if (entry->state == as_valid) {
		    if (set_ip(vcc->fd,entry->ip) < 0) {
			diag(COMPONENT,DIAG_ERROR,"set_ip: %s",
			  strerror(errno));
			disconnect_vcc(vcc);
		    }
		    else set_sndbuf(vcc);
		}
		return;
	    }
	}
    }
    entry = alloc_entry(1);
    entry->state = as_invalid;
    entry->addr = alloc_t(struct sockaddr_atmsvc);
    *entry->addr = addr;
    entry->flags = ATF_PUBL;
    Q_INSERT_HEAD(unknown_incoming,entry);
    vcc->entry = entry;
    Q_INSERT_HEAD(entry->vccs,vcc);
    incoming_call(vcc);
}
Example #7
0
void IntervalTimer::enroll_sync(float freq, doFn fn) {
  TimerEntry* e = alloc_entry();
  int32 factor = (int32) rint(float(ticks_per_second()) / freq);
  e->initialize(fn, (doFn)-1, factor);
}
static int learn(VCC *vcc,uint32_t ip,struct sockaddr_atmsvc *addr)
{
    ENTRY *entry;
    ITF *itf;
    VCC *walk,*next;
    unsigned char *ipp;
    int result = 0;

    if (!ip) return 0;
    ipp = (unsigned char *) &ip;
    itf = lookup_itf_by_ip(ip);
    if (!itf) {
	diag(COMPONENT,DIAG_ERROR,"got unroutable IP address %d.%d.%d.%d",
	  ipp[0],ipp[1],ipp[2],ipp[3]);
	return 0;
    }
    entry = lookup_ip(itf,ip);
    assert(!vcc || vcc->entry);
    /*
     * If the entry on which we received the update isn't dangling but it
     * doesn't correspond to the one with the address, ...
     */
    if (entry && vcc && vcc->entry->itf && entry != vcc->entry) {
	diag(COMPONENT,DIAG_DEBUG,"collision on %d.%d.%d.%d",ipp[0],ipp[1],
	  ipp[2],ipp[3]);
	return 0;
    }
    /*
     * If the entry on which we received the update is dangling and we found
     * an entry that already describes that IP address, ...
     */
    if (entry && vcc && !vcc->entry->itf) {
	if (!entry->svc) {
	    diag(COMPONENT,DIAG_ERROR,"attempt to overwrite PVC for IP "
	      "%d.%d.%d.%d",ipp[0],ipp[1],ipp[2],ipp[3]);
	    return 0;
	}
	STOP_TIMER(vcc->entry);
	Q_REMOVE(unknown_incoming,vcc->entry);
	free(vcc->entry);
	vcc->entry = entry;
	Q_INSERT_HEAD(entry->vccs,vcc);
	set_sndbuf(vcc);
	entry->flags &= ~ATF_NOVC;
	assert(!vcc->connecting);
	if (set_ip(vcc->fd,ip) < 0) {
	    diag(COMPONENT,DIAG_ERROR,"set_ip: %s",strerror(errno));
	    disconnect_vcc(vcc);
	    vcc = NULL;
	    result = -1;
	}
    }
    /*
     * If we still don't have an entry, we try to use the entry that already
     * belongs to the VCC (InARP), or we create a new one (ARP).
     */
    if (!entry) {
	if (vcc) {
	    entry = vcc->entry;
	    if (!entry->itf) {
		Q_REMOVE(unknown_incoming,entry);
		entry->sndbuf = itf->sndbuf;
		set_sndbuf(vcc);
	    }
	    else if (entry->ip && entry->ip != ip && (entry->flags & ATF_PERM)
		  && !(entry->flags & ATF_ARPSRV)) {
		    diag(COMPONENT,DIAG_ERROR,"ignoring attempt to change IP "
		      "address of permanent entry (to %d.%d.%d.%d)",ipp[0],
		      ipp[1],ipp[2],ipp[3]);
		    return result;
		}
	}
	else {
	    entry = alloc_entry(1);
	    entry->flags = ATF_PUBL;
	}
    }
    if (!atmsvc_addr_in_use(*addr)) addr = NULL;
    if (entry->addr && addr && (entry->flags & ATF_PERM) &&
      !atm_equal((struct sockaddr *) entry->addr,(struct sockaddr *) addr,0,0))
      {
	diag(COMPONENT,DIAG_ERROR,"ignoring attempt to change ATM address of "
	  "permanent entry");
	return result;
    }
    if (entry->state == as_valid && entry->ip == ip && (!addr || (entry->addr
      && atm_equal((struct sockaddr *) entry->addr,(struct sockaddr *) addr,0,
      0)))) return result; /* no news */
    STOP_TIMER(entry);
    if (entry->ip != ip) send_notifications(entry,0);
    entry->ip = ip;
    if (!entry->itf) {
	entry->itf = itf;
	/* @@@
	 * Need to fix this is in case we allow entries without a valid IP
	 * address but with a pre-set QOS, e.g. a VC on a given PVC with an
	 * unknown remote end.
	 */
	entry->qos = entry->itf->qos;
	adjust_qos(entry->itf,&entry->qos,0);
	Q_INSERT_HEAD(itf->table,entry);
    }
    if (entry->itf != itf)
	diag(COMPONENT,DIAG_ERROR,"interesting, interface has changed ... "
	  "(%d -> %d)",entry->itf->number,itf->number);
    if (addr) {
	if (!entry->addr) entry->addr = alloc(sizeof(*addr));
	*entry->addr = *addr;
	if (merge) {
	    ENTRY *incoming;

	    while ((incoming = lookup_incoming(addr))) {
		STOP_TIMER(incoming);
		Q_REMOVE(unknown_incoming,incoming);
		incoming->vccs->entry = entry;
		Q_INSERT_HEAD(entry->vccs,incoming->vccs);
		set_sndbuf(incoming->vccs);
		free(incoming);
	    }
	}
    }
    for (walk = entry->vccs; walk; walk = next) {
	next = walk->next;
	if (!walk->connecting)
	    if (set_ip(walk->fd,ip) < 0) {
		diag(COMPONENT,DIAG_ERROR,"set_ip: %s",strerror(errno));
		disconnect_vcc(walk);
		if (walk == vcc) result = -1;
	    }
    }
    if (entry->state != as_valid) {
	if (!entry->vccs && itf->arp_srv && !(entry->flags & ATF_NOVC))
	    connect_me(entry);
	send_notifications(entry,1);
    }
    if ((entry->flags & ATF_ARPSRV) || !(entry->flags & ATF_PERM)) {
	if (entry->itf->arp_srv) START_TIMER(entry,CREVAL);
	else START_TIMER(entry,SREVAL);
    }
    entry->state = as_valid;
    return result;
}
Example #9
0
void *pool_realloc_file_line(memory_pool *pool, void *ptr, size_t size, const char *file, int line)
{
	pool_entry *new_entry;
	void *new_ptr;
	void *free_block;

	/* if we're resizing or freeing a pointer, find the existing entry */
	if (ptr != NULL)
	{
		pool_entry *orig_entry;
		pool_entry **entry;

		/* recover the pool from the pointer (ignoring the specified pool) */
		orig_entry = (pool_entry *)((UINT8 *)ptr - offsetof(pool_entry, buffer));
		if (orig_entry->cookie != MAGIC_COOKIE)
		{
			report_failure(pool, "pool_realloc: Non-pool pointer 0x%p", ptr);
			return NULL;
		}
		pool = orig_entry->pool;

		/* find the entry that this block is referring to */
		for (entry = &pool->first; *entry != NULL; entry = &(*entry)->next)
			if ((*entry)->buffer == ptr)
				break;

		/* not found? */
		if (*entry == NULL)
		{
			report_failure(pool, "pool_realloc: Unknown pointer 0x%p", ptr);
			return NULL;
		}

		if (size != 0)
		{
			/* reallocate the entry */
			new_entry = realloc(*entry, offsetof(pool_entry, buffer) + size);
			if (new_entry == NULL)
			{
				report_failure(pool, "pool_realloc: Failure to realloc %u bytes", size);
				return NULL;
			}

			/* replace the entry with the new entry */
			*entry = new_entry;

			/* is this a final entry?  if so, update pool->lastptr */
			if ((*entry)->next == NULL)
				pool->lastptr = &(*entry)->next;

			/* return a pointer to the new entry's buffer */
			new_ptr = new_entry->buffer;
		}
		else
		{
			free_block = *entry;

			/* unlink this entry */
			*entry = (*entry)->next;
			if (*entry == NULL)
				pool->lastptr = entry;

			/* free the block */
			free(free_block);
			new_ptr = NULL;
		}
	}

	/* if we don't have a pointer, just allocate a new entry */
	else
	{
		new_entry = alloc_entry(pool, size, file, line);
		if (new_entry == NULL)
			return NULL;

		/* return a pointer to the new entry's buffer */
		new_ptr = new_entry->buffer;
	}

	return new_ptr;
}
Example #10
0
/* NOTE: this is used for upgrading old XML-based entries file. Be wary of
         removing items.

   ### many attributes are no longer used within the old-style log files.
   ### These attrs need to be recognized for old entries, however. For these
   ### cases, the code will parse the attribute, but not set *MODIFY_FLAGS
   ### for that particular field. MODIFY_FLAGS is *only* used by the
   ### log-based entry modification system, and will go way once we
   ### completely move away from loggy.

   Set *NEW_ENTRY to a new entry, taking attributes from ATTS, whose
   keys and values are both char *.  Allocate the entry and copy
   attributes into POOL as needed. */
static svn_error_t *
atts_to_entry(svn_wc_entry_t **new_entry,
              apr_hash_t *atts,
              apr_pool_t *pool)
{
    svn_wc_entry_t *entry = alloc_entry(pool);
    const char *name;

    /* Find the name and set up the entry under that name. */
    name = svn_hash_gets(atts, ENTRIES_ATTR_NAME);
    entry->name = name ? apr_pstrdup(pool, name) : SVN_WC_ENTRY_THIS_DIR;

    /* Attempt to set revision (resolve_to_defaults may do it later, too)

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *revision_str
            = svn_hash_gets(atts, ENTRIES_ATTR_REVISION);

        if (revision_str)
            entry->revision = SVN_STR_TO_REV(revision_str);
        else
            entry->revision = SVN_INVALID_REVNUM;
    }

    /* Attempt to set up url path (again, see resolve_to_defaults).

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->url = extract_string(atts, ENTRIES_ATTR_URL, pool);
    if (entry->url)
        entry->url = svn_uri_canonicalize(entry->url, pool);

    /* Set up repository root.  Make sure it is a prefix of url.

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->repos = extract_string(atts, ENTRIES_ATTR_REPOS, pool);
    if (entry->repos)
        entry->repos = svn_uri_canonicalize(entry->repos, pool);

    if (entry->url && entry->repos
            && !svn_uri__is_ancestor(entry->repos, entry->url))
        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
                                 _("Entry for '%s' has invalid repository "
                                   "root"),
                                 name ? name : SVN_WC_ENTRY_THIS_DIR);

    /* Set up kind. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *kindstr
            = svn_hash_gets(atts, ENTRIES_ATTR_KIND);

        entry->kind = svn_node_none;
        if (kindstr)
        {
            if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
                entry->kind = svn_node_file;
            else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
                entry->kind = svn_node_dir;
            else
                return svn_error_createf
                       (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
                        _("Entry '%s' has invalid node kind"),
                        (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
    }

    /* Look for a schedule attribute on this entry. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *schedulestr
            = svn_hash_gets(atts, ENTRIES_ATTR_SCHEDULE);

        entry->schedule = svn_wc_schedule_normal;
        if (schedulestr)
        {
            if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
                entry->schedule = svn_wc_schedule_add;
            else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
                entry->schedule = svn_wc_schedule_delete;
            else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
                entry->schedule = svn_wc_schedule_replace;
            else if (strcmp(schedulestr, "") == 0)
                entry->schedule = svn_wc_schedule_normal;
            else
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'schedule' value"),
                           (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
    }

    /* Is this entry in a state of mental torment (conflict)? */
    entry->prejfile = extract_string_normalize(atts,
                      ENTRIES_ATTR_PREJFILE,
                      pool);
    entry->conflict_old = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_OLD,
                          pool);
    entry->conflict_new = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_NEW,
                          pool);
    entry->conflict_wrk = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_WRK,
                          pool);

    /* Is this entry copied? */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->copied, atts, ENTRIES_ATTR_COPIED, name));

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->copyfrom_url = extract_string(atts, ENTRIES_ATTR_COPYFROM_URL, pool);

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *revstr;

        revstr = svn_hash_gets(atts, ENTRIES_ATTR_COPYFROM_REV);
        if (revstr)
            entry->copyfrom_rev = SVN_STR_TO_REV(revstr);
    }

    /* Is this entry deleted?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->deleted, atts, ENTRIES_ATTR_DELETED, name));

    /* Is this entry absent?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->absent, atts, ENTRIES_ATTR_ABSENT, name));

    /* Is this entry incomplete?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->incomplete, atts, ENTRIES_ATTR_INCOMPLETE,
                         name));

    /* Attempt to set up timestamps. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *text_timestr;

        text_timestr = svn_hash_gets(atts, ENTRIES_ATTR_TEXT_TIME);
        if (text_timestr)
            SVN_ERR(svn_time_from_cstring(&entry->text_time, text_timestr, pool));

        /* Note: we do not persist prop_time, so there is no need to attempt
           to parse a new prop_time value from the log. Certainly, on any
           recent working copy, there will not be a log record to alter
           the prop_time value. */
    }

    /* Checksum. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->checksum = extract_string(atts, ENTRIES_ATTR_CHECKSUM, pool);

    /* UUID.

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->uuid = extract_string(atts, ENTRIES_ATTR_UUID, pool);

    /* Setup last-committed values. */
    {
        const char *cmt_datestr, *cmt_revstr;

        cmt_datestr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_DATE);
        if (cmt_datestr)
        {
            SVN_ERR(svn_time_from_cstring(&entry->cmt_date, cmt_datestr, pool));
        }
        else
            entry->cmt_date = 0;

        cmt_revstr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_REV);
        if (cmt_revstr)
        {
            entry->cmt_rev = SVN_STR_TO_REV(cmt_revstr);
        }
        else
            entry->cmt_rev = SVN_INVALID_REVNUM;

        entry->cmt_author = extract_string(atts, ENTRIES_ATTR_CMT_AUTHOR, pool);
    }

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->lock_token = extract_string(atts, ENTRIES_ATTR_LOCK_TOKEN, pool);
    entry->lock_owner = extract_string(atts, ENTRIES_ATTR_LOCK_OWNER, pool);
    entry->lock_comment = extract_string(atts, ENTRIES_ATTR_LOCK_COMMENT, pool);
    {
        const char *cdate_str =
            svn_hash_gets(atts, ENTRIES_ATTR_LOCK_CREATION_DATE);
        if (cdate_str)
        {
            SVN_ERR(svn_time_from_cstring(&entry->lock_creation_date,
                                          cdate_str, pool));
        }
    }
    /* ----- end of lock handling.  */

    /* Note: if there are attributes for the (deprecated) has_props,
       has_prop_mods, cachable_props, or present_props, then we're just
       going to ignore them. */

    /* Translated size */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *val = svn_hash_gets(atts, ENTRIES_ATTR_WORKING_SIZE);
        if (val)
        {
            /* Cast to off_t; it's safe: we put in an off_t to start with... */
            entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
        }
    }

    *new_entry = entry;
    return SVN_NO_ERROR;
}
Example #11
0
/* Allocate an entry from POOL and read it from [*BUF, END).  The
   buffer may be modified in place while parsing.  Return the new
   entry in *NEW_ENTRY.  Advance *BUF to point at the end of the entry
   record.
   The entries file format should be provided in ENTRIES_FORMAT. */
static svn_error_t *
read_entry(svn_wc_entry_t **new_entry,
           char **buf, const char *end,
           int entries_format,
           apr_pool_t *pool)
{
    svn_wc_entry_t *entry = alloc_entry(pool);
    const char *name;

#define MAYBE_DONE if (**buf == '\f') goto done

    /* Find the name and set up the entry under that name. */
    SVN_ERR(read_path(&name, buf, end, pool));
    entry->name = name ? name : SVN_WC_ENTRY_THIS_DIR;

    /* Set up kind. */
    {
        const char *kindstr;
        SVN_ERR(read_val(&kindstr, buf, end));
        if (kindstr)
        {
            if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
                entry->kind = svn_node_file;
            else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
                entry->kind = svn_node_dir;
            else
                return svn_error_createf
                       (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
                        _("Entry '%s' has invalid node kind"),
                        (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
        else
            entry->kind = svn_node_none;
    }
    MAYBE_DONE;

    /* Attempt to set revision (resolve_to_defaults may do it later, too) */
    SVN_ERR(read_revnum(&entry->revision, buf, end, pool));
    MAYBE_DONE;

    /* Attempt to set up url path (again, see resolve_to_defaults). */
    SVN_ERR(read_url(&entry->url, buf, end, entries_format, pool));
    MAYBE_DONE;

    /* Set up repository root.  Make sure it is a prefix of url. */
    SVN_ERR(read_url(&entry->repos, buf, end, entries_format, pool));
    if (entry->repos && entry->url
            && ! svn_uri__is_ancestor(entry->repos, entry->url))
        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
                                 _("Entry for '%s' has invalid repository "
                                   "root"),
                                 name ? name : SVN_WC_ENTRY_THIS_DIR);
    MAYBE_DONE;

    /* Look for a schedule attribute on this entry. */
    {
        const char *schedulestr;
        SVN_ERR(read_val(&schedulestr, buf, end));
        entry->schedule = svn_wc_schedule_normal;
        if (schedulestr)
        {
            if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
                entry->schedule = svn_wc_schedule_add;
            else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
                entry->schedule = svn_wc_schedule_delete;
            else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
                entry->schedule = svn_wc_schedule_replace;
            else
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'schedule' value"),
                           name ? name : SVN_WC_ENTRY_THIS_DIR);
        }
    }
    MAYBE_DONE;

    /* Attempt to set up text timestamp. */
    SVN_ERR(read_time(&entry->text_time, buf, end, pool));
    MAYBE_DONE;

    /* Checksum. */
    SVN_ERR(read_str(&entry->checksum, buf, end, pool));
    MAYBE_DONE;

    /* Setup last-committed values. */
    SVN_ERR(read_time(&entry->cmt_date, buf, end, pool));
    MAYBE_DONE;

    SVN_ERR(read_revnum(&entry->cmt_rev, buf, end, pool));
    MAYBE_DONE;

    SVN_ERR(read_str(&entry->cmt_author, buf, end, pool));
    MAYBE_DONE;

    /* has-props, has-prop-mods, cachable-props, present-props are all
       deprecated. Read any values that may be in the 'entries' file, but
       discard them, and just put default values into the entry. */
    {
        const char *unused_value;

        /* has-props flag. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->has_props = FALSE;
        MAYBE_DONE;

        /* has-prop-mods flag. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->has_prop_mods = FALSE;
        MAYBE_DONE;

        /* Use the empty string for cachable_props, indicating that we no
           longer attempt to cache any properties. An empty string for
           present_props means that no cachable props are present. */

        /* cachable-props string. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->cachable_props = "";
        MAYBE_DONE;

        /* present-props string. */
        SVN_ERR(read_val(&unused_value, buf, end));
        entry->present_props = "";
        MAYBE_DONE;
    }

    /* Is this entry in a state of mental torment (conflict)? */
    {
        SVN_ERR(read_path(&entry->prejfile, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_old, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_new, buf, end, pool));
        MAYBE_DONE;
        SVN_ERR(read_path(&entry->conflict_wrk, buf, end, pool));
        MAYBE_DONE;
    }

    /* Is this entry copied? */
    SVN_ERR(read_bool(&entry->copied, ENTRIES_BOOL_COPIED, buf, end));
    MAYBE_DONE;

    SVN_ERR(read_url(&entry->copyfrom_url, buf, end, entries_format, pool));
    MAYBE_DONE;
    SVN_ERR(read_revnum(&entry->copyfrom_rev, buf, end, pool));
    MAYBE_DONE;

    /* Is this entry deleted? */
    SVN_ERR(read_bool(&entry->deleted, ENTRIES_BOOL_DELETED, buf, end));
    MAYBE_DONE;

    /* Is this entry absent? */
    SVN_ERR(read_bool(&entry->absent, ENTRIES_BOOL_ABSENT, buf, end));
    MAYBE_DONE;

    /* Is this entry incomplete? */
    SVN_ERR(read_bool(&entry->incomplete, ENTRIES_BOOL_INCOMPLETE, buf, end));
    MAYBE_DONE;

    /* UUID. */
    SVN_ERR(read_str(&entry->uuid, buf, end, pool));
    MAYBE_DONE;

    /* Lock token. */
    SVN_ERR(read_str(&entry->lock_token, buf, end, pool));
    MAYBE_DONE;

    /* Lock owner. */
    SVN_ERR(read_str(&entry->lock_owner, buf, end, pool));
    MAYBE_DONE;

    /* Lock comment. */
    SVN_ERR(read_str(&entry->lock_comment, buf, end, pool));
    MAYBE_DONE;

    /* Lock creation date. */
    SVN_ERR(read_time(&entry->lock_creation_date, buf, end, pool));
    MAYBE_DONE;

    /* Changelist. */
    SVN_ERR(read_str(&entry->changelist, buf, end, pool));
    MAYBE_DONE;

    /* Keep entry in working copy after deletion? */
    SVN_ERR(read_bool(&entry->keep_local, ENTRIES_BOOL_KEEP_LOCAL, buf, end));
    MAYBE_DONE;

    /* Translated size */
    {
        const char *val;

        /* read_val() returns NULL on an empty (e.g. default) entry line,
           and entry has already been initialized accordingly already */
        SVN_ERR(read_val(&val, buf, end));
        if (val)
            entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
    }
    MAYBE_DONE;

    /* Depth. */
    {
        const char *result;
        SVN_ERR(read_val(&result, buf, end));
        if (result)
        {
            svn_boolean_t invalid;
            svn_boolean_t is_this_dir;

            entry->depth = svn_depth_from_word(result);

            /* Verify the depth value:
               THIS_DIR should not have an excluded value and SUB_DIR should only
               have excluded value. Remember that infinity value is not stored and
               should not show up here. Otherwise, something bad may have
               happened. However, infinity value itself will always be okay. */
            is_this_dir = !name;
            /* '!=': XOR */
            invalid = is_this_dir != (entry->depth != svn_depth_exclude);
            if (entry->depth != svn_depth_infinity && invalid)
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'depth' value"),
                           name ? name : SVN_WC_ENTRY_THIS_DIR);
        }
        else
            entry->depth = svn_depth_infinity;

    }
    MAYBE_DONE;

    /* Tree conflict data. */
    SVN_ERR(read_str(&entry->tree_conflict_data, buf, end, pool));
    MAYBE_DONE;

    /* File external URL and revision. */
    {
        const char *str;
        SVN_ERR(read_str(&str, buf, end, pool));
        SVN_ERR(svn_wc__unserialize_file_external(&entry->file_external_path,
                &entry->file_external_peg_rev,
                &entry->file_external_rev,
                str,
                pool));
    }
    MAYBE_DONE;

done:
    *new_entry = entry;
    return SVN_NO_ERROR;
}