Ejemplo n.º 1
0
/*======================================================================
----------------------------------------------------------------------*/
static BOOL PathEmpty(CHAR *path)
   {
   BOOL result;
   EVENT info;

   ASSERT(path != NULL);

   /* Look for any files... */
   result = TRUE;
   sprintf(info.filespec, "%s/*", path);
   info.attribute = FIND_FILE;
   if (FileFindFirst(&info))
      result = FALSE;
   FileFindClose(&info);

   if (!result)
      return result;

   /* or subdirectories... */
   result = TRUE;
   sprintf(info.filespec, "%s/*", path);
   info.attribute = FIND_SUBDIR;
   if (FileFindFirst(&info))
      {
      do
         {
         if (info.filespec[0] != '.')
            {
            result = FALSE;
            break;
            }
         }
      while (FileFindNext(&info));
      }
   FileFindClose(&info);

   return result;
   }  /* end PathEmpty() */
Ejemplo n.º 2
0
static void
generateListing(TList *       const listP,
                char *        const z,
                const char *  const uri,
                TPool *       const poolP,
                const char ** const errorP,
                uint16_t *    const responseStatusP) {
    
    TFileInfo fileinfo;
    TFileFind findhandle;

    *errorP = NULL;

    if (!FileFindFirst(&findhandle, z, &fileinfo)) {
        *responseStatusP = ResponseStatusFromErrno(errno);
        xmlrpc_asprintf(errorP, "Can't read first entry in directory");
    } else {
        ListInit(listP);

        do {
            TFileInfo * fi;
            /* Files whose names start with a dot are ignored */
            /* This includes implicitly the ./ and ../ */
            if (*fileinfo.name == '.') {
                if (xmlrpc_streq(fileinfo.name, "..")) {
                    if (xmlrpc_streq(uri, "/"))
                        continue;
                } else
                    continue;
            }
            fi = (TFileInfo *)PoolAlloc(poolP, sizeof(fileinfo));
            if (fi) {
                abyss_bool success;
                memcpy(fi, &fileinfo, sizeof(fileinfo));
                success =  ListAdd(listP, fi);
                if (!success)
                    xmlrpc_asprintf(errorP, "ListAdd() failed");
            } else
                xmlrpc_asprintf(errorP, "PoolAlloc() failed.");
        } while (!*errorP && FileFindNext(&findhandle, &fileinfo));

        if (*errorP) {
            *responseStatusP = 500;
            ListFree(listP);
        }            
        FileFindClose(&findhandle);
    }
}
Ejemplo n.º 3
0
/*======================================================================
----------------------------------------------------------------------*/
static YD_NODE *GetYDList(H_ARCHIVE harchive,  STREAM *criteria)
	{
	EVENT info;
   YD_NODE *head = NULL;
   YD_NODE *tail = NULL;
   YD_NODE *cur,*new_node;
   int	year;
   int	day;

   InitEvent(&info);

   if (!ValidateHandle(harchive))
      {
      ArchiveLog(ARC_LOG_ERRORS, "GetYDList: ValidateHandle failed");
      return (NULL);
      }
   
	/* Look at all day directories and store them */
	sprintf(info.filespec, "%s%c*", _archive[harchive].path, PATH_DELIMITER);
	info.attribute = FIND_SUBDIR;
	if (FileFindFirst(&info)) 
		{
		do 
			{
		   /* Ignore . and .. and insist on right length! */
		   if (info.filespec[0] == '.' || strlen(info.filespec) != 7) 
		   	{
		      continue;
		   	}

		   /* Decode year and doy */
			sscanf(info.filespec, "%4d%3d", &year, &day);
		   /* Set hour, minute, and second to zeros */
		   info.yd = EncodeMSTimeDOY((INT32) year, (INT32) day, 0, 0, 0.0);
		
		   /* If earliest is specified and time is less, go around */
		   if (!UndefinedTime(criteria->time.earliest) &&
		       CompareYD(info.yd, criteria->time.earliest) < 0) 
		   	{
		      continue;
		   	}
		
		   /* If latest is specified and time is greater, go around */
		   if (!UndefinedTime(criteria->time.latest) &&
		       CompareYD(info.yd, criteria->time.latest) > 0) 
		   	{
		      continue;
		   	}
		
		   /* Otherwise, we'll save this year & day, inserting it in ordered list*/
		  	if (head == NULL)	/* if first directory, then start list*/
		  		{
		  		head = (YD_NODE*) malloc(sizeof(YD_NODE));
	  			if (head == NULL)
		  				break;
		  		tail = head;
		  		head->yd = info.yd;
				head->year = year;
				head->day = day;
				head->next = NULL;
		  		}
		  	else						/* find place to insert data */
		  		{
		  		cur = NULL;
		  		if (CompareYD(info.yd, head->yd) <= 0)
		  			{
		  			cur = (YD_NODE*) malloc(sizeof(YD_NODE));
		  			if (cur == NULL)
		  				break;
		  			cur->next = head;
					head = cur;
		  			}
		  		else if (CompareYD(info.yd, tail->yd) >= 0)
		  			{
		  			cur = (YD_NODE*) malloc(sizeof(YD_NODE));
		  			if (cur == NULL)
		  				break;
		  			tail->next = cur;
					cur->next = NULL;
					tail = cur;
		  			}
		  		else
		  			{
		  			for (cur = head; ; cur = cur->next)
		  				{
		  				if (cur->next == NULL)/*we already checked the tail*/
							break;
						if ((CompareYD(info.yd, cur->yd) >= 0) &&
					  	 (CompareYD(info.yd, cur->next->yd) <= 0))
							{
							new_node = (YD_NODE*) malloc(sizeof(YD_NODE));
			  				if (new_node == NULL)
			  					{
			  					cur = NULL;
			  					break;
			  					}
							new_node->next = cur->next;
							cur->next = new_node;
							cur = new_node;
							break;
							}
		  				}
		  			}
		  		/* If no memory to build list quit*/
		  		if (cur != NULL)
		  			{
		  			cur->yd = info.yd;
					cur->year = year;
					cur->day = day;
					}
				else
					{
					break;
					}
		  		}/*end else insert in list*/
			} while (FileFindNext(&info));
		}/* end if found first */
		FileFindClose(&info);
		return(head);
	}  /* end get_yd_list */