diff options
author | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-07-19 00:41:32 +0300 |
---|---|---|
committer | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-07-19 00:41:32 +0300 |
commit | ef6b6263abd1d58ebefe3c8b751c9148459c9638 (patch) | |
tree | aae08bd19811a3a11820279c45f25e588928ec76 /lnode.c | |
parent | c9c70745fbdb4be82796f94e5601109d9071bb46 (diff) |
Added the code for looking up files with names like 'file,,x'.
The user can now request files with special names like 'file,,x'
and the proxy will start the translator 'x' on file 'file' and
return the port to the user. If 'x' is not an absolute path,
the default prefix '/hurd/' is added to it.
Diffstat (limited to 'lnode.c')
-rw-r--r-- | lnode.c | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -303,3 +303,70 @@ lnode_uninstall node->next->prevp = &node->next; }/*lnode_uninstall*/ /*----------------------------------------------------------------------------*/ +/*Constructs a list of translators that were set on the ancestors of `node`*/ +error_t +lnode_list_translators + ( + lnode_t * node, + char ** trans, /*the malloced list of 0-separated strings*/ + size_t * ntrans /*the number of elements in `trans`*/ + ) + { + /*The size of block of memory for the list of translators*/ + size_t sz = 0; + + /*Used for tracing the lineage of `node`*/ + lnode_t * ln = node; + + /*Used in computing the lengths of lists of translators in every node + we will go through and for constructing the final list of translators*/ + char * p; + + /*The current position in *data (used in filling out the list of + translators)*/ + char * transp; + + /*The length of the current translator name*/ + size_t complen; + + size_t i; + + /*Trace the lineage of the `node` (including itself) and compute the + total length of the list of translators*/ + for(; ln; sz += ln->translen, ln = ln->dir); + + /*Try to allocate a block of memory sufficient for storing the list of + translators*/ + *trans = malloc(sz); + if(!*trans) + return ENOMEM; + + /*No translators at first*/ + *ntrans = 0; + + /*Again trace the lineage of the `node` (including itself)*/ + for(transp = *trans + sz, ln = node; ln; ln = ln->dir) + { + /*Go through each translator name in the list of names*/ + for(i = 0, p = ln->trans + ln->translen - 2; i < ln->ntrans; ++i) + { + /*position p at the beginning of the current component and + compute its length at the same time*/ + for(complen = 0; *p; --p, ++complen); + --p; + + /*move the current position backwards*/ + transp -= complen + 1; + + /*copy the current translator name into the list*/ + strcpy(transp, p + 2); + + /*we've got another translator*/ + ++*ntrans; + } + } + + /*Everything OK*/ + return 0; + }/*lnode_list_translators*/ +/*----------------------------------------------------------------------------*/ |