42 #ifdef HFS_DEBUG_PRINT 43 #define PRINT(x) TRACE(TFILE,x) 49 #define MAX_HFS_TABLES 6 68 static HfsTable hfsTables[MAX_HFS_TABLES];
69 static HfsTable *hfsTable = &hfsTables[0];
72 { 2, (MHEG5Byte *)
"//" },
73 { 6, (MHEG5Byte *)
"DSM://" },
78 static void ClearMappingTable(
void);
79 static void PushMappingTable(
void);
80 static void PopMappingTable(
void);
81 static void ReleaseMapping(
HfsMapping *mapping);
83 static void RemoveMapping(
HfsMapping **pMapping);
87 static void InsertMapping(
HfsMapping *newMapping);
90 static MHEG5Bool IsDefaultMapping(
HfsMapping *mapping);
91 static MHEG5Bool IsValidReference(
MHEG5String *reference);
94 #ifdef HFS_DEBUG_TABLE 95 static void PrintMappingTable(
void);
120 while (hfsTable != hfsTables)
157 TRACE(TFILE,(
"(\"%.*s\",\"%.*s\")",
158 (
int)pathName->len, (
char *)pathName->data,
159 (
int)mappingList->len, (
char *)mappingList->data));
161 if (pathName->len > 0)
163 pMapping = FindMapping(pathName);
164 if (pMapping != NULL)
166 if (mappingList->len == 0)
168 RemoveMapping(pMapping);
172 newMapping = CreateMapping(pathName, mappingList);
173 if (newMapping != NULL)
175 ReplaceMapping(pMapping, newMapping);
181 if (mappingList->len != 0)
183 newMapping = CreateMapping(pathName, mappingList);
184 if (newMapping != NULL)
186 InsertMapping(newMapping);
199 #ifdef HFS_DEBUG_TABLE 220 if (IsValidReference(reference))
222 currentMapping = hfsTable->anchor;
223 while (currentMapping != NULL)
225 pathName = currentMapping->pathName;
226 if (longest < pathName.len)
228 if (pathName.data[pathName.len - 1] ==
'/')
231 if (pathName.len < reference->len &&
232 memcmp(pathName.data, reference->data, pathName.len) == 0)
234 longest = pathName.len;
235 mapping = currentMapping;
241 if (pathName.len == reference->len &&
242 memcmp(pathName.data, reference->data, pathName.len) == 0)
244 longest = pathName.len;
245 mapping = currentMapping;
249 currentMapping = currentMapping->next;
253 TRACE(TFILE,(
"path=%.*s mapping=%.*s",
254 (
int)mapping->pathName.len, mapping->pathName.data,
255 (
int)mapping->mappingList.len, mapping->mappingList.data));
272 assert(handle != NULL);
274 ReleaseMapping(handle);
285 assert(iter != NULL);
286 assert(mapping != NULL);
288 iter->mapping = mapping;
289 iter->currentPos = 0;
309 assert(iter != NULL);
311 mapping = iter->mapping;
312 if (iter->currentPos == mapping->mappingList.len)
316 reference.data = NULL;
317 TRACE(TFILE,(
"END"));
322 data = mapping->mappingList.data + iter->currentPos;
323 limit = mapping->mappingList.len - iter->currentPos;
325 while (len < limit && data[len] !=
' ')
330 if (data[len - 1] ==
'/')
333 reference.data = STR_DataAlloc(len + ref->len -
334 mapping->pathName.len);
335 if (reference.data != NULL)
337 memcpy(reference.data, data, len);
338 reference.len += len;
339 memcpy(reference.data + reference.len,
340 ref->data + mapping->pathName.len,
341 ref->len - mapping->pathName.len);
342 reference.len += ref->len - mapping->pathName.len;
343 reference.data[reference.len] =
'\0';
349 reference.data = STR_DataAlloc(len);
350 if (reference.data != NULL)
352 memcpy(reference.data, data, len);
353 reference.data[len] =
'\0';
358 iter->currentPos += len;
359 if (iter->currentPos < mapping->mappingList.len)
364 TRACE(TFILE,(
"reference=%.*s",(
int)reference.len, reference.data));
394 if (origin == ORIGIN_HYBRID)
396 input.data = (U8BIT *)path.data + 7;
397 input.len = path.len - 7;
401 while (output.len != 0)
403 if (output.len >= 6 && memcmp(output.data,
"DSM://", 6) == 0)
412 else if (origin == ORIGIN_DSM)
429 static void ClearMappingTable(
void)
434 mapping = hfsTable->anchor;
435 while (mapping != NULL)
437 hfsTable->anchor = mapping->next;
438 ReleaseMapping(mapping);
439 mapping = hfsTable->anchor;
443 hfsTable->anchor = &defaultMapping;
445 #ifdef HFS_DEBUG_TABLE 455 static void PushMappingTable(
void)
460 assert(newTable - hfsTables < MAX_HFS_TABLES);
461 assert(newTable->anchor == NULL ||
462 newTable->anchor == &defaultMapping);
465 curr = hfsTable->anchor;
466 new = &newTable->anchor;
469 (*new) = MHEG5getMem(
sizeof **
new);
474 (*new)->refCount = 1;
484 #ifdef HFS_DEBUG_TABLE 494 static void PopMappingTable(
void)
496 assert(hfsTable - hfsTables > 0);
501 #ifdef HFS_DEBUG_TABLE 514 static void ReleaseMapping(
HfsMapping *mapping)
516 if (mapping != &defaultMapping)
519 assert(mapping->refCount >= 0);
521 if (mapping->refCount == 0)
525 MHEG5freeMem(mapping);
541 pMapping = &hfsTable->anchor;
544 while (mapping != NULL && !match)
546 match = IsStringEqual(pathName, &mapping->pathName);
549 pMapping = &mapping->next;
568 static void RemoveMapping(
HfsMapping **pMapping)
573 oldMapping = *pMapping;
574 if (!IsDefaultMapping(oldMapping))
576 nextMapping = oldMapping->next;
579 *pMapping = nextMapping;
582 ReleaseMapping(oldMapping);
599 oldMapping = (*pMapping);
600 nextMapping = oldMapping->next;
603 oldMapping->next = NULL;
606 mapping->next = nextMapping;
610 ReleaseMapping(oldMapping);
626 if (IsValidInput(pathName, mappingList))
628 mapping = MHEG5getMem(
sizeof *mapping);
633 if ((mapping->pathName.len == pathName->len) &&
634 (mapping->mappingList.len == mappingList->len))
636 mapping->next = NULL;
637 mapping->refCount = 1;
643 MHEG5freeMem(mapping);
660 static void InsertMapping(
HfsMapping *newMapping)
665 newMapping->next = NULL;
667 pMapping = &hfsTable->anchor;
668 while (*pMapping != NULL)
671 if (IsStringAfter(&newMapping->pathName, &mapping->pathName))
673 newMapping->next = mapping;
678 pMapping = &(*pMapping)->next;
681 *pMapping = newMapping;
695 if (string->len == otherString->len)
697 if (string->len == 0 ||
699 memcmp(string->data, otherString->data, string->len) == 0))
723 toCompare =
string->len;
724 if (toCompare > otherString->len)
726 toCompare = otherString->len;
729 comp = memcmp(string->data, otherString->data, toCompare);
730 if (comp > 0 || (comp == 0 && string->len > otherString->len))
745 static MHEG5Bool IsDefaultMapping(
HfsMapping *mapping)
750 if (mapping->pathName.len == 2 &&
751 mapping->pathName.data[0] ==
'/' &&
752 mapping->pathName.data[1] ==
'/')
767 static MHEG5Bool IsValidReference(
MHEG5String *reference)
772 if ((reference->len > 2) &&
773 (reference->data[0] ==
'/') && (reference->data[1] ==
'/'))
811 if (path.data[path.len - 1] !=
'/')
828 while (valid && offset < mappingList->len)
830 while (offset < mappingList->len && mappingList->data[offset] !=
' ')
835 length = offset - start;
836 PRINT((
"Checking \"%.*s\"\n", (
int)length, mappingList->data + start));
838 check.data = mappingList->data + start;
842 if (path.len == 0 || origin == ORIGIN_HYBRID)
846 else if (path.data[path.len - 1] ==
'/' && isFile)
850 else if (path.data[path.len - 1] !=
'/' && !isFile)
863 #ifdef HFS_DEBUG_TABLE 868 static void PrintMappingTable(
void)
872 mapping = hfsTable->anchor;
873 while (mapping != NULL)
875 TPRINT(TFILE,(
"pathName = \"%.*s\"\n", (
int)mapping->pathName.len,
876 (
char *)mapping->pathName.data));
877 TPRINT(TFILE,(
"mappingList = \"%.*s\"\n", (
int)mapping->mappingList.len,
878 (
char *)mapping->mappingList.data));
879 mapping = mapping->next;
void MHEG5ReleaseHybridFileSystemMapping(void *handle)
Release mapping returned from the hybrid file system. The mapping must be have been returned by a cal...
void MHEG5ClearHybridFileSystem(void)
Clear the hybrid file system and restore the default mapping // -> DSM://.
void MHEG5PopHybridFileSystem(void)
Clear the current hybrid file system and pop a stored hybrid file system from the stack...
MHEG5String MHEG5GetFirstDsmReference(MHEG5String *reference)
Return first reference with DSM:// source. This is a convenience function that converts a hybrid:// r...
void * MHEG5GetHybridFileSystemMapping(MHEG5String *reference)
Return mapping from the hybrid file system given path name. The mapping must be released using MHEG5R...
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
void MHEG5stringDestruct(MHEG5String *item)
Destruct a MHEG5String.
This file defines the profile for the MHEG engine.
Implement Functions to support Service Gateways. Functions for standarizing several GroupIDs like +DS...
void MHEG5PushHybridFileSystem(void)
Push a copy of the current hybrid file system into the stack.
MHEG5String MHEG5convertGIDGetOrigin(MHEG5String *inRef, E_FS_ORIGIN *pOrigin)
Convert a group ID from a relative reference to an absolute reference. See UK1.05 section 8...
void MHEG5InitialiseHybridFileSystem(void)
Initialise the hybrid file system. The hybrid file system is a set of mappings from a "path" string (...
void MHEG5InitMappingIter(MHEG5MappingIter_t *iter, void *mapping)
Initialise hybrid filesystem mapping iterator.
System Wide Global Technical Data Type Definitions.
MHEG5String MHEG5GetNextReference(MHEG5String *ref, MHEG5MappingIter_t *iter)
Return next reference from mapping iterator.
void MHEG5SetHybridFileSystem(MHEG5String *pathName, MHEG5String *mappingList)
Set mapping list in the hybrid file system. This function sets, clears or modifies the list of mappin...
Functions relating to Hybrid file system.