PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/external/fieldtrip/trunk/fileio/private/filetype_check_uri.m

http://open-realtime-fmri.googlecode.com/
MATLAB | 236 lines | 81 code | 20 blank | 135 comment | 17 complexity | 2479d6069ef94dd15386ae6bc901b0c5 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. function varargout = filetype_check_uri(filename, ftyp)
  2. % FILETYPE_CHECK_URI
  3. %
  4. % Supported URIs are
  5. % buffer://<host>:<port>
  6. % fifo://<filename>
  7. % global://<varname>
  8. % mysql://<user>:<password>@<host>:<port>
  9. % rfb://<password>@<host>:<port>
  10. % serial:<port>?key1=value1&key2=value2&...
  11. % shm://<filename>
  12. % tcp://<host>:<port>
  13. % udp://<host>:<port>
  14. %
  15. % The URI schemes supproted by these function are not the official schemes.
  16. % See the documentation included inside this function for more details.
  17. % RFC4395 defines an IANA-maintained registry of URI Schemes. See also
  18. % http://www.iana.org/assignments/uri-schemes.html and
  19. % http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax.
  20. % Copyright (C) 2007, Robert Oostenveld
  21. %
  22. % This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
  23. % for the documentation and details.
  24. %
  25. % FieldTrip is free software: you can redistribute it and/or modify
  26. % it under the terms of the GNU General Public License as published by
  27. % the Free Software Foundation, either version 3 of the License, or
  28. % (at your option) any later version.
  29. %
  30. % FieldTrip is distributed in the hope that it will be useful,
  31. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. % GNU General Public License for more details.
  34. %
  35. % You should have received a copy of the GNU General Public License
  36. % along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
  37. %
  38. % $Id: filetype_check_uri.m 2885 2011-02-16 09:41:58Z roboos $
  39. % these are for remembering the type on subsequent calls with the same input arguments
  40. persistent previous_argin previous_argout
  41. if nargin<2
  42. % ensure that all input arguments are defined
  43. ftyp = [];
  44. end
  45. current_argin = {filename, ftyp};
  46. if isequal(current_argin, previous_argin)
  47. % don't do the detection again, but return the previous value from cache
  48. varargout = previous_argout;
  49. return
  50. end
  51. sep = find(filename==':');
  52. if ~isempty(sep)
  53. scheme = filename(1:(sep(1)-1));
  54. else
  55. scheme = [];
  56. end
  57. if nargin>1
  58. % only return true or false
  59. varargout{1} = strcmp(scheme, ftyp);
  60. else
  61. % return the full details of this URI scheme
  62. switch scheme
  63. case 'shm'
  64. % shm://<filename>
  65. % the filename is optional, usually it can and will be read from shared memory
  66. if length(filename)>6
  67. varargout{1} = filename(7:end);
  68. else
  69. varargout{1} = [];
  70. end
  71. case 'fifo'
  72. % fifo://<filename>
  73. varargout{1} = filename(8:end);
  74. case 'global'
  75. % global://<varname>
  76. varargout{1} = filename(10:end);
  77. case 'buffer'
  78. % buffer://<host>:<port>
  79. tok = tokenize(filename(10:end), ':');
  80. varargout{1} = tok{1};
  81. varargout{2} = str2num(tok{2});
  82. case 'tcp'
  83. % tcp://<host>:<port>
  84. tok = tokenize(filename(7:end), ':');
  85. varargout{1} = tok{1};
  86. varargout{2} = str2num(tok{2});
  87. case 'udp'
  88. % udp://<host>:<port>
  89. tok = tokenize(filename(7:end), ':');
  90. varargout{1} = tok{1};
  91. varargout{2} = str2num(tok{2});
  92. case 'rfb'
  93. % rfb://<password>@<host>:<port>
  94. tok0 = tokenize(filename(7:end), '@');
  95. tok1 = tokenize(tok0{2}, ':');
  96. varargout{1} = tok0{1};
  97. varargout{2} = tok1{1};
  98. varargout{3} = str2num(tok1{2});
  99. case 'mysql'
  100. % mysql://<user>:<password>@<host>:<port>
  101. tok0 = tokenize(filename(9:end), '@');
  102. tok1 = tokenize(tok0{1}, ':');
  103. tok2 = tokenize(tok0{2}, ':');
  104. varargout{1} = tok1{1};
  105. varargout{2} = tok1{2};
  106. varargout{3} = tok2{1};
  107. if length(tok2)>1
  108. varargout{4} = str2num(tok2{2});
  109. else
  110. varargout{4} = [];
  111. end
  112. case 'serial'
  113. % serial:<Port>?key1=value1&key2=value2&...
  114. % the supported optional arguments are
  115. % BaudRate
  116. % DataBits
  117. % DataTerminalReady
  118. % FlowControl
  119. % Parity
  120. % Port
  121. % ReadAsyncMode
  122. % RequestToSend
  123. % StopBits
  124. % Terminator
  125. tok0 = tokenize(filename(8:end), '?');
  126. varargout{1} = tok0{1};
  127. varargout{2} = [];
  128. if length(tok0)>1
  129. tok1 = tokenize(tok0{2}, '&');
  130. for i=1:length(tok1)
  131. tok2 = tokenize(tok1{i}, '=');
  132. opt{(i-1)*2+1} = tok2{1};
  133. opt{(i-1)*2+2} = tok2{2};
  134. end
  135. varargout{2} = opt;
  136. end
  137. otherwise
  138. error('unsupported scheme in URI')
  139. end
  140. end
  141. % remember the current input and output arguments, so that they can be
  142. % reused on a subsequent call in case the same input argument is given
  143. current_argout = varargout;
  144. previous_argin = current_argin;
  145. previous_argout = current_argout;
  146. return % main()
  147. % RFC4395 defines an IANA-maintained registry of URI Schemes.
  148. % see also http://www.iana.org/assignments/uri-schemes.html
  149. % and http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
  150. %
  151. % Scheme Description Reference
  152. % -------------------------------------------------------------
  153. % aaa Diameter Protocol [RFC3588]
  154. % aaas Diameter Protocol with Secure Transport [RFC3588]
  155. % acap application configuration access protocol [RFC2244]
  156. % cap Calendar Access Protocol [RFC4324]
  157. % cid content identifier [RFC2392]
  158. % crid TV-Anytime Content Reference Identifier [RFC4078]
  159. % data data [RFC2397]
  160. % dav dav [RFC-ietf-webdav-rfc2518bis-18.txt]
  161. % dict dictionary service protocol [RFC2229]
  162. % dns Domain Name System [RFC4501]
  163. % fax fax [RFC3966]
  164. % file Host-specific file names [RFC1738]
  165. % ftp File Transfer Protocol [RFC1738]
  166. % go go [RFC3368]
  167. % gopher The Gopher Protocol [RFC4266]
  168. % h323 H.323 [RFC3508]
  169. % http Hypertext Transfer Protocol [RFC2616]
  170. % https Hypertext Transfer Protocol Secure [RFC2818]
  171. % icap Internet Content Adaptation Protocol [RFC3507]
  172. % im Instant Messaging [RFC3860]
  173. % imap internet message access protocol [RFC2192]
  174. % info Information Assets with Identifiers in Public Namespaces [RFC4452]
  175. % ipp Internet Printing Protocol [RFC3510]
  176. % iris Internet Registry Information Service [RFC3981]
  177. % iris.beep iris.beep [RFC3983]
  178. % iris.xpc iris.xpc [RFC-ietf-crisp-iris-xpc-06.txt]
  179. % iris.xpcs iris.xpcs [RFC-ietf-crisp-iris-xpc-06.txt]
  180. % iris.lwz iris.lwz [RFC-ietf-crisp-iris-lwz-08.txt]
  181. % ldap Lightweight Directory Access Protocol [RFC4516]
  182. % mailto Electronic mail address [RFC2368]
  183. % mid message identifier [RFC2392]
  184. % modem modem [RFC3966]
  185. % msrp Message Session Relay Protocol [RFC-ietf-simple-message-sessions-19.txt]
  186. % msrps Message Session Relay Protocol Secure [RFC-ietf-simple-message-sessions-19.txt]
  187. % mtqp Message Tracking Query Protocol [RFC3887]
  188. % mupdate Mailbox Update (MUPDATE) Protocol [RFC3656]
  189. % news USENET news [RFC1738]
  190. % nfs network file system protocol [RFC2224]
  191. % nntp USENET news using NNTP access [RFC1738]
  192. % opaquelocktoken opaquelocktokent [RFC-ietf-webdav-rfc2518bis-18.txt]
  193. % pop Post Office Protocol v3 [RFC2384]
  194. % pres Presence [RFC3859]
  195. % rtsp real time streaming protocol [RFC2326]
  196. % service service location [RFC2609]
  197. % shttp Secure Hypertext Transfer Protocol [RFC2660]
  198. % sip session initiation protocol [RFC3261]
  199. % sips secure session initiation protocol [RFC3261]
  200. % snmp Simple Network Management Protocol [RFC4088]
  201. % soap.beep soap.beep [RFC3288]
  202. % soap.beeps soap.beeps [RFC3288]
  203. % tag tag [RFC4151]
  204. % tel telephone [RFC3966]
  205. % telnet Reference to interactive sessions [RFC4248]
  206. % tftp Trivial File Transfer Protocol [RFC3617]
  207. % thismessage multipart/related relative reference resolution [RFC2557]
  208. % tip Transaction Internet Protocol [RFC2371]
  209. % tv TV Broadcasts [RFC2838]
  210. % urn Uniform Resource Names (click for registry) [RFC2141]
  211. % vemmi versatile multimedia interface [RFC2122]
  212. % xmlrpc.beep xmlrpc.beep [RFC3529]
  213. % xmlrpc.beeps xmlrpc.beeps [RFC3529]
  214. % xmpp Extensible Messaging and Presence Protocol [RFC4622]
  215. % z39.50r Z39.50 Retrieval [RFC2056]
  216. % z39.50s Z39.50 Session [RFC2056]