/opensource.apple.com/source/OpenSSL096/OpenSSL096-15/openssl/crypto/conf/conf_def.c
# · C · 730 lines · 618 code · 51 blank · 61 comment · 65 complexity · fd8668154382c15e2e576a758714e741 MD5 · raw file
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>conf_def.c</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">conf_def.c <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/* crypto/conf/conf.c */</span>
- <span class="enscript-comment">/* Copyright (C) 1995-1998 Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (<a href="mailto:tjh@cryptsoft.com">tjh@cryptsoft.com</a>).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * "This product includes cryptographic software written by
- * Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (<a href="mailto:tjh@cryptsoft.com">tjh@cryptsoft.com</a>)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * The licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */</span>
- <span class="enscript-comment">/* Part of the code in here was originally in conf.c, which is now removed */</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><stdio.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><string.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/stack.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/lhash.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/conf.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/conf_api.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"conf_def.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/buffer.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><openssl/err.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"cryptlib.h"</span>
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">eat_ws</span>(CONF *conf, <span class="enscript-type">char</span> *p);
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">eat_alpha_numeric</span>(CONF *conf, <span class="enscript-type">char</span> *p);
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">clear_comments</span>(CONF *conf, <span class="enscript-type">char</span> *p);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">str_copy</span>(CONF *conf,<span class="enscript-type">char</span> *section,<span class="enscript-type">char</span> **to, <span class="enscript-type">char</span> *from);
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">scan_quote</span>(CONF *conf, <span class="enscript-type">char</span> *p);
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">scan_dquote</span>(CONF *conf, <span class="enscript-type">char</span> *p);
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">scan_esc</span>(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
- <span class="enscript-type">static</span> CONF *<span class="enscript-function-name">def_create</span>(CONF_METHOD *meth);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_init_default</span>(CONF *conf);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_init_WIN32</span>(CONF *conf);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_destroy</span>(CONF *conf);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_destroy_data</span>(CONF *conf);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_load</span>(CONF *conf, BIO *bp, <span class="enscript-type">long</span> *eline);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_dump</span>(CONF *conf, BIO *bp);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_is_number</span>(CONF *conf, <span class="enscript-type">char</span> c);
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_to_int</span>(CONF *conf, <span class="enscript-type">char</span> c);
- <span class="enscript-type">const</span> <span class="enscript-type">char</span> *CONF_def_version=<span class="enscript-string">"CONF_def"</span> OPENSSL_VERSION_PTEXT;
- <span class="enscript-type">static</span> CONF_METHOD default_method = {
- <span class="enscript-string">"OpenSSL default"</span>,
- def_create,
- def_init_default,
- def_destroy,
- def_destroy_data,
- def_load,
- def_dump,
- def_is_number,
- def_to_int
- };
- <span class="enscript-type">static</span> CONF_METHOD WIN32_method = {
- <span class="enscript-string">"WIN32"</span>,
- def_create,
- def_init_WIN32,
- def_destroy,
- def_destroy_data,
- def_load,
- def_dump,
- def_is_number,
- def_to_int
- };
- CONF_METHOD *<span class="enscript-function-name">NCONF_default</span>()
- {
- <span class="enscript-keyword">return</span> &default_method;
- }
- CONF_METHOD *<span class="enscript-function-name">NCONF_WIN32</span>()
- {
- <span class="enscript-keyword">return</span> &WIN32_method;
- }
- <span class="enscript-type">static</span> CONF *<span class="enscript-function-name">def_create</span>(CONF_METHOD *meth)
- {
- CONF *ret;
- ret = (CONF *)OPENSSL_malloc(<span class="enscript-keyword">sizeof</span>(CONF) + <span class="enscript-keyword">sizeof</span>(<span class="enscript-type">unsigned</span> <span class="enscript-type">short</span> *));
- <span class="enscript-keyword">if</span> (ret)
- <span class="enscript-keyword">if</span> (meth->init(ret) == 0)
- {
- OPENSSL_free(ret);
- ret = NULL;
- }
- <span class="enscript-keyword">return</span> ret;
- }
-
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_init_default</span>(CONF *conf)
- {
- <span class="enscript-keyword">if</span> (conf == NULL)
- <span class="enscript-keyword">return</span> 0;
- conf->meth = &default_method;
- conf->meth_data = (<span class="enscript-type">void</span> *)CONF_type_default;
- conf->data = NULL;
- <span class="enscript-keyword">return</span> 1;
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_init_WIN32</span>(CONF *conf)
- {
- <span class="enscript-keyword">if</span> (conf == NULL)
- <span class="enscript-keyword">return</span> 0;
- conf->meth = &WIN32_method;
- conf->meth_data = (<span class="enscript-type">void</span> *)CONF_type_win32;
- conf->data = NULL;
- <span class="enscript-keyword">return</span> 1;
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_destroy</span>(CONF *conf)
- {
- <span class="enscript-keyword">if</span> (def_destroy_data(conf))
- {
- OPENSSL_free(conf);
- <span class="enscript-keyword">return</span> 1;
- }
- <span class="enscript-keyword">return</span> 0;
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_destroy_data</span>(CONF *conf)
- {
- <span class="enscript-keyword">if</span> (conf == NULL)
- <span class="enscript-keyword">return</span> 0;
- _CONF_free_data(conf);
- <span class="enscript-keyword">return</span> 1;
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_load</span>(CONF *conf, BIO *in, <span class="enscript-type">long</span> *line)
- {
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">BUFSIZE</span> 512
- <span class="enscript-type">int</span> bufnum=0,i,ii;
- BUF_MEM *buff=NULL;
- <span class="enscript-type">char</span> *s,*p,*end;
- <span class="enscript-type">int</span> again,n;
- <span class="enscript-type">long</span> eline=0;
- <span class="enscript-type">char</span> btmp[DECIMAL_SIZE(eline)+1];
- CONF_VALUE *v=NULL,*tv;
- CONF_VALUE *sv=NULL;
- <span class="enscript-type">char</span> *section=NULL,*buf;
- STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
- <span class="enscript-type">char</span> *start,*psection,*pname;
- <span class="enscript-type">void</span> *h = (<span class="enscript-type">void</span> *)(conf->data);
- <span class="enscript-keyword">if</span> ((buff=BUF_MEM_new()) == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- section=(<span class="enscript-type">char</span> *)OPENSSL_malloc(10);
- <span class="enscript-keyword">if</span> (section == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- strcpy(section,<span class="enscript-string">"default"</span>);
- <span class="enscript-keyword">if</span> (_CONF_new_data(conf) == 0)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- sv=_CONF_new_section(conf,section);
- <span class="enscript-keyword">if</span> (sv == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
- bufnum=0;
- again=0;
- <span class="enscript-keyword">for</span> (;;)
- {
- <span class="enscript-keyword">if</span> (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- p= &(buff->data[bufnum]);
- *p=<span class="enscript-string">'\0'</span>;
- BIO_gets(in, p, BUFSIZE-1);
- p[BUFSIZE-1]=<span class="enscript-string">'\0'</span>;
- ii=i=strlen(p);
- <span class="enscript-keyword">if</span> (i == 0 && !again) <span class="enscript-keyword">break</span>;
- again=0;
- <span class="enscript-keyword">while</span> (i > 0)
- {
- <span class="enscript-keyword">if</span> ((p[i-1] != <span class="enscript-string">'\r'</span>) && (p[i-1] != <span class="enscript-string">'\n'</span>))
- <span class="enscript-keyword">break</span>;
- <span class="enscript-keyword">else</span>
- i--;
- }
- <span class="enscript-comment">/* we removed some trailing stuff so there is a new
- * line on the end. */</span>
- <span class="enscript-keyword">if</span> (ii && i == ii)
- again=1; <span class="enscript-comment">/* long line */</span>
- <span class="enscript-keyword">else</span>
- {
- p[i]=<span class="enscript-string">'\0'</span>;
- eline++; <span class="enscript-comment">/* another input line */</span>
- }
- <span class="enscript-comment">/* we now have a line with trailing \r\n removed */</span>
- <span class="enscript-comment">/* i is the number of bytes */</span>
- bufnum+=i;
- v=NULL;
- <span class="enscript-comment">/* check for line continuation */</span>
- <span class="enscript-keyword">if</span> (bufnum >= 1)
- {
- <span class="enscript-comment">/* If we have bytes and the last char '\\' and
- * second last char is not '\\' */</span>
- p= &(buff->data[bufnum-1]);
- <span class="enscript-keyword">if</span> (IS_ESC(conf,p[0]) &&
- ((bufnum <= 1) || !IS_ESC(conf,p[-1])))
- {
- bufnum--;
- again=1;
- }
- }
- <span class="enscript-keyword">if</span> (again) <span class="enscript-keyword">continue</span>;
- bufnum=0;
- buf=buff->data;
- clear_comments(conf, buf);
- n=strlen(buf);
- s=eat_ws(conf, buf);
- <span class="enscript-keyword">if</span> (IS_EOF(conf,*s)) <span class="enscript-keyword">continue</span>; <span class="enscript-comment">/* blank line */</span>
- <span class="enscript-keyword">if</span> (*s == <span class="enscript-string">'['</span>)
- {
- <span class="enscript-type">char</span> *ss;
- s++;
- start=eat_ws(conf, s);
- ss=start;
- <span class="enscript-reference">again</span>:
- end=eat_alpha_numeric(conf, ss);
- p=eat_ws(conf, end);
- <span class="enscript-keyword">if</span> (*p != <span class="enscript-string">']'</span>)
- {
- <span class="enscript-keyword">if</span> (*p != <span class="enscript-string">'\0'</span>)
- {
- ss=p;
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">again</span>;
- }
- CONFerr(CONF_F_CONF_LOAD_BIO,
- CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- *end=<span class="enscript-string">'\0'</span>;
- <span class="enscript-keyword">if</span> (!str_copy(conf,NULL,&section,start)) <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- <span class="enscript-keyword">if</span> ((sv=_CONF_get_section(conf,section)) == NULL)
- sv=_CONF_new_section(conf,section);
- <span class="enscript-keyword">if</span> (sv == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
- <span class="enscript-keyword">continue</span>;
- }
- <span class="enscript-keyword">else</span>
- {
- pname=s;
- psection=NULL;
- end=eat_alpha_numeric(conf, s);
- <span class="enscript-keyword">if</span> ((end[0] == <span class="enscript-string">':'</span>) && (end[1] == <span class="enscript-string">':'</span>))
- {
- *end=<span class="enscript-string">'\0'</span>;
- end+=2;
- psection=pname;
- pname=end;
- end=eat_alpha_numeric(conf, end);
- }
- p=eat_ws(conf, end);
- <span class="enscript-keyword">if</span> (*p != <span class="enscript-string">'='</span>)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- CONF_R_MISSING_EQUAL_SIGN);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- *end=<span class="enscript-string">'\0'</span>;
- p++;
- start=eat_ws(conf, p);
- <span class="enscript-keyword">while</span> (!IS_EOF(conf,*p))
- p++;
- p--;
- <span class="enscript-keyword">while</span> ((p != start) && (IS_WS(conf,*p)))
- p--;
- p++;
- *p=<span class="enscript-string">'\0'</span>;
- <span class="enscript-keyword">if</span> (!(v=(CONF_VALUE *)OPENSSL_malloc(<span class="enscript-keyword">sizeof</span>(CONF_VALUE))))
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- <span class="enscript-keyword">if</span> (psection == NULL) psection=section;
- v->name=(<span class="enscript-type">char</span> *)OPENSSL_malloc(strlen(pname)+1);
- v->value=NULL;
- <span class="enscript-keyword">if</span> (v->name == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- strcpy(v->name,pname);
- <span class="enscript-keyword">if</span> (!str_copy(conf,psection,&(v->value),start)) <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- <span class="enscript-keyword">if</span> (strcmp(psection,section) != 0)
- {
- <span class="enscript-keyword">if</span> ((tv=_CONF_get_section(conf,psection))
- == NULL)
- tv=_CONF_new_section(conf,psection);
- <span class="enscript-keyword">if</span> (tv == NULL)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- ts=(STACK_OF(CONF_VALUE) *)tv->value;
- }
- <span class="enscript-keyword">else</span>
- {
- tv=sv;
- ts=section_sk;
- }
- #<span class="enscript-reference">if</span> 1
- <span class="enscript-keyword">if</span> (_CONF_add_string(conf, tv, v) == 0)
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- #<span class="enscript-reference">else</span>
- v->section=tv->section;
- <span class="enscript-keyword">if</span> (!sk_CONF_VALUE_push(ts,v))
- {
- CONFerr(CONF_F_CONF_LOAD_BIO,
- ERR_R_MALLOC_FAILURE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- vv=(CONF_VALUE *)lh_insert(conf->data,v);
- <span class="enscript-keyword">if</span> (vv != NULL)
- {
- sk_CONF_VALUE_delete_ptr(ts,vv);
- OPENSSL_free(vv->name);
- OPENSSL_free(vv->value);
- OPENSSL_free(vv);
- }
- #<span class="enscript-reference">endif</span>
- v=NULL;
- }
- }
- <span class="enscript-keyword">if</span> (buff != NULL) BUF_MEM_free(buff);
- <span class="enscript-keyword">if</span> (section != NULL) OPENSSL_free(section);
- <span class="enscript-keyword">return</span>(1);
- <span class="enscript-reference">err</span>:
- <span class="enscript-keyword">if</span> (buff != NULL) BUF_MEM_free(buff);
- <span class="enscript-keyword">if</span> (section != NULL) OPENSSL_free(section);
- <span class="enscript-keyword">if</span> (line != NULL) *line=eline;
- sprintf(btmp,<span class="enscript-string">"%ld"</span>,eline);
- ERR_add_error_data(2,<span class="enscript-string">"line "</span>,btmp);
- <span class="enscript-keyword">if</span> ((h != conf->data) && (conf->data != NULL)) CONF_free(conf->data);
- <span class="enscript-keyword">if</span> (v != NULL)
- {
- <span class="enscript-keyword">if</span> (v->name != NULL) OPENSSL_free(v->name);
- <span class="enscript-keyword">if</span> (v->value != NULL) OPENSSL_free(v->value);
- <span class="enscript-keyword">if</span> (v != NULL) OPENSSL_free(v);
- }
- <span class="enscript-keyword">return</span>(0);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">clear_comments</span>(CONF *conf, <span class="enscript-type">char</span> *p)
- {
- <span class="enscript-type">char</span> *to;
- to=p;
- <span class="enscript-keyword">for</span> (;;)
- {
- <span class="enscript-keyword">if</span> (IS_FCOMMENT(conf,*p))
- {
- *p=<span class="enscript-string">'\0'</span>;
- <span class="enscript-keyword">return</span>;
- }
- <span class="enscript-keyword">if</span> (!IS_WS(conf,*p))
- {
- <span class="enscript-keyword">break</span>;
- }
- p++;
- }
- <span class="enscript-keyword">for</span> (;;)
- {
- <span class="enscript-keyword">if</span> (IS_COMMENT(conf,*p))
- {
- *p=<span class="enscript-string">'\0'</span>;
- <span class="enscript-keyword">return</span>;
- }
- <span class="enscript-keyword">if</span> (IS_DQUOTE(conf,*p))
- {
- p=scan_dquote(conf, p);
- <span class="enscript-keyword">continue</span>;
- }
- <span class="enscript-keyword">if</span> (IS_QUOTE(conf,*p))
- {
- p=scan_quote(conf, p);
- <span class="enscript-keyword">continue</span>;
- }
- <span class="enscript-keyword">if</span> (IS_ESC(conf,*p))
- {
- p=scan_esc(conf,p);
- <span class="enscript-keyword">continue</span>;
- }
- <span class="enscript-keyword">if</span> (IS_EOF(conf,*p))
- <span class="enscript-keyword">return</span>;
- <span class="enscript-keyword">else</span>
- p++;
- }
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">str_copy</span>(CONF *conf, <span class="enscript-type">char</span> *section, <span class="enscript-type">char</span> **pto, <span class="enscript-type">char</span> *from)
- {
- <span class="enscript-type">int</span> q,r,rr=0,to=0,len=0;
- <span class="enscript-type">char</span> *s,*e,*rp,*p,*rrp,*np,*cp,v;
- BUF_MEM *buf;
- <span class="enscript-keyword">if</span> ((buf=BUF_MEM_new()) == NULL) <span class="enscript-keyword">return</span>(0);
- len=strlen(from)+1;
- <span class="enscript-keyword">if</span> (!BUF_MEM_grow(buf,len)) <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- <span class="enscript-keyword">for</span> (;;)
- {
- <span class="enscript-keyword">if</span> (IS_QUOTE(conf,*from))
- {
- q= *from;
- from++;
- <span class="enscript-keyword">while</span> (!IS_EOF(conf,*from) && (*from != q))
- {
- <span class="enscript-keyword">if</span> (IS_ESC(conf,*from))
- {
- from++;
- <span class="enscript-keyword">if</span> (IS_EOF(conf,*from)) <span class="enscript-keyword">break</span>;
- }
- buf->data[to++]= *(from++);
- }
- <span class="enscript-keyword">if</span> (*from == q) from++;
- }
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (IS_DQUOTE(conf,*from))
- {
- q= *from;
- from++;
- <span class="enscript-keyword">while</span> (!IS_EOF(conf,*from))
- {
- <span class="enscript-keyword">if</span> (*from == q)
- {
- <span class="enscript-keyword">if</span> (*(from+1) == q)
- {
- from++;
- }
- <span class="enscript-keyword">else</span>
- {
- <span class="enscript-keyword">break</span>;
- }
- }
- buf->data[to++]= *(from++);
- }
- <span class="enscript-keyword">if</span> (*from == q) from++;
- }
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (IS_ESC(conf,*from))
- {
- from++;
- v= *(from++);
- <span class="enscript-keyword">if</span> (IS_EOF(conf,v)) <span class="enscript-keyword">break</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (v == <span class="enscript-string">'r'</span>) v=<span class="enscript-string">'\r'</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (v == <span class="enscript-string">'n'</span>) v=<span class="enscript-string">'\n'</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (v == <span class="enscript-string">'b'</span>) v=<span class="enscript-string">'\b'</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (v == <span class="enscript-string">'t'</span>) v=<span class="enscript-string">'\t'</span>;
- buf->data[to++]= v;
- }
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (IS_EOF(conf,*from))
- <span class="enscript-keyword">break</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (*from == <span class="enscript-string">'$'</span>)
- {
- <span class="enscript-comment">/* try to expand it */</span>
- rrp=NULL;
- s= &(from[1]);
- <span class="enscript-keyword">if</span> (*s == <span class="enscript-string">'{'</span>)
- q=<span class="enscript-string">'}'</span>;
- <span class="enscript-keyword">else</span> <span class="enscript-keyword">if</span> (*s == <span class="enscript-string">'('</span>)
- q=<span class="enscript-string">')'</span>;
- <span class="enscript-keyword">else</span> q=0;
- <span class="enscript-keyword">if</span> (q) s++;
- cp=section;
- e=np=s;
- <span class="enscript-keyword">while</span> (IS_ALPHA_NUMERIC(conf,*e))
- e++;
- <span class="enscript-keyword">if</span> ((e[0] == <span class="enscript-string">':'</span>) && (e[1] == <span class="enscript-string">':'</span>))
- {
- cp=np;
- rrp=e;
- rr= *e;
- *rrp=<span class="enscript-string">'\0'</span>;
- e+=2;
- np=e;
- <span class="enscript-keyword">while</span> (IS_ALPHA_NUMERIC(conf,*e))
- e++;
- }
- r= *e;
- *e=<span class="enscript-string">'\0'</span>;
- rp=e;
- <span class="enscript-keyword">if</span> (q)
- {
- <span class="enscript-keyword">if</span> (r != q)
- {
- CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- e++;
- }
- <span class="enscript-comment">/* So at this point we have
- * ns which is the start of the name string which is
- * '\0' terminated.
- * cs which is the start of the section string which is
- * '\0' terminated.
- * e is the 'next point after'.
- * r and s are the chars replaced by the '\0'
- * rp and sp is where 'r' and 's' came from.
- */</span>
- p=_CONF_get_string(conf,cp,np);
- <span class="enscript-keyword">if</span> (rrp != NULL) *rrp=rr;
- *rp=r;
- <span class="enscript-keyword">if</span> (p == NULL)
- {
- CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
- <span class="enscript-keyword">goto</span> <span class="enscript-reference">err</span>;
- }
- BUF_MEM_grow(buf,(strlen(p)+len-(e-from)));
- <span class="enscript-keyword">while</span> (*p)
- buf->data[to++]= *(p++);
- from=e;
- }
- <span class="enscript-keyword">else</span>
- buf->data[to++]= *(from++);
- }
- buf->data[to]=<span class="enscript-string">'\0'</span>;
- <span class="enscript-keyword">if</span> (*pto != NULL) OPENSSL_free(*pto);
- *pto=buf->data;
- OPENSSL_free(buf);
- <span class="enscript-keyword">return</span>(1);
- <span class="enscript-reference">err</span>:
- <span class="enscript-keyword">if</span> (buf != NULL) BUF_MEM_free(buf);
- <span class="enscript-keyword">return</span>(0);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">eat_ws</span>(CONF *conf, <span class="enscript-type">char</span> *p)
- {
- <span class="enscript-keyword">while</span> (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
- p++;
- <span class="enscript-keyword">return</span>(p);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">eat_alpha_numeric</span>(CONF *conf, <span class="enscript-type">char</span> *p)
- {
- <span class="enscript-keyword">for</span> (;;)
- {
- <span class="enscript-keyword">if</span> (IS_ESC(conf,*p))
- {
- p=scan_esc(conf,p);
- <span class="enscript-keyword">continue</span>;
- }
- <span class="enscript-keyword">if</span> (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
- <span class="enscript-keyword">return</span>(p);
- p++;
- }
- }
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">scan_quote</span>(CONF *conf, <span class="enscript-type">char</span> *p)
- {
- <span class="enscript-type">int</span> q= *p;
- p++;
- <span class="enscript-keyword">while</span> (!(IS_EOF(conf,*p)) && (*p != q))
- {
- <span class="enscript-keyword">if</span> (IS_ESC(conf,*p))
- {
- p++;
- <span class="enscript-keyword">if</span> (IS_EOF(conf,*p)) <span class="enscript-keyword">return</span>(p);
- }
- p++;
- }
- <span class="enscript-keyword">if</span> (*p == q) p++;
- <span class="enscript-keyword">return</span>(p);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">scan_dquote</span>(CONF *conf, <span class="enscript-type">char</span> *p)
- {
- <span class="enscript-type">int</span> q= *p;
- p++;
- <span class="enscript-keyword">while</span> (!(IS_EOF(conf,*p)))
- {
- <span class="enscript-keyword">if</span> (*p == q)
- {
- <span class="enscript-keyword">if</span> (*(p+1) == q)
- {
- p++;
- }
- <span class="enscript-keyword">else</span>
- {
- <span class="enscript-keyword">break</span>;
- }
- }
- p++;
- }
- <span class="enscript-keyword">if</span> (*p == q) p++;
- <span class="enscript-keyword">return</span>(p);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">dump_value</span>(CONF_VALUE *a, BIO *out)
- {
- <span class="enscript-keyword">if</span> (a->name)
- BIO_printf(out, <span class="enscript-string">"[%s] %s=%s\n"</span>, a->section, a->name, a->value);
- <span class="enscript-keyword">else</span>
- BIO_printf(out, <span class="enscript-string">"[[%s]]\n"</span>, a->section);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_dump</span>(CONF *conf, BIO *out)
- {
- lh_doall_arg(conf->data, (<span class="enscript-type">void</span> (*)())dump_value, out);
- <span class="enscript-keyword">return</span> 1;
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_is_number</span>(CONF *conf, <span class="enscript-type">char</span> c)
- {
- <span class="enscript-keyword">return</span> IS_NUMBER(conf,c);
- }
- <span class="enscript-type">static</span> <span class="enscript-type">int</span> <span class="enscript-function-name">def_to_int</span>(CONF *conf, <span class="enscript-type">char</span> c)
- {
- <span class="enscript-keyword">return</span> c - <span class="enscript-string">'0'</span>;
- }
- </pre>
- <hr />
- </body></html>