title: Varnish C VRT variables/functions
body: <p>I'm starting to pick up varnish and have come across references to VRT functions in C code in our configuration (and examples on the net) that I can't find documentation on (that I understand, my C knowledge is non-existant). This is the best I can find but it's just the prototypes: <a href="http://fossies.org/dox/varnish-4.0.2/vrt__obj_8h.html#a7b48e87e48beb191015eedf37489a290" rel="nofollow">http://fossies.org/dox/varnish-4.0.2/vrt__obj_8h.html#a7b48e87e48beb191015eedf37489a290</a></p>
  
  <p>So here's an example we use (and which seems to be copypasta from the net as I've found it plenty of times):</p>
  
  <pre><code>C{
    #include &lt;ctype.h&gt;
    static void strtolower(char *c) {
      for (; *c; c++) {
        if (isupper(*c)) {
          *c = tolower(*c);
        }
      }
    }
  }C
  
  sub vcl_recv {
  ...stuff....
  if (req.url ~ "&lt;condition&gt;" &amp;&amp; (&lt;another if condition&gt;)) {
    C{
      strtolower((char *)VRT_r_req_url(sp));
    }C
  }
  </code></pre>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>What is sp here? Where does it come from? It's not defined anywhere nor can I find anything about it</li>
  <li>What does VRT_r_req_url do? Why is it VRT_ prefixed and what is the <em>r</em> (I see there are VRT_l_ functions too). What is this struct it gets data from?</li>
  <li>Are all of these VRT functions parallels to get variables equivalent to say req.url outside of a C block?</li>
  <li><p>Is there documentation somewhere that says what all of these do? For example I've seen this one a few times as well:</p>
  
  <pre><code>sub detectmobile {
    C{
      VRT_SetHdr(sp, HDR_BEREQ, "\020X-Varnish-TeraWurfl:", "no1", vrt_magic_string_end);
    }C
   }
  </code></pre>
  
  <p>So what is HDR_BEREQ and vrt_magic_string_end here?</p></li>
  </ol>