- changed server side getFileDirectory service to return flat file directory

pull/6/head
Michael Zillgith 10 years ago
parent 758615a3f8
commit 2daa5fdec4

@ -1,5 +1,7 @@
Changes to version 0.8.7 Changes to version 0.8.7
------------------------ ------------------------
- extended beoglebone demo (write access to GAPC settings, ...)
- File service: support for wildcard character ('*') in requests
- server: changed signature of WriteAccessHandler: Handler now return MmsDataAccessError instead of boolean value! - server: changed signature of WriteAccessHandler: Handler now return MmsDataAccessError instead of boolean value!
- server: added function IedModel_setIedNameForDynamicModel - server: added function IedModel_setIedNameForDynamicModel

@ -201,7 +201,7 @@ prepareGooseBuffer(GoosePublisher self, CommParameters* parameters, const char*
int bufPos = 12; int bufPos = 12;
#if 0 #if 1
/* Priority tag - IEEE 802.1Q */ /* Priority tag - IEEE 802.1Q */
self->buffer[bufPos++] = 0x81; self->buffer[bufPos++] = 0x81;
self->buffer[bufPos++] = 0x00; self->buffer[bufPos++] = 0x00;

@ -123,7 +123,7 @@ FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModific
{ {
struct stat fileStats; struct stat fileStats;
char fullPath[sizeof(CONFIG_VIRTUAL_FILESTORE_BASEPATH) + 255]; char fullPath[sizeof(CONFIG_VIRTUAL_FILESTORE_BASEPATH) + 256];
createFullPathFromFileName(fullPath, filename); createFullPathFromFileName(fullPath, filename);

@ -96,7 +96,7 @@ FileSystem_closeFile(FileHandle handle)
bool bool
FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp) FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp)
{ {
char fullPath[sizeof(CONFIG_VIRTUAL_FILESTORE_BASEPATH) + 255]; char fullPath[sizeof(CONFIG_VIRTUAL_FILESTORE_BASEPATH) + 256];
createFullPathFromFileName(fullPath, filename); createFullPathFromFileName(fullPath, filename);

@ -133,6 +133,10 @@ FileSystem_openDirectory(char* directoryName);
/** /**
* \brief read the next directory entry * \brief read the next directory entry
* *
* This function returns the next directory entry. The entry is only a valid pointer as long as the
* FileSystem_closeDirectory or another FileSystem_readDirectory function is not called for the given
* DirectoryHandle.
*
* \param directory the handle to identify the directory * \param directory the handle to identify the directory
* \param isDirectory return value that indicates if the directory entry is itself a directory (true) * \param isDirectory return value that indicates if the directory entry is itself a directory (true)
* *

@ -214,11 +214,11 @@ mmsServer_handleFileDeleteRequest(
filename[length] = 0; filename[length] = 0;
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("mms_file_service.c: Delete file (%s)\n", filename); printf("MMS_SERVER: mms_file_service.c: Delete file (%s)\n", filename);
if (!FileSystem_getFileInfo(filename, NULL, NULL)) { if (!FileSystem_getFileInfo(filename, NULL, NULL)) {
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("mms_file_service.c: File (%s) not found\n", filename); printf("MMS_SERVER: mms_file_service.c: File (%s) not found\n", filename);
mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_NON_EXISTENT); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_NON_EXISTENT);
return; return;
@ -226,7 +226,7 @@ mmsServer_handleFileDeleteRequest(
if (!FileSystem_deleteFile(filename)) { if (!FileSystem_deleteFile(filename)) {
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("mms_file_service.c: Delete file (%s) failed\n", filename); printf("MMS_SERVER: mms_file_service.c: Delete file (%s) failed\n", filename);
mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_ACCESS_DENIED); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_ACCESS_DENIED);
return; return;
@ -381,7 +381,7 @@ mmsServer_handleFileReadRequest(
int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos); int32_t frsmId = (int32_t) BerDecoder_decodeUint32(buffer, maxBufPos - bufPos, bufPos);
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("mmsServer_handleFileReadRequest read request for frsmId: %i\n", frsmId); printf("MMS_SERVER: mmsServer_handleFileReadRequest read request for frsmId: %i\n", frsmId);
MmsFileReadStateMachine* frsm = getFrsm(connection, frsmId); MmsFileReadStateMachine* frsm = getFrsm(connection, frsmId);
@ -436,70 +436,42 @@ encodeFileSpecification(uint8_t tag, char* fileSpecification, uint8_t* buffer, i
} }
} }
static int
addFileEntriesToResponse(uint8_t* buffer, int bufPos, int maxBufSize, char* directoryName, char* continueAfterFileName, bool* moreFollows)
static void
createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* directoryName, char* continueAfterFileName)
{ {
int maxSize = response->maxSize - 3; /* reserve space for moreFollows */ int directoryNameLength = strlen(directoryName);
uint8_t* buffer = response->buffer;
bool moreFollows = false;
int tempStartPos = 30; /* estimated header part with safety margin */
int tempCurPos = tempStartPos;
int tempEncoded = 0;
char extendedFileName[300];
DirectoryHandle directory = FileSystem_openDirectory(directoryName); DirectoryHandle directory = FileSystem_openDirectory(directoryName);
if (continueAfterFileName != NULL) {
if (strlen(continueAfterFileName) == 0)
continueAfterFileName = NULL;
}
if (directory != NULL) { if (directory != NULL) {
bool isDirectory; bool isDirectory;
char* fileName = FileSystem_readDirectory(directory, &isDirectory); char* fileName = FileSystem_readDirectory(directory, &isDirectory);
while (fileName != NULL) { while (fileName != NULL) {
directoryName[directoryNameLength] = 0;
if (directoryNameLength > 0)
strcat(directoryName, "/");
strcat(directoryName, fileName);
if (isDirectory) { if (isDirectory) {
strcpy(extendedFileName, fileName); bufPos = addFileEntriesToResponse(buffer, bufPos, maxBufSize, directoryName, continueAfterFileName, moreFollows);
strcat(extendedFileName, "/");
fileName = extendedFileName; if (*moreFollows == true)
break;
} }
else {
if (continueAfterFileName != NULL) { if (continueAfterFileName != NULL) {
if (strcmp(continueAfterFileName, fileName) == 0) if (strcmp(continueAfterFileName, directoryName) == 0)
continueAfterFileName = NULL; continueAfterFileName = NULL;
} }
else { else {
uint64_t msTime; uint64_t msTime;
char fullPath[CONFIG_MMS_FILE_SERVICE_MAX_FILENAME_LENGTH];
if (directoryName != NULL) {
int directoryLen = strlen(directoryName);
strcpy(fullPath, directoryName);
if (directoryName[directoryLen - 1] != CONFIG_SYSTEM_FILE_SEPARATOR) {
fullPath[directoryLen] = CONFIG_SYSTEM_FILE_SEPARATOR;
fullPath[directoryLen + 1] = 0;
}
strcat(fullPath, fileName);
}
else {
strncpy(fullPath, fileName, CONFIG_MMS_FILE_SERVICE_MAX_FILENAME_LENGTH - 1);
fullPath[CONFIG_MMS_FILE_SERVICE_MAX_FILENAME_LENGTH - 1] = 0;
}
uint32_t fileSize; uint32_t fileSize;
FileSystem_getFileInfo(fullPath, &fileSize, &msTime); FileSystem_getFileInfo(directoryName, &fileSize, &msTime);
char gtString[30]; char gtString[30];
@ -507,36 +479,63 @@ createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* direc
int fileAttributesSize = encodeFileAttributes(0xa1, fileSize, gtString, NULL, 0); int fileAttributesSize = encodeFileAttributes(0xa1, fileSize, gtString, NULL, 0);
int filenameSize = encodeFileSpecification(0xa0, fileName, NULL, 0); int filenameSize = encodeFileSpecification(0xa0, directoryName, NULL, 0);
int dirEntrySize = 2 + fileAttributesSize + filenameSize; int dirEntrySize = 2 + fileAttributesSize + filenameSize;
int overallEntrySize = 1 + BerEncoder_determineLengthSize(dirEntrySize) + dirEntrySize; int overallEntrySize = 1 + BerEncoder_determineLengthSize(dirEntrySize) + dirEntrySize;
int bufferSpaceLeft = maxSize - tempCurPos; int bufferSpaceLeft = maxBufSize - bufPos;
if (overallEntrySize > bufferSpaceLeft) { if (overallEntrySize > bufferSpaceLeft) {
moreFollows = true;
*moreFollows = true;
break; break;
} }
tempCurPos = BerEncoder_encodeTL(0x30, dirEntrySize, buffer, tempCurPos); /* SEQUENCE (DirectoryEntry) */ bufPos = BerEncoder_encodeTL(0x30, dirEntrySize, buffer, bufPos); /* SEQUENCE (DirectoryEntry) */
tempCurPos = encodeFileSpecification(0xa0, fileName, buffer, tempCurPos); /* fileName */ bufPos = encodeFileSpecification(0xa0, directoryName, buffer, bufPos); /* fileName */
tempCurPos = encodeFileAttributes(0xa1, fileSize, gtString, buffer, tempCurPos); /* file attributes */ bufPos = encodeFileAttributes(0xa1, fileSize, gtString, buffer, bufPos); /* file attributes */
} }
}
fileName = FileSystem_readDirectory(directory, &isDirectory); fileName = FileSystem_readDirectory(directory, &isDirectory);
} }
FileSystem_closeDirectory(directory); FileSystem_closeDirectory(directory);
} }
else {
//TODO check if it is a directory directoryName[directoryNameLength] = 0;
return bufPos;
}
static void
createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* directoryName, char* continueAfterFileName)
{
int maxSize = response->maxSize - 3; /* reserve space for moreFollows */
uint8_t* buffer = response->buffer;
bool moreFollows = false;
int tempStartPos = 30; /* estimated header part with safety margin */
int tempCurPos = tempStartPos;
int tempEncoded = 0;
if (continueAfterFileName != NULL) {
if (strlen(continueAfterFileName) == 0)
continueAfterFileName = NULL;
}
tempCurPos = addFileEntriesToResponse(buffer, tempCurPos, maxSize, directoryName, continueAfterFileName, &moreFollows);
if (tempCurPos < 0) {
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("Error opening directory!\n"); printf("MMS_SERVER: Error opening directory!\n");
mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_NON_EXISTENT); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_FILE_NON_EXISTENT);
@ -611,7 +610,7 @@ mmsServer_handleFileRenameRequest(
return; return;
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("currentFileName: (%s)\n", currentFileName); printf("MMS_SERVER: currentFileName: (%s)\n", currentFileName);
break; break;
@ -620,12 +619,12 @@ mmsServer_handleFileRenameRequest(
return; return;
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("newFileName: (%s)\n", newFileName); printf("MMS_SERVER: newFileName: (%s)\n", newFileName);
break; break;
default: /* ignore unknown tag */ default: /* ignore unknown tag */
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("unknown tag: (%02x)\n", tag); printf("MMS_SERVER: unknown tag: (%02x)\n", tag);
bufPos += length; bufPos += length;
break; break;
@ -640,7 +639,7 @@ mmsServer_handleFileRenameRequest(
else else
{ {
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("rename file failed!\n"); printf("MMS_SERVER: rename file failed!\n");
mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_OTHER); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_FILE_OTHER);
} }
@ -658,7 +657,7 @@ mmsServer_handleFileDirectoryRequest(
ByteBuffer* response) ByteBuffer* response)
{ {
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("handleFileDirectoryRequest bufPos:%i, maxBufPus:%i\n", bufPos, maxBufPos); printf("MMS_SERVER: handleFileDirectoryRequest bufPos:%i, maxBufPus:%i\n", bufPos, maxBufPos);
char filename[256] = ""; char filename[256] = "";
@ -683,7 +682,8 @@ mmsServer_handleFileDirectoryRequest(
return; return;
/* check for wildcard character(*) */ /* check for wildcard character(*) */
if (strcmp(filename, "*") == 0) filename[0] = 0; if ((strcmp(filename, "*") == 0) || (strcmp(filename, "/") == 0) || (strcmp(filename, "\\") == 0))
filename[0] = 0;
break; break;
@ -697,7 +697,7 @@ mmsServer_handleFileDirectoryRequest(
default: /* unrecognized parameter */ default: /* unrecognized parameter */
if (DEBUG_MMS_SERVER) if (DEBUG_MMS_SERVER)
printf("handleFileDirectoryRequest: unrecognized parameter\n"); printf("MMS_SERVER: handleFileDirectoryRequest: unrecognized parameter\n");
mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return; return;
} }

Loading…
Cancel
Save