/*** qy_internal_ReadObject - reads an object, with its attributes (blobs
 *** limited to 255 bytes), and stores the data in the object-attr cache,
 *** or looks the object up there if it has already been cached.
 ***/
pQyObjAttr
qy_internal_ReadObject(char* path, pObjSession s)
    {
    pQyObjAttr objattr;
    pObject obj;
    char* attrname;
    int type;
    int ival;
    char* sval;

    	/** Check the cache first. **/
	objattr = (pQyObjAttr)xhLookup(&QY_INF.ObjAttrCache, path);
	if (objattr) 
	    {
	    objattr->CacheTime = time(NULL);
	    objattr->LinkCnt++;
	    return objattr;
	    }

	/** Otherwise, open the object & read its attrs. **/
	obj = objOpen(s, path, O_RDONLY, 0600, "system/file");
	if (!obj) return NULL;

	/** Allocate... **/
	objattr = (pQyObjAttr)nmMalloc(sizeof(QyObjAttr));
	if (!objattr)
	    {
	    objClose(obj);
	    return NULL;
	    }
	memccpy(objattr->ObjPathname,path,0,255);
	objattr->ObjPathname[255]=0;
	xsInit(&objattr->AttrNameBuf);
	xsInit(&objattr->AttrValueBuf);
	xaInit(&objattr->AttrNames,32);
	xaInit(&objattr->AttrValues,32);

	/** Loop through attributes. **/
	for(attrname=objGetFirstAttr(obj);attrname;attrname=objGetNextAttr(obj))
	    {
	    /** Copy attrname to names listing.  Be sure to copy the '\0'. **/
	    xaAddItem(&objattr->AttrNames, xsStringEnd(&objattr->AttrNameBuf));
	    xsConcatenate(&objattr->AttrNameBuf, attrname, strlen(attrname)+1);

	    /** Get type and copy to attrvalues. **/
	    type = objGetAttrType(obj,attrname);
	    switch(type)
	        {
		case DATA_T_INTEGER:
		    if (objGetAttrValue(obj,attrname,&ival) == 0)
		        {
		        xaAddItem(&objattr->AttrValues, xsStringEnd(&objattr->AttrValueBuf));
			xsConcatenate(&objattr->AttrValueBuf, (char*)&ival, 4);
			}
		    else
		        {
		        xaAddItem(&objattr->AttrValues, NULL);
			}
		    break;

		case DATA_T_STRING:
		    if (objGetAttrValue(obj,attrname,&sval) == 0)
		        {
		        xaAddItem(&objattr->AttrValues, xsStringEnd(&objattr->AttrValueBuf));
		        xsConcatenate(&objattr->AttrValueBuf,sval, strlen(sval)+1);
			}
		    else
		        {
		        xaAddItem(&objattr->AttrValues, NULL);
			}
		    break;

		default:
		    break;
		}
	    }

	/** Close up the object **/
	objClose(obj);

	/** Cache the objattr structure **/
	xhAdd(&QY_INF.ObjAttrCache, objattr->ObjPathname, (void*)objattr);
	xaAddItem(&QY_INF.ObjAttrCacheList, (void*)objattr);

    return objattr;
    }
Exemple #2
0
static INLINE char *put_string(const char *s, char *p, char *const e)
{
	const ptrdiff_t n = e - p;
	char *const c = (char *)memccpy(p, s, '\0', n);
	return 0 != c? c - 1: e;
}
/*
 * read a line of text
 *
 * return -1 on error or bytecount
 */
