Exemple #1
0
int checkIdentifier(char* identifier, char* rootdir) {
	/* Cosa fare nel caso in cui l'identificatore non esiste sul server?
	In questa prima implementazione, si esce, avvisando l'utente. */

	int returnCode = ALLOK;

	if (strlen(identifier) != IDENTIFIER_LEN) {
		log_err("Bad identifier len: %s", identifier);
		return BAD_IDENTIFIER;
	}

	int i = 0;
	for (i = 0; i < strlen(identifier); ++i) {
		char currentChar = identifier[i];
		if (currentChar < 48 ||
		    (currentChar > 90 && currentChar < 97) ||
		    currentChar > 122) {
			return BAD_IDENTIFIER;
		}
	}

	char* identifierPath = createFullPath(rootdir, identifier);
	char* identifierFolderPath = createFullPath(identifierPath, PLACEHOLDER);

	if (checkFolderExists(identifierFolderPath) != 1) {
		log_err("Error opening identifier directory: %s", identifier);
		returnCode = BAD_IDENTIFIER;
	}

	free(identifierPath);
	free(identifierFolderPath);

	return returnCode;
}
Exemple #2
0
FRESULT f_unlink (
   const XCHAR *path    /* Pointer to the file or directory path */
)
{
   FRESULT ret = FR_OK;
   const char* target= createFullPath(path);

   if (-1 == stat(target, &stats))
   {
      return cvtERRNO();
   }

   if (stats.st_mode & S_IFDIR)
   {
      if (_rmdir(target) == -1)
      {
         ret = FR_DENIED;
      }
   }
   else
   {
      // a concatenation of the mmc dir & the requested path
      if (_unlink(target) == -1)
      {
         ret = cvtERRNO();
      }
   }

   return ret;
}
Exemple #3
0
FRESULT f_opendir (
   DIR *dj,       /* Pointer to directory object to create */
   const XCHAR *path /* Pointer to the directory path */
)
{
   return (FRESULT)dirOpen(createFullPath(path));
}
Exemple #4
0
FRESULT f_rename (
   const XCHAR *path1,    /* Pointer to the file or directory path */
   const XCHAR *path2    /* Pointer to the file or directory path */
)
{
   FRESULT ret = FR_OK;

   char tmpp[32768];
   createFullPath(path1);
   strcpy(tmpp, tempPath);

   // a concatenation of the mmc dir & the requested path
   if (rename(tmpp, createFullPath(path2)))
   {
      ret = cvtERRNO();
   }

   return ret;
}
Exemple #5
0
FRESULT f_mkdir (const XCHAR* dirname)
{
   FRESULT ret = FR_OK;

   if (_mkdir(createFullPath(dirname)) == -1)
   {
      ret = cvtERRNO();
   }

   return ret;
}
Exemple #6
0
int deletefd(char* identifierPath, char* path) {
	/* Questa funzione rimuove un file o una cartella (soltanto se vuota) */

	char* fullPath = createFullPath(identifierPath, path);
	int returnCode = ALLOK;

	SEMAPHORE_TYPE pathSemaphore = getPathSemaphore(fullPath, sharedMemory);

	#ifndef _WIN32
		if (sem_Trywait(pathSemaphore) == EAGAIN) {
			returnCode = TEMP_UNAVAIBLE;
		} else {
			if (remove(fullPath) != 0)	{
				log_err("Error while removing file or directory.");
				returnCode = parseErrno(errno);
			}

			sem_Post(pathSemaphore);
		}
		sem_Close(pathSemaphore);
	#else
		if (TRYWaitForSingleObject(pathSemaphore) == WAIT_TIMEOUT) {
			returnCode = TEMP_UNAVAIBLE;
		} else {
			DWORD ftype = GetFileAttributes(fullPath);

			if (ftype == INVALID_FILE_ATTRIBUTES) {  // path invalido
				returnCode = INVALID_PATH;
			} else if (ftype == FILE_ATTRIBUTE_DIRECTORY ) {  // directory
				if (_rmdir(fullPath) != 0)	{
					log_err("Error while removing file or directory.");
					returnCode = parseErrno(errno);
				}
			} else {
				if (remove(fullPath) != 0)	{
					log_err("Error while removing file or directory.");
					returnCode = parseErrno(errno);
				}
			}
			RELEASESemaphore(pathSemaphore);
		}

		CLOSEHandle(pathSemaphore);
	#endif

	free(fullPath);
	return returnCode;
}
ossimRefPtr<ossimElevCellHandler> ossimDtedElevationDatabase::createCell(const ossimGpt& gpt)
{
  ossimRefPtr<ossimElevCellHandler> result = 0;
  ossimFilename f;
  createFullPath(f, gpt);
  if(f.exists())
  {
     ossimRefPtr<ossimDtedHandler> h = new ossimDtedHandler(f, m_memoryMapCellsFlag);
     if (!(h->getErrorStatus()))
     {
        result = h.get();
     }
  }

  return result;
}
Exemple #8
0
FRESULT f_open (
   FIL *fp,       /* Pointer to the blank file object */
   const XCHAR *path,   /* Pointer to the file name */
   BYTE mode         /* Access mode and file open mode flags */
)
{
   if (GetHandle(fp) != 0)
   {
      _close(GetHandle(fp));
      SetHandle(fp, 0);
   }

   int flags = _O_BINARY;
   if (mode & FA_WRITE)
   {
      flags |= _O_CREAT | _O_TRUNC | _O_RDWR;
      if (mode & FA_CREATE_NEW)
      {
         // fail if exists
         flags |= _O_EXCL;
      }
   }

   // use stat(name,...) instead of fstat(handle,...)
   
   const char* fullNme = createFullPath(path);
   int handle = _open(fullNme, flags);
   if (-1 == handle)
   {
      return cvtERRNO();
   }

   if (-1 == stat(fullNme, &stats))
   {
      _close(handle);
      return cvtERRNO();
   }

   fp->fsize = stats.st_size;
   fp->flag = 0;

   loadFileSymbolsProxy(fullNme);

   SetHandle(fp, handle);
   return FR_OK;
}
ossimRefPtr<ossimElevCellHandler>
ossimSrtmElevationDatabase::createCell(const ossimGpt& gpt)
{

  ossimRefPtr<ossimElevCellHandler> result = 0;
  ossimFilename f;
  createFullPath(f, gpt);

  if(f.exists())
  {
     ossimRefPtr<ossimSrtmHandler> h = new ossimSrtmHandler();
     if (h->open(f, m_memoryMapCellsFlag))
     {
        result = h.get();
     }
  }

  return result;
}
Exemple #10
0
int executeServerCommand(int msfd, struct url *url, struct config *cfg) {
	/* In base al comando inserito, viene chiamata la rispettiva funzione. */

	// Si controlla l'esistenza dell'identificativo e si cambia directory.
	int returnCode = checkIdentifier(url->identifier, cfg->rootdir);

	if (returnCode != BAD_IDENTIFIER) {
		char* identifierPath = createFullPath(cfg->rootdir, url->identifier);
		char* command = url->command;

		if (strcmp(command, "mkdir") == 0) {
			returnCode = makeDir(identifierPath, url->argument);
		} else if (strcmp(command, "put") == 0) {
			returnCode = putf(msfd, identifierPath, url->argument, url->optionalArgument, "wb");
		} else if (strcmp(command, "puta") == 0) {
			returnCode = putf(msfd, identifierPath, url->argument, url->optionalArgument, "ab");
		} else if (strcmp(command, "move") == 0) {
			returnCode = movefd(identifierPath, url->argument, url->optionalArgument);
		} else if (strcmp(command, "dele") == 0) {
			returnCode = deletefd(identifierPath, url->argument);
		} else if (strcmp(command, "get") == 0) {
			returnCode = getf(msfd, identifierPath, url->argument);
		} else {
			log_err("Unknown_command");
			returnCode = MALFORMED_COMMAND;
		}

		free(identifierPath);
	} else {
		if (strcmp(url->command, "get") == 0) {
			/* Se l'identificativo non è valido, bisogna comunque
			avvertire il client che non sta per ricevere alcun file. */
			sendEntireFile(msfd, NULL);
		} else if (strcmp(url->command, "put") == 0 || strcmp(url->command, "puta") == 0) {
			/* E allo stesso modo devo avvertire il client, nel caso in cui
			lui voglia effettuare un put ma l'identificativo è errato. */
			sendReturnCode(msfd, returnCode);
		}
	}

	log_info("Return code: %d", returnCode);
	return returnCode;
}
Exemple #11
0
int makeDir(char* identifierPath, char* path) {
	/* Questa funzione crea la directory, se il path esiste. */

	char* fullPath = createFullPath(identifierPath, path);
	int returnCode = ALLOK;

	SEMAPHORE_TYPE pathSemaphore = getPathSemaphore(fullPath, sharedMemory);

	#ifndef _WIN32
		int n;
		if ((n = sem_Trywait(pathSemaphore)) == EAGAIN) {
			returnCode = TEMP_UNAVAIBLE;
		} else {
			if (mkdir(fullPath, 0755) != 0) {
				log_err("Error while making new directory.");
				returnCode = parseErrno(errno);
			}

			sem_Post(pathSemaphore);
		}
		sem_Close(pathSemaphore);
	#else
		if (TRYWaitForSingleObject(pathSemaphore) == WAIT_TIMEOUT) {
			returnCode = TEMP_UNAVAIBLE;
		} else {
			if (mkdir(fullPath) != 0) {
				log_err("Error while making new directory.");
				returnCode = parseErrno(errno);
			}

			RELEASESemaphore(pathSemaphore);
		}
		CLOSEHandle(pathSemaphore);
	#endif

	free(fullPath);
	return returnCode;
}
Exemple #12
0
			}
			RELEASESemaphore(pathSemaphore);
		}

		CLOSEHandle(pathSemaphore);
	#endif

	free(fullPath);
	return returnCode;
}

int movefd(char* identifierPath, char* old, char* new) {
	/* Questa funzione sposta/rinomina un file o una cartella */
	int returnCode = ALLOK;

	char* oldFullPath = createFullPath(identifierPath, old);
	char* newFullPath = createFullPath(identifierPath, new);

	#ifndef _WIN32
		sem_t *moveSemaphore = sem_Open(SEMAPHORE_MOVE, 0);
		sem_Wait(moveSemaphore);
	#else
		HANDLE moveSemaphore = OPENSemaphore(SEMAPHORE_FLAGS, FALSE, SEMAPHORE_MOVE);
		WAITForSingleObjectInfinite(moveSemaphore);
	#endif

	SEMAPHORE_TYPE oldPathSemaphore = getPathSemaphore(oldFullPath, sharedMemory);
	SEMAPHORE_TYPE newPathSemaphore = getPathSemaphore(newFullPath, sharedMemory);

	#ifndef _WIN32
		if (sem_Trywait(oldPathSemaphore) == EAGAIN ||