test/v2-regression/ctest.html

Tue, 23 Aug 2016 14:31:02 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 23 Aug 2016 14:31:02 +0200
changeset 43
a8cee98c8832
parent 41
c06ab07fd29d
permissions
-rw-r--r--

cleans up main function

<!DOCTYPE html>
<html>
  <head>
    <title>c2html</title>
    <style type="text/css">
      span.c2html-lineno a {
        font-style: italic;
        text-decoration: none;
        color: grey;
      }
      span.c2html-keyword {
        color: blue;
      }
      span.c2html-macroconst {
        color: cornflowerblue;
      }
      span.c2html-type {
        color: cornflowerblue;
      }
      span.c2html-directive {
        color: green;
      }
      span.c2html-string {
        color: darkorange;
      }
      span.c2html-comment {
        color: grey;
      }
      span.c2html-stdinclude {
        color: darkorange;
      }
      span.c2html-userinclude {
        color: darkorange;
      }
      a.c2html-userinclude {
        color: darkorange;
        text-decoration: underline;
      }
    </style>
  </head>
  <body>

<pre>
<span class="c2html-lineno"><a name="l1" href="#l1">  1 </a></span> <span class="c2html-comment">/*</span>
<span class="c2html-lineno"><a name="l2" href="#l2">  2 </a></span> <span class="c2html-comment"> * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.</span>
<span class="c2html-lineno"><a name="l3" href="#l3">  3 </a></span> <span class="c2html-comment"> *</span>
<span class="c2html-lineno"><a name="l4" href="#l4">  4 </a></span> <span class="c2html-comment"> * Copyright 2015 Olaf Wintermann. All rights reserved.</span>
<span class="c2html-lineno"><a name="l5" href="#l5">  5 </a></span> <span class="c2html-comment"> *</span>
<span class="c2html-lineno"><a name="l6" href="#l6">  6 </a></span> <span class="c2html-comment"> * Redistribution and use in source and binary forms, with or without</span>
<span class="c2html-lineno"><a name="l7" href="#l7">  7 </a></span> <span class="c2html-comment"> * modification, are permitted provided that the following conditions are met:</span>
<span class="c2html-lineno"><a name="l8" href="#l8">  8 </a></span> <span class="c2html-comment"> *</span>
<span class="c2html-lineno"><a name="l9" href="#l9">  9 </a></span> <span class="c2html-comment"> *   1. Redistributions of source code must retain the above copyright</span>
<span class="c2html-lineno"><a name="l10" href="#l10"> 10 </a></span> <span class="c2html-comment"> *      notice, this list of conditions and the following disclaimer.</span>
<span class="c2html-lineno"><a name="l11" href="#l11"> 11 </a></span> <span class="c2html-comment"> *</span>
<span class="c2html-lineno"><a name="l12" href="#l12"> 12 </a></span> <span class="c2html-comment"> *   2. Redistributions in binary form must reproduce the above copyright</span>
<span class="c2html-lineno"><a name="l13" href="#l13"> 13 </a></span> <span class="c2html-comment"> *      notice, this list of conditions and the following disclaimer in the</span>
<span class="c2html-lineno"><a name="l14" href="#l14"> 14 </a></span> <span class="c2html-comment"> *      documentation and/or other materials provided with the distribution.</span>
<span class="c2html-lineno"><a name="l15" href="#l15"> 15 </a></span> <span class="c2html-comment"> *</span>
<span class="c2html-lineno"><a name="l16" href="#l16"> 16 </a></span> <span class="c2html-comment"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"</span>
<span class="c2html-lineno"><a name="l17" href="#l17"> 17 </a></span> <span class="c2html-comment"> * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<span class="c2html-lineno"><a name="l18" href="#l18"> 18 </a></span> <span class="c2html-comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<span class="c2html-lineno"><a name="l19" href="#l19"> 19 </a></span> <span class="c2html-comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE</span>
<span class="c2html-lineno"><a name="l20" href="#l20"> 20 </a></span> <span class="c2html-comment"> * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span>
<span class="c2html-lineno"><a name="l21" href="#l21"> 21 </a></span> <span class="c2html-comment"> * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span>
<span class="c2html-lineno"><a name="l22" href="#l22"> 22 </a></span> <span class="c2html-comment"> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS</span>
<span class="c2html-lineno"><a name="l23" href="#l23"> 23 </a></span> <span class="c2html-comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN</span>
<span class="c2html-lineno"><a name="l24" href="#l24"> 24 </a></span> <span class="c2html-comment"> * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</span>
<span class="c2html-lineno"><a name="l25" href="#l25"> 25 </a></span> <span class="c2html-comment"> * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span>
<span class="c2html-lineno"><a name="l26" href="#l26"> 26 </a></span> <span class="c2html-comment"> * POSSIBILITY OF SUCH DAMAGE.</span>
<span class="c2html-lineno"><a name="l27" href="#l27"> 27 </a></span> <span class="c2html-comment"> */</span>
<span class="c2html-lineno"><a name="l28" href="#l28"> 28 </a></span> 
<span class="c2html-lineno"><a name="l29" href="#l29"> 29 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;time.h&gt;</span>
<span class="c2html-lineno"><a name="l30" href="#l30"> 30 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;stdio.h&gt;</span>
<span class="c2html-lineno"><a name="l31" href="#l31"> 31 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;stdlib.h&gt;</span>
<span class="c2html-lineno"><a name="l32" href="#l32"> 32 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;string.h&gt;</span>
<span class="c2html-lineno"><a name="l33" href="#l33"> 33 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;ucx/string.h&gt;</span>
<span class="c2html-lineno"><a name="l34" href="#l34"> 34 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;ucx/buffer.h&gt;</span>
<span class="c2html-lineno"><a name="l35" href="#l35"> 35 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;ucx/utils.h&gt;</span>
<span class="c2html-lineno"><a name="l36" href="#l36"> 36 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;libxml/tree.h&gt;</span>
<span class="c2html-lineno"><a name="l37" href="#l37"> 37 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;curl/curl.h&gt;</span>
<span class="c2html-lineno"><a name="l38" href="#l38"> 38 </a></span> 
<span class="c2html-lineno"><a name="l39" href="#l39"> 39 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/sha.h&gt;</span>
<span class="c2html-lineno"><a name="l40" href="#l40"> 40 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/hmac.h&gt;</span>
<span class="c2html-lineno"><a name="l41" href="#l41"> 41 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/evp.h&gt;</span>
<span class="c2html-lineno"><a name="l42" href="#l42"> 42 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/bio.h&gt;</span>
<span class="c2html-lineno"><a name="l43" href="#l43"> 43 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/buffer.h&gt;</span>
<span class="c2html-lineno"><a name="l44" href="#l44"> 44 </a></span> <span class="c2html-directive">#include</span> <span class="c2html-stdinclude">&lt;openssl/rand.h&gt;</span>
<span class="c2html-lineno"><a name="l45" href="#l45"> 45 </a></span> 
<span class="c2html-lineno"><a name="l46" href="#l46"> 46 </a></span> <span class="c2html-directive">#include</span> <a class="c2html-userinclude" href="utils.h">"utils.h"</a>
<span class="c2html-lineno"><a name="l47" href="#l47"> 47 </a></span> <span class="c2html-directive">#include</span> <a class="c2html-userinclude" href="crypto.h">"crypto.h"</a>
<span class="c2html-lineno"><a name="l48" href="#l48"> 48 </a></span> <span class="c2html-directive">#include</span> <a class="c2html-userinclude" href="webdav.h">"webdav.h"</a>
<span class="c2html-lineno"><a name="l49" href="#l49"> 49 </a></span> 
<span class="c2html-lineno"><a name="l50" href="#l50"> 50 </a></span> <span class="c2html-directive">#define</span> <span class="c2html-macroconst">MACRO1337</span> <span class="c2html-macroconst">1337L</span>
<span class="c2html-lineno"><a name="l51" href="#l51"> 51 </a></span> 
<span class="c2html-lineno"><a name="l52" href="#l52"> 52 </a></span> <span class="c2html-comment">/* -------------------- This is a testing file. -------------------------- */</span>
<span class="c2html-lineno"><a name="l53" href="#l53"> 53 </a></span> <span class="c2html-comment">/*</span>
<span class="c2html-lineno"><a name="l54" href="#l54"> 54 </a></span> <span class="c2html-comment">time_t util_parse_creationdate(char *str) {</span>
<span class="c2html-lineno"><a name="l55" href="#l55"> 55 </a></span> <span class="c2html-comment">    // example: 2012-11-29T21:35:35Z</span>
<span class="c2html-lineno"><a name="l56" href="#l56"> 56 </a></span> <span class="c2html-comment">    if(!str) {</span>
<span class="c2html-lineno"><a name="l57" href="#l57"> 57 </a></span> <span class="c2html-comment">        return 0;</span>
<span class="c2html-lineno"><a name="l58" href="#l58"> 58 </a></span> <span class="c2html-comment">    }</span>
<span class="c2html-lineno"><a name="l59" href="#l59"> 59 </a></span> <span class="c2html-comment">    // TODO</span>
<span class="c2html-lineno"><a name="l60" href="#l60"> 60 </a></span> <span class="c2html-comment">    return 0;</span>
<span class="c2html-lineno"><a name="l61" href="#l61"> 61 </a></span> <span class="c2html-comment">}</span>
<span class="c2html-lineno"><a name="l62" href="#l62"> 62 </a></span> <span class="c2html-comment">*/</span>
<span class="c2html-lineno"><a name="l63" href="#l63"> 63 </a></span> <span class="c2html-type">time_t</span> util_parse_lastmodified(<span class="c2html-keyword">char</span> *str) {
<span class="c2html-lineno"><a name="l64" href="#l64"> 64 </a></span>     <span class="c2html-comment">// example: Thu, 29 Nov 2012 21:35:35 GMT</span>
<span class="c2html-lineno"><a name="l65" href="#l65"> 65 </a></span>     <span class="c2html-keyword">if</span>(!str) {
<span class="c2html-lineno"><a name="l66" href="#l66"> 66 </a></span>         <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l67" href="#l67"> 67 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l68" href="#l68"> 68 </a></span>         <span class="c2html-keyword">return</span> curl_getdate(str, <span class="c2html-macroconst">NULL</span>);
<span class="c2html-lineno"><a name="l69" href="#l69"> 69 </a></span>     }
<span class="c2html-lineno"><a name="l70" href="#l70"> 70 </a></span> }
<span class="c2html-lineno"><a name="l71" href="#l71"> 71 </a></span> 
<span class="c2html-lineno"><a name="l72" href="#l72"> 72 </a></span> <span class="c2html-keyword">int</span> util_getboolean(<span class="c2html-keyword">char</span> *v) {
<span class="c2html-lineno"><a name="l73" href="#l73"> 73 </a></span>     <span class="c2html-keyword">if</span>(v[<span class="c2html-macroconst">0</span>] == <span class="c2html-string">'T'</span> || v[<span class="c2html-macroconst">0</span>] == <span class="c2html-string">'t'</span>) {
<span class="c2html-lineno"><a name="l74" href="#l74"> 74 </a></span>         <span class="c2html-keyword">return</span> <span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l75" href="#l75"> 75 </a></span>     }
<span class="c2html-lineno"><a name="l76" href="#l76"> 76 </a></span>     <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l77" href="#l77"> 77 </a></span> }
<span class="c2html-lineno"><a name="l78" href="#l78"> 78 </a></span> 
<span class="c2html-lineno"><a name="l79" href="#l79"> 79 </a></span> <span class="c2html-keyword">int</span> util_strtoint(<span class="c2html-keyword">char</span> *str, <span class="c2html-type">int64_t</span> *value) {
<span class="c2html-lineno"><a name="l80" href="#l80"> 80 </a></span>     <span class="c2html-keyword">char</span> *end;
<span class="c2html-lineno"><a name="l81" href="#l81"> 81 </a></span>     <span class="c2html-type">int64_t</span> val = strtoll(str, &end, <span class="c2html-macroconst">0</span>);
<span class="c2html-lineno"><a name="l82" href="#l82"> 82 </a></span>     <span class="c2html-keyword">if</span>(strlen(end) == <span class="c2html-macroconst">0</span>) {
<span class="c2html-lineno"><a name="l83" href="#l83"> 83 </a></span>         *value = val;
<span class="c2html-lineno"><a name="l84" href="#l84"> 84 </a></span>         <span class="c2html-keyword">return</span> <span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l85" href="#l85"> 85 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l86" href="#l86"> 86 </a></span>         <span class="c2html-keyword">return</span> <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l87" href="#l87"> 87 </a></span>     }
<span class="c2html-lineno"><a name="l88" href="#l88"> 88 </a></span> }
<span class="c2html-lineno"><a name="l89" href="#l89"> 89 </a></span> 
<span class="c2html-lineno"><a name="l90" href="#l90"> 90 </a></span> <span class="c2html-keyword">char</span>* util_url_path(<span class="c2html-keyword">char</span> *url) { 
<span class="c2html-lineno"><a name="l91" href="#l91"> 91 </a></span>     <span class="c2html-keyword">char</span> *path = <span class="c2html-macroconst">NULL</span>;
<span class="c2html-lineno"><a name="l92" href="#l92"> 92 </a></span>     <span class="c2html-type">size_t</span> len = strlen(url);
<span class="c2html-lineno"><a name="l93" href="#l93"> 93 </a></span>     <span class="c2html-keyword">int</span> slashcount = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l94" href="#l94"> 94 </a></span>     <span class="c2html-keyword">int</span> slmax;
<span class="c2html-lineno"><a name="l95" href="#l95"> 95 </a></span>     <span class="c2html-keyword">if</span>(len &gt; <span class="c2html-macroconst">7</span> && !strncasecmp(url, <span class="c2html-string">"http://"</span>, <span class="c2html-macroconst">7</span>)) {
<span class="c2html-lineno"><a name="l96" href="#l96"> 96 </a></span>         slmax = <span class="c2html-macroconst">3</span>;
<span class="c2html-lineno"><a name="l97" href="#l97"> 97 </a></span>     } <span class="c2html-keyword">else</span> <span class="c2html-keyword">if</span>(len &gt; <span class="c2html-macroconst">8</span> && !strncasecmp(url, <span class="c2html-string">"https://"</span>, <span class="c2html-macroconst">8</span>)) {
<span class="c2html-lineno"><a name="l98" href="#l98"> 98 </a></span>         slmax = <span class="c2html-macroconst">3</span>;
<span class="c2html-lineno"><a name="l99" href="#l99"> 99 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l100" href="#l100">100 </a></span>         slmax = <span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l101" href="#l101">101 </a></span>     }
<span class="c2html-lineno"><a name="l102" href="#l102">102 </a></span>     <span class="c2html-keyword">char</span> c;
<span class="c2html-lineno"><a name="l103" href="#l103">103 </a></span>     <span class="c2html-keyword">for</span>(<span class="c2html-keyword">int</span> i=<span class="c2html-macroconst">0</span>;i&lt;len;i++) {
<span class="c2html-lineno"><a name="l104" href="#l104">104 </a></span>         c = url[i];
<span class="c2html-lineno"><a name="l105" href="#l105">105 </a></span>         <span class="c2html-keyword">if</span>(c == <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l106" href="#l106">106 </a></span>             slashcount++;
<span class="c2html-lineno"><a name="l107" href="#l107">107 </a></span>             <span class="c2html-keyword">if</span>(slashcount == slmax) {
<span class="c2html-lineno"><a name="l108" href="#l108">108 </a></span>                 path = url + i;
<span class="c2html-lineno"><a name="l109" href="#l109">109 </a></span>                 <span class="c2html-keyword">break</span>;
<span class="c2html-lineno"><a name="l110" href="#l110">110 </a></span>             }
<span class="c2html-lineno"><a name="l111" href="#l111">111 </a></span>         }
<span class="c2html-lineno"><a name="l112" href="#l112">112 </a></span>     } 
<span class="c2html-lineno"><a name="l113" href="#l113">113 </a></span>     <span class="c2html-keyword">return</span> path;
<span class="c2html-lineno"><a name="l114" href="#l114">114 </a></span> }
<span class="c2html-lineno"><a name="l115" href="#l115">115 </a></span> 
<span class="c2html-lineno"><a name="l116" href="#l116">116 </a></span> <span class="c2html-keyword">char</span>* util_url_decode(DavSession *sn, <span class="c2html-keyword">char</span> *url) {
<span class="c2html-lineno"><a name="l117" href="#l117">117 </a></span>     <span class="c2html-keyword">char</span> *unesc = curl_easy_unescape(sn-&gt;handle, url, strlen(url), <span class="c2html-macroconst">NULL</span>);
<span class="c2html-lineno"><a name="l118" href="#l118">118 </a></span>     <span class="c2html-keyword">char</span> *ret = strdup(unesc);
<span class="c2html-lineno"><a name="l119" href="#l119">119 </a></span>     curl_free(unesc);
<span class="c2html-lineno"><a name="l120" href="#l120">120 </a></span>     <span class="c2html-keyword">return</span> ret;
<span class="c2html-lineno"><a name="l121" href="#l121">121 </a></span> }
<span class="c2html-lineno"><a name="l122" href="#l122">122 </a></span> 
<span class="c2html-lineno"><a name="l123" href="#l123">123 </a></span> <span class="c2html-keyword">char</span>* util_resource_name(<span class="c2html-keyword">char</span> *url) {
<span class="c2html-lineno"><a name="l124" href="#l124">124 </a></span>     <span class="c2html-keyword">int</span> si = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l125" href="#l125">125 </a></span>     <span class="c2html-keyword">int</span> osi = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l126" href="#l126">126 </a></span>     <span class="c2html-keyword">int</span> i = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l127" href="#l127">127 </a></span>     <span class="c2html-keyword">int</span> p = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l128" href="#l128">128 </a></span>     <span class="c2html-keyword">char</span> c;
<span class="c2html-lineno"><a name="l129" href="#l129">129 </a></span>     <span class="c2html-keyword">while</span>((c = url[i]) != <span class="c2html-macroconst">0</span>) {
<span class="c2html-lineno"><a name="l130" href="#l130">130 </a></span>         <span class="c2html-keyword">if</span>(c == <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l131" href="#l131">131 </a></span>             osi = si;
<span class="c2html-lineno"><a name="l132" href="#l132">132 </a></span>             si = i;
<span class="c2html-lineno"><a name="l133" href="#l133">133 </a></span>             p = <span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l134" href="#l134">134 </a></span>         }
<span class="c2html-lineno"><a name="l135" href="#l135">135 </a></span>         i++;
<span class="c2html-lineno"><a name="l136" href="#l136">136 </a></span>     }
<span class="c2html-lineno"><a name="l137" href="#l137">137 </a></span>     
<span class="c2html-lineno"><a name="l138" href="#l138">138 </a></span>     <span class="c2html-keyword">char</span> *name = url + si + p;
<span class="c2html-lineno"><a name="l139" href="#l139">139 </a></span>     <span class="c2html-keyword">if</span>(name[<span class="c2html-macroconst">0</span>] == <span class="c2html-macroconst">0</span>) {
<span class="c2html-lineno"><a name="l140" href="#l140">140 </a></span>         name = url + osi + p;
<span class="c2html-lineno"><a name="l141" href="#l141">141 </a></span>         <span class="c2html-keyword">if</span>(name[<span class="c2html-macroconst">0</span>] == <span class="c2html-macroconst">0</span>) {
<span class="c2html-lineno"><a name="l142" href="#l142">142 </a></span>             <span class="c2html-keyword">return</span> url;
<span class="c2html-lineno"><a name="l143" href="#l143">143 </a></span>         }
<span class="c2html-lineno"><a name="l144" href="#l144">144 </a></span>     }
<span class="c2html-lineno"><a name="l145" href="#l145">145 </a></span>     
<span class="c2html-lineno"><a name="l146" href="#l146">146 </a></span>     <span class="c2html-keyword">return</span> name;
<span class="c2html-lineno"><a name="l147" href="#l147">147 </a></span> }
<span class="c2html-lineno"><a name="l148" href="#l148">148 </a></span> 
<span class="c2html-lineno"><a name="l149" href="#l149">149 </a></span> <span class="c2html-keyword">int</span> util_mkdir(<span class="c2html-keyword">char</span> *path, <span class="c2html-type">mode_t</span> mode) {
<span class="c2html-lineno"><a name="l150" href="#l150">150 </a></span> <span class="c2html-directive">#ifdef</span> <span class="c2html-macroconst">_WIN32</span>
<span class="c2html-lineno"><a name="l151" href="#l151">151 </a></span>     <span class="c2html-keyword">return</span> mkdir(path);
<span class="c2html-lineno"><a name="l152" href="#l152">152 </a></span> <span class="c2html-directive">#else</span>
<span class="c2html-lineno"><a name="l153" href="#l153">153 </a></span>     <span class="c2html-keyword">return</span> mkdir(path, mode);
<span class="c2html-lineno"><a name="l154" href="#l154">154 </a></span> <span class="c2html-directive">#endif</span>
<span class="c2html-lineno"><a name="l155" href="#l155">155 </a></span> }
<span class="c2html-lineno"><a name="l156" href="#l156">156 </a></span> 
<span class="c2html-lineno"><a name="l157" href="#l157">157 </a></span> <span class="c2html-keyword">char</span>* util_concat_path(<span class="c2html-keyword">char</span> *url_base, <span class="c2html-keyword">char</span> *p) {
<span class="c2html-lineno"><a name="l158" href="#l158">158 </a></span>     <span class="c2html-type">sstr_t</span> base = sstr(url_base);
<span class="c2html-lineno"><a name="l159" href="#l159">159 </a></span>     <span class="c2html-type">sstr_t</span> path;
<span class="c2html-lineno"><a name="l160" href="#l160">160 </a></span>     <span class="c2html-keyword">if</span>(p) {
<span class="c2html-lineno"><a name="l161" href="#l161">161 </a></span>         path = sstr(p);
<span class="c2html-lineno"><a name="l162" href="#l162">162 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l163" href="#l163">163 </a></span>         path = sstrn(<span class="c2html-string">""</span>, <span class="c2html-macroconst">0</span>);
<span class="c2html-lineno"><a name="l164" href="#l164">164 </a></span>     }
<span class="c2html-lineno"><a name="l165" href="#l165">165 </a></span>     
<span class="c2html-lineno"><a name="l166" href="#l166">166 </a></span>     <span class="c2html-keyword">int</span> add_separator = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l167" href="#l167">167 </a></span>     <span class="c2html-keyword">if</span>(base.ptr[base.length-<span class="c2html-macroconst">1</span>] == <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l168" href="#l168">168 </a></span>         <span class="c2html-keyword">if</span>(path.ptr[<span class="c2html-macroconst">0</span>] == <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l169" href="#l169">169 </a></span>             base.length--;
<span class="c2html-lineno"><a name="l170" href="#l170">170 </a></span>         }
<span class="c2html-lineno"><a name="l171" href="#l171">171 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l172" href="#l172">172 </a></span>         <span class="c2html-keyword">if</span>(path.length == <span class="c2html-macroconst">0</span> || path.ptr[<span class="c2html-macroconst">0</span>] != <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l173" href="#l173">173 </a></span>             add_separator = <span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l174" href="#l174">174 </a></span>         }
<span class="c2html-lineno"><a name="l175" href="#l175">175 </a></span>     }
<span class="c2html-lineno"><a name="l176" href="#l176">176 </a></span>     
<span class="c2html-lineno"><a name="l177" href="#l177">177 </a></span>     <span class="c2html-type">sstr_t</span> url;
<span class="c2html-lineno"><a name="l178" href="#l178">178 </a></span>     <span class="c2html-keyword">if</span>(add_separator) {
<span class="c2html-lineno"><a name="l179" href="#l179">179 </a></span>         url = sstrcat(<span class="c2html-macroconst">3</span>, base, sstr(<span class="c2html-string">"/"</span>), path);
<span class="c2html-lineno"><a name="l180" href="#l180">180 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l181" href="#l181">181 </a></span>         url = sstrcat(<span class="c2html-macroconst">2</span>, base, path);
<span class="c2html-lineno"><a name="l182" href="#l182">182 </a></span>     }
<span class="c2html-lineno"><a name="l183" href="#l183">183 </a></span>     
<span class="c2html-lineno"><a name="l184" href="#l184">184 </a></span>     <span class="c2html-keyword">return</span> url.ptr;
<span class="c2html-lineno"><a name="l185" href="#l185">185 </a></span> }
<span class="c2html-lineno"><a name="l186" href="#l186">186 </a></span> 
<span class="c2html-lineno"><a name="l187" href="#l187">187 </a></span> <span class="c2html-keyword">void</span> util_set_url(DavSession *sn, <span class="c2html-keyword">char</span> *href) {
<span class="c2html-lineno"><a name="l188" href="#l188">188 </a></span>     <span class="c2html-type">sstr_t</span> base = sstr(sn-&gt;base_url);
<span class="c2html-lineno"><a name="l189" href="#l189">189 </a></span>     <span class="c2html-type">sstr_t</span> href_str = sstr(href);
<span class="c2html-lineno"><a name="l190" href="#l190">190 </a></span>     
<span class="c2html-lineno"><a name="l191" href="#l191">191 </a></span>     <span class="c2html-keyword">char</span> *base_path = util_url_path(sn-&gt;base_url);
<span class="c2html-lineno"><a name="l192" href="#l192">192 </a></span>     base.length -= strlen(base_path);
<span class="c2html-lineno"><a name="l193" href="#l193">193 </a></span>     
<span class="c2html-lineno"><a name="l194" href="#l194">194 </a></span>     <span class="c2html-type">sstr_t</span> url = sstrcat(<span class="c2html-macroconst">2</span>, base, href_str);
<span class="c2html-lineno"><a name="l195" href="#l195">195 </a></span>     
<span class="c2html-lineno"><a name="l196" href="#l196">196 </a></span>     curl_easy_setopt(sn-&gt;handle, <span class="c2html-macroconst">CURLOPT_URL</span>, url.ptr);
<span class="c2html-lineno"><a name="l197" href="#l197">197 </a></span>     free(url.ptr);
<span class="c2html-lineno"><a name="l198" href="#l198">198 </a></span> }
<span class="c2html-lineno"><a name="l199" href="#l199">199 </a></span> 
<span class="c2html-lineno"><a name="l200" href="#l200">200 </a></span> <span class="c2html-keyword">char</span>* util_path_to_url(DavSession *sn, <span class="c2html-keyword">char</span> *path) {
<span class="c2html-lineno"><a name="l201" href="#l201">201 </a></span>     <span class="c2html-keyword">char</span> *space = malloc(<span class="c2html-macroconst">256</span>);
<span class="c2html-lineno"><a name="l202" href="#l202">202 </a></span>     UcxBuffer *url = ucx_buffer_new(space, <span class="c2html-macroconst">256</span>, <span class="c2html-macroconst">UCX_BUFFER_AUTOEXTEND</span>);
<span class="c2html-lineno"><a name="l203" href="#l203">203 </a></span>     
<span class="c2html-lineno"><a name="l204" href="#l204">204 </a></span>     <span class="c2html-comment">// add base url</span>
<span class="c2html-lineno"><a name="l205" href="#l205">205 </a></span>     ucx_buffer_write(sn-&gt;base_url, <span class="c2html-macroconst">1</span>, strlen(sn-&gt;base_url), url);
<span class="c2html-lineno"><a name="l206" href="#l206">206 </a></span>     <span class="c2html-comment">// remove trailing slash</span>
<span class="c2html-lineno"><a name="l207" href="#l207">207 </a></span>     ucx_buffer_seek(url, -<span class="c2html-macroconst">1</span>, <span class="c2html-macroconst">SEEK_CUR</span>);
<span class="c2html-lineno"><a name="l208" href="#l208">208 </a></span>     
<span class="c2html-lineno"><a name="l209" href="#l209">209 </a></span>     <span class="c2html-type">sstr_t</span> p = sstr(path);
<span class="c2html-lineno"><a name="l210" href="#l210">210 </a></span>     <span class="c2html-type">ssize_t</span> ntk = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l211" href="#l211">211 </a></span>     <span class="c2html-type">sstr_t</span> *tks = sstrsplit(p, <span class="c2html-macroconst">S</span>(<span class="c2html-string">"/"</span>), &ntk);
<span class="c2html-lineno"><a name="l212" href="#l212">212 </a></span>     
<span class="c2html-lineno"><a name="l213" href="#l213">213 </a></span>     <span class="c2html-keyword">for</span>(<span class="c2html-keyword">int</span> i=<span class="c2html-macroconst">0</span>;i&lt;ntk;i++) {
<span class="c2html-lineno"><a name="l214" href="#l214">214 </a></span>         <span class="c2html-type">sstr_t</span> node = tks[i];
<span class="c2html-lineno"><a name="l215" href="#l215">215 </a></span>         <span class="c2html-keyword">if</span>(node.length &gt; <span class="c2html-macroconst">0</span>) {
<span class="c2html-lineno"><a name="l216" href="#l216">216 </a></span>             <span class="c2html-keyword">char</span> *esc = curl_easy_escape(sn-&gt;handle, node.ptr, node.length);
<span class="c2html-lineno"><a name="l217" href="#l217">217 </a></span>             ucx_buffer_putc(url, <span class="c2html-string">'/'</span>);
<span class="c2html-lineno"><a name="l218" href="#l218">218 </a></span>             ucx_buffer_write(esc, <span class="c2html-macroconst">1</span>, strlen(esc), url);
<span class="c2html-lineno"><a name="l219" href="#l219">219 </a></span>             curl_free(esc);
<span class="c2html-lineno"><a name="l220" href="#l220">220 </a></span>         }
<span class="c2html-lineno"><a name="l221" href="#l221">221 </a></span>         free(node.ptr);
<span class="c2html-lineno"><a name="l222" href="#l222">222 </a></span>     }
<span class="c2html-lineno"><a name="l223" href="#l223">223 </a></span>     free(tks);
<span class="c2html-lineno"><a name="l224" href="#l224">224 </a></span>     <span class="c2html-keyword">if</span>(path[p.length-<span class="c2html-macroconst">1</span>] == <span class="c2html-string">'/'</span>) {
<span class="c2html-lineno"><a name="l225" href="#l225">225 </a></span>         ucx_buffer_putc(url, <span class="c2html-string">'/'</span>);
<span class="c2html-lineno"><a name="l226" href="#l226">226 </a></span>     }
<span class="c2html-lineno"><a name="l227" href="#l227">227 </a></span>     ucx_buffer_putc(url, <span class="c2html-macroconst">0</span>);
<span class="c2html-lineno"><a name="l228" href="#l228">228 </a></span>     
<span class="c2html-lineno"><a name="l229" href="#l229">229 </a></span>     space = url-&gt;space;
<span class="c2html-lineno"><a name="l230" href="#l230">230 </a></span>     ucx_buffer_free(url);
<span class="c2html-lineno"><a name="l231" href="#l231">231 </a></span>     
<span class="c2html-lineno"><a name="l232" href="#l232">232 </a></span>     <span class="c2html-keyword">return</span> space;
<span class="c2html-lineno"><a name="l233" href="#l233">233 </a></span> }
<span class="c2html-lineno"><a name="l234" href="#l234">234 </a></span> 
<span class="c2html-lineno"><a name="l235" href="#l235">235 </a></span> <span class="c2html-keyword">char</span>* util_parent_path(<span class="c2html-keyword">char</span> *path) {
<span class="c2html-lineno"><a name="l236" href="#l236">236 </a></span>     <span class="c2html-keyword">char</span> *name = util_resource_name(path);
<span class="c2html-lineno"><a name="l237" href="#l237">237 </a></span>     <span class="c2html-type">size_t</span> namelen = strlen(name);
<span class="c2html-lineno"><a name="l238" href="#l238">238 </a></span>     <span class="c2html-type">size_t</span> pathlen = strlen(path);
<span class="c2html-lineno"><a name="l239" href="#l239">239 </a></span>     <span class="c2html-type">size_t</span> parentlen = pathlen - namelen;
<span class="c2html-lineno"><a name="l240" href="#l240">240 </a></span>     <span class="c2html-keyword">char</span> *parent = malloc(parentlen + <span class="c2html-macroconst">1</span>);
<span class="c2html-lineno"><a name="l241" href="#l241">241 </a></span>     memcpy(parent, path, parentlen);
<span class="c2html-lineno"><a name="l242" href="#l242">242 </a></span>     parent[parentlen] = <span class="c2html-string">'\0'</span>;
<span class="c2html-lineno"><a name="l243" href="#l243">243 </a></span>     <span class="c2html-keyword">return</span> parent;
<span class="c2html-lineno"><a name="l244" href="#l244">244 </a></span> }
<span class="c2html-lineno"><a name="l245" href="#l245">245 </a></span> 
<span class="c2html-lineno"><a name="l246" href="#l246">246 </a></span> 
<span class="c2html-lineno"><a name="l247" href="#l247">247 </a></span> <span class="c2html-keyword">char</span>* util_xml_get_text(xmlNode *elm) {
<span class="c2html-lineno"><a name="l248" href="#l248">248 </a></span>     xmlNode *node = elm-&gt;children;
<span class="c2html-lineno"><a name="l249" href="#l249">249 </a></span>     <span class="c2html-keyword">while</span>(node) {
<span class="c2html-lineno"><a name="l250" href="#l250">250 </a></span>         <span class="c2html-keyword">if</span>(node-&gt;type == <span class="c2html-macroconst">XML_TEXT_NODE</span>) {
<span class="c2html-lineno"><a name="l251" href="#l251">251 </a></span>             <span class="c2html-keyword">return</span> (<span class="c2html-keyword">char</span>*)node-&gt;content;
<span class="c2html-lineno"><a name="l252" href="#l252">252 </a></span>         }
<span class="c2html-lineno"><a name="l253" href="#l253">253 </a></span>         node = node-&gt;next;
<span class="c2html-lineno"><a name="l254" href="#l254">254 </a></span>     }
<span class="c2html-lineno"><a name="l255" href="#l255">255 </a></span>     <span class="c2html-keyword">return</span> <span class="c2html-macroconst">NULL</span>;
<span class="c2html-lineno"><a name="l256" href="#l256">256 </a></span> }
<span class="c2html-lineno"><a name="l257" href="#l257">257 </a></span> 
<span class="c2html-lineno"><a name="l258" href="#l258">258 </a></span> 
<span class="c2html-lineno"><a name="l259" href="#l259">259 </a></span> <span class="c2html-keyword">char</span>* util_base64decode(<span class="c2html-keyword">char</span> *in) {
<span class="c2html-lineno"><a name="l260" href="#l260">260 </a></span>     <span class="c2html-keyword">int</span> len = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l261" href="#l261">261 </a></span>     <span class="c2html-keyword">return</span> util_base64decode_len(in, &len);
<span class="c2html-lineno"><a name="l262" href="#l262">262 </a></span> }
<span class="c2html-lineno"><a name="l263" href="#l263">263 </a></span> 
<span class="c2html-lineno"><a name="l264" href="#l264">264 </a></span> <span class="c2html-keyword">char</span>* util_base64decode_len(<span class="c2html-keyword">char</span>* in, <span class="c2html-keyword">int</span> *outlen) {
<span class="c2html-lineno"><a name="l265" href="#l265">265 </a></span>     <span class="c2html-type">size_t</span> len = strlen(in);
<span class="c2html-lineno"><a name="l266" href="#l266">266 </a></span>     <span class="c2html-keyword">char</span> *out = calloc(<span class="c2html-macroconst">1</span>, len);
<span class="c2html-lineno"><a name="l267" href="#l267">267 </a></span>     
<span class="c2html-lineno"><a name="l268" href="#l268">268 </a></span>     <span class="c2html-macroconst">BIO</span>* b = BIO_new_mem_buf(in, len);
<span class="c2html-lineno"><a name="l269" href="#l269">269 </a></span>     <span class="c2html-macroconst">BIO</span> *d = BIO_new(BIO_f_base64());
<span class="c2html-lineno"><a name="l270" href="#l270">270 </a></span>     BIO_set_flags(d, <span class="c2html-macroconst">BIO_FLAGS_BASE64_NO_NL</span>);
<span class="c2html-lineno"><a name="l271" href="#l271">271 </a></span>     b = BIO_push(d, b);
<span class="c2html-lineno"><a name="l272" href="#l272">272 </a></span> 
<span class="c2html-lineno"><a name="l273" href="#l273">273 </a></span>     *outlen = BIO_read(b, out, len);
<span class="c2html-lineno"><a name="l274" href="#l274">274 </a></span>     BIO_free_all(b);
<span class="c2html-lineno"><a name="l275" href="#l275">275 </a></span>     
<span class="c2html-lineno"><a name="l276" href="#l276">276 </a></span>     <span class="c2html-keyword">return</span> out;
<span class="c2html-lineno"><a name="l277" href="#l277">277 </a></span> }
<span class="c2html-lineno"><a name="l278" href="#l278">278 </a></span> 
<span class="c2html-lineno"><a name="l279" href="#l279">279 </a></span> <span class="c2html-keyword">char</span>* util_base64encode(<span class="c2html-keyword">char</span> *in, <span class="c2html-type">size_t</span> len) { 
<span class="c2html-lineno"><a name="l280" href="#l280">280 </a></span>     <span class="c2html-macroconst">BIO</span> *b;
<span class="c2html-lineno"><a name="l281" href="#l281">281 </a></span>     <span class="c2html-macroconst">BIO</span> *e;
<span class="c2html-lineno"><a name="l282" href="#l282">282 </a></span>     <span class="c2html-macroconst">BUF_MEM</span> *mem;
<span class="c2html-lineno"><a name="l283" href="#l283">283 </a></span> 
<span class="c2html-lineno"><a name="l284" href="#l284">284 </a></span>     e = BIO_new(BIO_f_base64());
<span class="c2html-lineno"><a name="l285" href="#l285">285 </a></span>     b = BIO_new(BIO_s_mem());
<span class="c2html-lineno"><a name="l286" href="#l286">286 </a></span>     
<span class="c2html-lineno"><a name="l287" href="#l287">287 </a></span>     e = BIO_push(e, b);
<span class="c2html-lineno"><a name="l288" href="#l288">288 </a></span>     BIO_write(e, in, len);
<span class="c2html-lineno"><a name="l289" href="#l289">289 </a></span>     BIO_flush(e);
<span class="c2html-lineno"><a name="l290" href="#l290">290 </a></span>     
<span class="c2html-lineno"><a name="l291" href="#l291">291 </a></span>     BIO_get_mem_ptr(e, &mem);
<span class="c2html-lineno"><a name="l292" href="#l292">292 </a></span>     <span class="c2html-keyword">char</span> *out = malloc(mem-&gt;length);
<span class="c2html-lineno"><a name="l293" href="#l293">293 </a></span>     memcpy(out, mem-&gt;data, mem-&gt;length -<span class="c2html-macroconst">1</span>);
<span class="c2html-lineno"><a name="l294" href="#l294">294 </a></span>     out[mem-&gt;length - <span class="c2html-macroconst">1</span>] = <span class="c2html-string">'\0'</span>;
<span class="c2html-lineno"><a name="l295" href="#l295">295 </a></span> 
<span class="c2html-lineno"><a name="l296" href="#l296">296 </a></span>     BIO_free_all(e);
<span class="c2html-lineno"><a name="l297" href="#l297">297 </a></span> 
<span class="c2html-lineno"><a name="l298" href="#l298">298 </a></span>     <span class="c2html-keyword">return</span> out;
<span class="c2html-lineno"><a name="l299" href="#l299">299 </a></span> }
<span class="c2html-lineno"><a name="l300" href="#l300">300 </a></span> 
<span class="c2html-lineno"><a name="l301" href="#l301">301 </a></span> <span class="c2html-keyword">char</span>* util_encrypt_str(DavSession *sn, <span class="c2html-keyword">char</span> *str, <span class="c2html-keyword">char</span> *key) {
<span class="c2html-lineno"><a name="l302" href="#l302">302 </a></span>     DavKey *k = dav_context_get_key(sn-&gt;context, key);
<span class="c2html-lineno"><a name="l303" href="#l303">303 </a></span>     <span class="c2html-keyword">if</span>(!k) {
<span class="c2html-lineno"><a name="l304" href="#l304">304 </a></span>         <span class="c2html-comment">// TODO: session error</span>
<span class="c2html-lineno"><a name="l305" href="#l305">305 </a></span>         <span class="c2html-keyword">return</span> <span class="c2html-macroconst">NULL</span>;
<span class="c2html-lineno"><a name="l306" href="#l306">306 </a></span>     }
<span class="c2html-lineno"><a name="l307" href="#l307">307 </a></span>     
<span class="c2html-lineno"><a name="l308" href="#l308">308 </a></span>     <span class="c2html-keyword">char</span> *enc_str = aes_encrypt(str, k);
<span class="c2html-lineno"><a name="l309" href="#l309">309 </a></span>     <span class="c2html-keyword">char</span> *ret_str = dav_session_strdup(sn, enc_str);
<span class="c2html-lineno"><a name="l310" href="#l310">310 </a></span>     free(enc_str);
<span class="c2html-lineno"><a name="l311" href="#l311">311 </a></span>     <span class="c2html-keyword">return</span> ret_str;
<span class="c2html-lineno"><a name="l312" href="#l312">312 </a></span> }
<span class="c2html-lineno"><a name="l313" href="#l313">313 </a></span> 
<span class="c2html-lineno"><a name="l314" href="#l314">314 </a></span> <span class="c2html-comment">/* commented out for testing reasons */</span>
<span class="c2html-lineno"><a name="l315" href="#l315">315 </a></span> <span class="c2html-comment">/*</span>
<span class="c2html-lineno"><a name="l316" href="#l316">316 </a></span> <span class="c2html-comment">char* util_decrypt_str(DavSession *sn, char *str, char *key) {</span>
<span class="c2html-lineno"><a name="l317" href="#l317">317 </a></span> <span class="c2html-comment">    DavKey *k = dav_context_get_key(sn-&gt;context, key);</span>
<span class="c2html-lineno"><a name="l318" href="#l318">318 </a></span> <span class="c2html-comment">    if(!k) {</span>
<span class="c2html-lineno"><a name="l319" href="#l319">319 </a></span> <span class="c2html-comment">        // TODO: session error</span>
<span class="c2html-lineno"><a name="l320" href="#l320">320 </a></span> <span class="c2html-comment">        return NULL;</span>
<span class="c2html-lineno"><a name="l321" href="#l321">321 </a></span> <span class="c2html-comment">    }</span>
<span class="c2html-lineno"><a name="l322" href="#l322">322 </a></span> <span class="c2html-comment">    </span>
<span class="c2html-lineno"><a name="l323" href="#l323">323 </a></span> <span class="c2html-comment">    char *dec_str = aes_decrypt(str, k);</span>
<span class="c2html-lineno"><a name="l324" href="#l324">324 </a></span> <span class="c2html-comment">    char *ret_str = dav_session_strdup(sn, dec_str);</span>
<span class="c2html-lineno"><a name="l325" href="#l325">325 </a></span> <span class="c2html-comment">    free(dec_str);</span>
<span class="c2html-lineno"><a name="l326" href="#l326">326 </a></span> <span class="c2html-comment">    return ret_str;</span>
<span class="c2html-lineno"><a name="l327" href="#l327">327 </a></span> <span class="c2html-comment">}</span>
<span class="c2html-lineno"><a name="l328" href="#l328">328 </a></span> <span class="c2html-comment">*/</span>
<span class="c2html-lineno"><a name="l329" href="#l329">329 </a></span> <span class="c2html-keyword">char</span>* util_random_str() {
<span class="c2html-lineno"><a name="l330" href="#l330">330 </a></span>     <span class="c2html-keyword">unsigned</span> <span class="c2html-keyword">char</span> *str = malloc(<span class="c2html-macroconst">25</span>);
<span class="c2html-lineno"><a name="l331" href="#l331">331 </a></span>     str[<span class="c2html-macroconst">24</span>] = <span class="c2html-string">'\0'</span>;
<span class="c2html-lineno"><a name="l332" href="#l332">332 </a></span>     
<span class="c2html-lineno"><a name="l333" href="#l333">333 </a></span>     <span class="c2html-type">sstr_t</span> t = <span class="c2html-macroconst">S</span>(
<span class="c2html-lineno"><a name="l334" href="#l334">334 </a></span>             <span class="c2html-string">"01234567890"</span>
<span class="c2html-lineno"><a name="l335" href="#l335">335 </a></span>             <span class="c2html-string">"abcdefghijklmnopqrstuvwxyz"</span>
<span class="c2html-lineno"><a name="l336" href="#l336">336 </a></span>             <span class="c2html-string">"ABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>);
<span class="c2html-lineno"><a name="l337" href="#l337">337 </a></span>     <span class="c2html-keyword">const</span> <span class="c2html-keyword">unsigned</span> <span class="c2html-keyword">char</span> *table = (<span class="c2html-keyword">const</span> <span class="c2html-keyword">unsigned</span> <span class="c2html-keyword">char</span>*)t.ptr;
<span class="c2html-lineno"><a name="l338" href="#l338">338 </a></span>     
<span class="c2html-lineno"><a name="l339" href="#l339">339 </a></span>     RAND_pseudo_bytes(str, <span class="c2html-macroconst">24</span>);
<span class="c2html-lineno"><a name="l340" href="#l340">340 </a></span>     <span class="c2html-keyword">for</span>(<span class="c2html-keyword">int</span> i=<span class="c2html-macroconst">0</span>;i&lt;<span class="c2html-macroconst">24</span>;i++) {
<span class="c2html-lineno"><a name="l341" href="#l341">341 </a></span>         <span class="c2html-keyword">int</span> c = str[i] % t.length;
<span class="c2html-lineno"><a name="l342" href="#l342">342 </a></span>         str[i] = table[c];
<span class="c2html-lineno"><a name="l343" href="#l343">343 </a></span>     }
<span class="c2html-lineno"><a name="l344" href="#l344">344 </a></span>     
<span class="c2html-lineno"><a name="l345" href="#l345">345 </a></span>     <span class="c2html-keyword">return</span> (<span class="c2html-keyword">char</span>*)str;
<span class="c2html-lineno"><a name="l346" href="#l346">346 </a></span> }
<span class="c2html-lineno"><a name="l347" href="#l347">347 </a></span> 
<span class="c2html-lineno"><a name="l348" href="#l348">348 </a></span> <span class="c2html-comment">/*</span>
<span class="c2html-lineno"><a name="l349" href="#l349">349 </a></span> <span class="c2html-comment"> * gets a substring from 0 to the appearance of the token</span>
<span class="c2html-lineno"><a name="l350" href="#l350">350 </a></span> <span class="c2html-comment"> * tokens are separated by space</span>
<span class="c2html-lineno"><a name="l351" href="#l351">351 </a></span> <span class="c2html-comment"> * sets sub to the substring and returns the remaining string</span>
<span class="c2html-lineno"><a name="l352" href="#l352">352 </a></span> <span class="c2html-comment"> */</span>
<span class="c2html-lineno"><a name="l353" href="#l353">353 </a></span> <span class="c2html-type">sstr_t</span> util_getsubstr_until_token(<span class="c2html-type">sstr_t</span> str, <span class="c2html-type">sstr_t</span> token, <span class="c2html-type">sstr_t</span> *sub) {  
<span class="c2html-lineno"><a name="l354" href="#l354">354 </a></span>     <span class="c2html-keyword">int</span> i;
<span class="c2html-lineno"><a name="l355" href="#l355">355 </a></span>     <span class="c2html-keyword">int</span> token_start = -<span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l356" href="#l356">356 </a></span>     <span class="c2html-keyword">int</span> token_end = -<span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l357" href="#l357">357 </a></span>     <span class="c2html-keyword">for</span>(i=<span class="c2html-macroconst">0</span>;i&lt;=str.length;i++) {
<span class="c2html-lineno"><a name="l358" href="#l358">358 </a></span>         <span class="c2html-keyword">int</span> c;
<span class="c2html-lineno"><a name="l359" href="#l359">359 </a></span>         <span class="c2html-keyword">if</span>(i == str.length) {
<span class="c2html-lineno"><a name="l360" href="#l360">360 </a></span>             c = <span class="c2html-string">' '</span>;
<span class="c2html-lineno"><a name="l361" href="#l361">361 </a></span>         } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l362" href="#l362">362 </a></span>             c = str.ptr[i];
<span class="c2html-lineno"><a name="l363" href="#l363">363 </a></span>         }
<span class="c2html-lineno"><a name="l364" href="#l364">364 </a></span>         <span class="c2html-keyword">if</span>(c &lt; <span class="c2html-macroconst">33</span>) {
<span class="c2html-lineno"><a name="l365" href="#l365">365 </a></span>             <span class="c2html-keyword">if</span>(token_start != -<span class="c2html-macroconst">1</span>) {
<span class="c2html-lineno"><a name="l366" href="#l366">366 </a></span>                 token_end = i;
<span class="c2html-lineno"><a name="l367" href="#l367">367 </a></span>                 <span class="c2html-type">size_t</span> len = token_end - token_start;
<span class="c2html-lineno"><a name="l368" href="#l368">368 </a></span>                 <span class="c2html-type">sstr_t</span> tk = sstrsubsl(str, token_start, len);
<span class="c2html-lineno"><a name="l369" href="#l369">369 </a></span>                 <span class="c2html-comment">//printf("token: {%.*s}\n", token.length, token.ptr);</span>
<span class="c2html-lineno"><a name="l370" href="#l370">370 </a></span>                 <span class="c2html-keyword">if</span>(!sstrcmp(tk, token)) {
<span class="c2html-lineno"><a name="l371" href="#l371">371 </a></span>                     *sub = sstrtrim(sstrsubsl(str, <span class="c2html-macroconst">0</span>, token_start));
<span class="c2html-lineno"><a name="l372" href="#l372">372 </a></span>                     <span class="c2html-keyword">break</span>;
<span class="c2html-lineno"><a name="l373" href="#l373">373 </a></span>                 }
<span class="c2html-lineno"><a name="l374" href="#l374">374 </a></span>                 token_start = -<span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l375" href="#l375">375 </a></span>                 token_end = -<span class="c2html-macroconst">1</span>;
<span class="c2html-lineno"><a name="l376" href="#l376">376 </a></span>             }
<span class="c2html-lineno"><a name="l377" href="#l377">377 </a></span>         } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l378" href="#l378">378 </a></span>             <span class="c2html-keyword">if</span>(token_start == -<span class="c2html-macroconst">1</span>) {
<span class="c2html-lineno"><a name="l379" href="#l379">379 </a></span>                 token_start = i;
<span class="c2html-lineno"><a name="l380" href="#l380">380 </a></span>             }
<span class="c2html-lineno"><a name="l381" href="#l381">381 </a></span>         }
<span class="c2html-lineno"><a name="l382" href="#l382">382 </a></span>     }
<span class="c2html-lineno"><a name="l383" href="#l383">383 </a></span>     
<span class="c2html-lineno"><a name="l384" href="#l384">384 </a></span>     <span class="c2html-keyword">if</span>(i &lt; str.length) {
<span class="c2html-lineno"><a name="l385" href="#l385">385 </a></span>         <span class="c2html-keyword">return</span> sstrtrim(sstrsubs(str, i));
<span class="c2html-lineno"><a name="l386" href="#l386">386 </a></span>     } <span class="c2html-keyword">else</span> {
<span class="c2html-lineno"><a name="l387" href="#l387">387 </a></span>         str.ptr = <span class="c2html-macroconst">NULL</span>;
<span class="c2html-lineno"><a name="l388" href="#l388">388 </a></span>         str.length = <span class="c2html-macroconst">0</span>;
<span class="c2html-lineno"><a name="l389" href="#l389">389 </a></span>         <span class="c2html-keyword">return</span> str;
<span class="c2html-lineno"><a name="l390" href="#l390">390 </a></span>     }
<span class="c2html-lineno"><a name="l391" href="#l391">391 </a></span> }
</pre>
  </body>
</html>

mercurial