static int readline(char *buf,int max,struct stream_priv_s *ctl)
{
    int x,retval = 0;
    char *end,*bp=buf;
    int eof = 0;

    do {
      if (ctl->cavail > 0) {
	x = (max >= ctl->cavail) ? ctl->cavail : max-1;
	end = memccpy(bp,ctl->cget,'\n',x);
	if (end != NULL)
	  x = end - bp;
	retval += x;
	bp += x;
	*bp = '\0';
	max -= x;
	ctl->cget += x;
	ctl->cavail -= x;
	if (end != NULL) {
	  bp -= 2;
	  if (strcmp(bp,"\r\n") == 0) {
	    *bp++ = '\n';
	    *bp++ = '\0';
	    --retval;
	  }
	  break;
	}
      }
      if (max == 1) {
	*buf = '\0';
	break;
      }
      if (ctl->cput == ctl->cget) {
	ctl->cput = ctl->cget = ctl->buf;
	ctl->cavail = 0;
	ctl->cleft = BUFSIZE;
      }
      if(eof) {
	if (retval == 0)
	  retval = -1;
	break;
      }

      if(!fd_can_read(ctl->handle, 15)) {
        mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] read timed out\n");
        retval = -1;
        break;
      }

      if ((x = recv(ctl->handle,ctl->cput,ctl->cleft,0)) == -1) {
	mp_msg(MSGT_STREAM,MSGL_ERR, "[ftp] read error: %s\n",strerror(errno));
	retval = -1;
	break;
      }
      if (x == 0)
	eof = 1;
      ctl->cleft -= x;
      ctl->cavail += x;
      ctl->cput += x;
    } while (1);

    return retval;
}
Exemple #4
0
        current->next = new;
        current = new;
      }
      current->indent = indent;
      d = current->s;
      if( *s == '\t' || cont == 1 ) current->label = 0;
      else {
        current->label = strtol(s, &d2, 10);
        if( d2 != s ) p = d2, *xrp++ = current;
      }
      if( cont == 1 ) {
        current->indent += 2;
        if( !space ) *d++ = '&';
      }
    }
    p = (char *)memccpy(d, p + strspn(p, " \t"), 0, 256) - 2;
    while( p > s && (*p == ' ' || *p == '\t') ) --p;
    *++p = 0;
    if( *s == '*' || (*s | 0x20) == 'c' ) {
      *d = '!';
			/* this is a dirty hack to cure some problems
			   the DEC f90 compiler has with FF */
      if( strstr(s, "#] declarations") ) strcpy(p, "\ncontinue");
      continue;
    }
    for( p = s, d2 = d; *d2; ) *p++ = tolower(*d2++);
    *p = 0;
    if( strncmp(s, "include", 7) == 0 || strncmp(s, "#include", 8) == 0 ) {
      if( (p = strpbrk(d + 7, "'\"<")) && (d2 = strpbrk(++p, "'\">")) ) {
        ch = *d2;
        *d2 = 0;
// Parse packet text data
static void parsePacket(s_netData* netData, s_monitorData* monitorData)
{
	byte count = 0;
	char* token = strtok(packetData,CHAR_SPLIT);
	if(token != NULL && strcmp(token,CHAR_START2) == 0)
	{
		while(token != NULL)
		{
			switch(count)
			{
				case PACKET_POS_SYNCDOWN:
					netData->sync.down	= atoi(token);
					break;
				case PACKET_POS_SYNCUP:
					netData->sync.up	= atoi(token);
					break;
				case PACKET_POS_RATEDOWN:
					netData->rate.down	= atoi(token);
					break;
				case PACKET_POS_RATEUP:
					netData->rate.up	= atoi(token);
					break;
				case PACKET_POS_PING:
					netData->ping		= atoi(token);
					break;
				case PACKET_POS_LOSS:
					netData->loss		= atoi(token);
					break;
				case PACKET_POS_IP:
					memccpy(netData->ip, token, 0x00, 15);
					break;
				case PACKET_POS_EMAILS:
					monitorData->emails	= atoi(token);
					break;
				case PACKET_POS_DATE:
					memccpy(monitorData->time.date, token, 0x00, 13);
					break;
				case PACKET_POS_TIME:
					memccpy(monitorData->time.time, token, 0x00, 8);
					break;
				/*
				case PACKET_POS_DAY:
					memccpy(monitorData->time.day, token, 0x00, 3);
					break;
				case PACKET_POS_MONTH:
					memccpy(monitorData->time.month, token, 0x00, 3);
					break;
				case PACKET_POS_DATE:
					monitorData->time.date		= atoi(token);
					break;
				case PACKET_POS_YEAR:
					monitorData->time.year		= atoi(token);
					break;
				case PACKET_POS_HOUR:
					monitorData->time.hour		= atoi(token);
					break;
				case PACKET_POS_MIN:
					monitorData->time.minute	= atoi(token);
					break;
				case PACKET_POS_SEC:
					monitorData->time.seconds	= atoi(token);
					break;
				*/
				default:
					break;
			}
			++count;
			token = strtok(NULL,CHAR_SPLIT);
		}
	}
}