1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>discover: /home/pere/src/debiancvs/pkg-discover/discover/trunk/lib/load-url.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<div class="nav">
<a class="el" href="dir_000002.html">lib</a></div>
<h1>load-url.c</h1><a href="load-url_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001
00006 <span class="comment">/* $Progeny$</span>
00007 <span class="comment"> *</span>
00008 <span class="comment"> * Copyright 2003 Hewlett-Packard Company</span>
00009 <span class="comment"> *</span>
00010 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
00011 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
00012 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
00013 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
00014 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
00015 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
00018 <span class="comment"> * all copies or substantial portions of the Software.</span>
00019 <span class="comment"> *</span>
00020 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
00021 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
00022 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
00023 <span class="comment"> * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
00024 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
00025 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
00026 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
00027 <span class="comment"> */</span>
00028
00029 <span class="preprocessor">#include "config.h"</span>
00030
00031 <span class="preprocessor">#ifndef HAVE_LIBCURL</span>
00032 <span class="preprocessor"></span>
00033 <span class="preprocessor">#include <assert.h></span>
00034 <span class="preprocessor">#include <expat.h></span>
00035
00036 <span class="preprocessor">#include <discover/load-url.h></span>
00037
00038 <span class="preprocessor">#ifdef HAVE_ZLIB</span>
00039 <span class="preprocessor"></span><span class="preprocessor">#include <zlib.h></span>
00040 <span class="preprocessor">#define stdio_file gzFile</span>
00041 <span class="preprocessor"></span><span class="preprocessor">#define fopen gzopen</span>
00042 <span class="preprocessor"></span><span class="preprocessor">#define STDIO_READ fread</span>
00043 <span class="preprocessor"></span><span class="preprocessor">#define fclose gzclose</span>
00044 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00045 <span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
00046 <span class="keyword">typedef</span> FILE *stdio_file;
00047 <span class="preprocessor">#define STDIO_READ(f, buf, len) fread(buf, 1, len, f)</span>
00048 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00049 <span class="preprocessor"></span>
00050 <span class="preprocessor">#include <string.h></span>
00051
00052 <span class="keywordtype">int</span>
00053 _discover_load_url(<span class="keyword">const</span> <span class="keywordtype">char</span> *url, XML_Parser parser)
00054 {
00055 <span class="keyword">const</span> <span class="keywordtype">char</span> *file_path;
00056 stdio_file url_file;
00057 <span class="keywordtype">char</span> buf[4096];
00058 <span class="keywordtype">char</span> *tmp;
00059 size_t len;
00060 <span class="keywordtype">int</span> parse_result;
00061
00062 assert(url != NULL);
00063
00064 <span class="keywordflow">if</span> (strncmp(url, <span class="stringliteral">"file:"</span>, 5))
00065 <span class="keywordflow">return</span> 0;
00066
00067 <span class="comment">/* We have three accepted formats for the url: file://host/path,</span>
00068 <span class="comment"> * file:///path, and file://path. The third is not actually</span>
00069 <span class="comment"> * legal, but curl allows it to refer to a file in the current</span>
00070 <span class="comment"> * directory. Since we use that format in the test suite, we need</span>
00071 <span class="comment"> * to support it here.</span>
00072 <span class="comment"> *</span>
00073 <span class="comment"> * For file://host/path and file:///path, the strchr call takes us</span>
00074 <span class="comment"> * directly to the correct absolute path. For file://path, url +</span>
00075 <span class="comment"> * 7 is just "path" so we use that relative path. */</span>
00076 file_path = strchr(url + 7, <span class="charliteral">'/'</span>);
00077 <span class="keywordflow">if</span> (!file_path) {
00078 file_path = url + 7;
00079 }
00080
00081 <span class="keywordflow">if</span> (*file_path == <span class="charliteral">'\0'</span>)
00082 <span class="keywordflow">return</span> 0;
00083
00084 url_file = fopen(file_path, <span class="stringliteral">"r"</span>);
00085 <span class="keywordflow">if</span> (url_file == NULL)
00086 <span class="keywordflow">return</span> 0;
00087
00088 <span class="keywordflow">do</span>
00089 {
00090 len = STDIO_READ(url_file, buf, <span class="keyword">sizeof</span>(buf));
00091 <span class="keywordflow">if</span> (len > 0)
00092 parse_result = XML_Parse(parser, buf, len, 0);
00093 } <span class="keywordflow">while</span> ((len > 0) && (parse_result != 0));
00094
00095 fclose(url_file);
00096
00097 <span class="keywordflow">return</span> (parse_result != 0);
00098 }
00099
00100 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Jul 28 03:38:00 2005 for discover by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|