⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conf.c

📁 openssl是ssl的开源项目
💻 C
📖 第 1 页 / 共 2 页
字号:
/* crypto/conf/conf.c *//* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * 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 (tjh@cryptsoft.com). *  * 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 (eay@cryptsoft.com)" *    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 (tjh@cryptsoft.com)" *  * 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.] */#include <stdio.h>#include <errno.h>#include "cryptlib.h"#include "stack.h"#include "lhash.h"#include "conf.h"#include "buffer.h"#include "err.h"#include "conf_lcl.h"#ifndef NOPROTOstatic void value_free_hash(CONF_VALUE *a, LHASH *conf);static void value_free_stack(CONF_VALUE *a,LHASH *conf);static unsigned long hash(CONF_VALUE *v);static int cmp(CONF_VALUE *a,CONF_VALUE *b);static char *eat_ws(char *p);static char *eat_alpha_numeric(char *p);static void clear_comments(char *p);static int str_copy(LHASH *conf,char *section,char **to, char *from);static char *scan_quote(char *p);static CONF_VALUE *new_section(LHASH *conf,char *section);static CONF_VALUE *get_section(LHASH *conf,char *section);#elsestatic void value_free_hash();static void value_free_stack();static unsigned long hash();static int cmp();static char *eat_ws();static char *eat_alpha_numeric();static void clear_comments();static int str_copy();static char *scan_quote();static CONF_VALUE *new_section();static CONF_VALUE *get_section();#endif#define scan_esc(p)	((((p)[1] == '\0')?(p++):(p+=2)),p)char *CONF_version="CONF part of OpenSSL 0.9.1c 23-Dec-1998";LHASH *CONF_load(h,file,line)LHASH *h;char *file;long *line;	{	LHASH *ret=NULL;	FILE *in=NULL;#define BUFSIZE	512	char btmp[16];	int bufnum=0,i,ii;	BUF_MEM *buff=NULL;	char *s,*p,*end;	int again,n;	long eline=0;	CONF_VALUE *v=NULL,*vv,*tv;	CONF_VALUE *sv=NULL;	char *section=NULL,*buf;	STACK *section_sk=NULL,*ts;	char *start,*psection,*pname;	if ((buff=BUF_MEM_new()) == NULL)		{		CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);		goto err;		}	in=fopen(file,"rb");	if (in == NULL)		{		SYSerr(SYS_F_FOPEN,get_last_sys_error());		ERR_set_error_data(BUF_strdup(file),			ERR_TXT_MALLOCED|ERR_TXT_STRING);		CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);		goto err;		}	section=(char *)Malloc(10);	if (section == NULL)		{		CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);		goto err;		}	strcpy(section,"default");	if (h == NULL)		{		if ((ret=lh_new(hash,cmp)) == NULL)			{			CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);			goto err;			}		}	else		ret=h;	sv=new_section(ret,section);	if (sv == NULL)		{		CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);		goto err;		}	section_sk=(STACK *)sv->value;	bufnum=0;	for (;;)		{		again=0;		if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))			{			CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);			goto err;			}		p= &(buff->data[bufnum]);		*p='\0';		fgets(p,BUFSIZE-1,in);		p[BUFSIZE-1]='\0';		ii=i=strlen(p);		if (i == 0) break;		while (i > 0)			{			if ((p[i-1] != '\r') && (p[i-1] != '\n'))				break;			else				i--;			}		/* we removed some trailing stuff so there is a new		 * line on the end. */		if (i == ii)			again=1; /* long line */		else			{			p[i]='\0';			eline++; /* another input line */			}		/* we now have a line with trailing \r\n removed */		/* i is the number of bytes */		bufnum+=i;		v=NULL;		/* check for line continuation */		if (bufnum >= 1)			{			/* If we have bytes and the last char '\\' and			 * second last char is not '\\' */			p= &(buff->data[bufnum-1]);			if (	IS_ESC(p[0]) &&				((bufnum <= 1) || !IS_ESC(p[-1])))				{				bufnum--;				again=1;				}			}		if (again) continue;		bufnum=0;		buf=buff->data;		clear_comments(buf);		n=strlen(buf);		s=eat_ws(buf);		if (IS_EOF(*s)) continue; /* blank line */		if (*s == '[')			{			char *ss;			s++;			start=eat_ws(s);			ss=start;again:			end=eat_alpha_numeric(ss);			p=eat_ws(end);			if (*p != ']')				{				if (*p != '\0')					{					ss=p;					goto again;					}				CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET);				goto err;				}			*end='\0';			if (!str_copy(ret,NULL,&section,start)) goto err;			if ((sv=get_section(ret,section)) == NULL)				sv=new_section(ret,section);			if (sv == NULL)				{				CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);				goto err;				}			section_sk=(STACK *)sv->value;			continue;			}		else			{			pname=s;			psection=NULL;			end=eat_alpha_numeric(s);			if ((end[0] == ':') && (end[1] == ':'))				{				*end='\0';				end+=2;				psection=pname;				pname=end;				end=eat_alpha_numeric(end);				}			p=eat_ws(end);			if (*p != '=')				{				CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN);				goto err;				}			*end='\0';			p++;			start=eat_ws(p);			while (!IS_EOF(*p))				p++;			p--;			while ((p != start) && (IS_WS(*p)))				p--;			p++;			*p='\0';			if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)				{				CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);				goto err;				}			if (psection == NULL) psection=section;			v->name=(char *)Malloc(strlen(pname)+1);			v->value=NULL;			if (v->name == NULL)				{				CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);				goto err;				}			strcpy(v->name,pname);			if (!str_copy(ret,psection,&(v->value),start)) goto err;			if (strcmp(psection,section) != 0)				{				if ((tv=get_section(ret,psection))					== NULL)					tv=new_section(ret,psection);				if (tv == NULL)					{					CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);					goto err;					}				ts=(STACK *)tv->value;				}			else				{				tv=sv;				ts=section_sk;				}			v->section=tv->section;				if (!sk_push(ts,(char *)v))				{				CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);				goto err;				}			vv=(CONF_VALUE *)lh_insert(ret,(char *)v);			if (vv != NULL)				{				sk_delete_ptr(ts,(char *)vv);				Free(vv->name);				Free(vv->value);				Free(vv);				}			v=NULL;			}		}	if (buff != NULL) BUF_MEM_free(buff);	if (section != NULL) Free(section);	if (in != NULL) fclose(in);	return(ret);err:	if (buff != NULL) BUF_MEM_free(buff);	if (section != NULL) Free(section);	if (line != NULL) *line=eline;	sprintf(btmp,"%ld",eline);	ERR_add_error_data(2,"line ",btmp);	if (in != NULL) fclose(in);	if ((h != ret) && (ret != NULL)) CONF_free(ret);	if (v != NULL)		{		if (v->name != NULL) Free(v->name);		if (v->value != NULL) Free(v->value);		if (v != NULL) Free(v);		}	return(NULL);	}		char *CONF_get_string(conf,section,name)LHASH *conf;char *section;char *name;	{	CONF_VALUE *v,vv;	char *p;	if (name == NULL) return(NULL);	if (conf != NULL)		{		if (section != NULL)			{			vv.name=name;			vv.section=section;			v=(CONF_VALUE *)lh_retrieve(conf,(char *)&vv);			if (v != NULL) return(v->value);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -