源文件:
#include"common.h"//常用头文件
#include<openssl/conf.h>//openssl配置文件头文件
int main()
{
CONF *conf;
long line,result;
int ret;
char *p;
BIO *bp;
STACK_OF(CONF_VALUE) *v;//某段所有配置信息指针
CONF_VALUE *one;//单个配置信息指针
int i,num;
conf=NCONF_new(NULL);
#if 0
bp=BIO_new_file("/home/qual/qualSystem/etc/honorCentosMini1/honorCentosMini1.cnf","r");
if(bp==NULL)
{
printf("BIO_new_file error\n");
exit(1);
}
NCONF_load_bio(conf,bp,&line);
#else
ret=NCONF_load(conf,"/home/qual/qualSystem/etc/honorCentosMini1/honorCentosMini1.cnf",&line);
if(ret!=1)
{
printf("NCONF_load error\n");
exit(1);
}
#endif
p=NCONF_get_string(conf,NULL,"ORACLE_NAME");
if(p==NULL)
{
printf("NCONF_get_string error[%d]\n",__LINE__);
//exit(1);
}else
{
printf("%s\n",p);
}
p=NCONF_get_string(conf,"ORACLE","ORACLE_NAME");//获取某段某key,字符串形式
if(p==NULL)
{
printf("NCONF_get_string error\n");
exit(1);
}
printf("[%s]\n",p);
p=NCONF_get_string(conf,"ORACLE","ORACLE_PAWD");
if(p==NULL)
{
printf("NCONF_get_string error\n");
exit(1);
}
printf("[%s]\n",p);
ret=NCONF_get_number_e(conf,"MYSQL","MYSQL_PAWD",&result);//获取某段某key,数字形式
printf("ret[%d]\n",ret);
printf("[%d]\n",result);
ret=NCONF_get_number(conf,"ORACLE","ORACLE_PAWD",&result);//获取某段某key,数字形式
printf("ret[%d]\n",ret);
printf("[%d]\n",result);
v=NCONF_get_section(conf,"MYSQL");//获取某段所有配置
num=sk_CONF_VALUE_num(v);
printf("section MYSQL :\n");
for(i=0;i<num;i++)
{
one=sk_CONF_VALUE_value(v,i);
printf("%s = %s\n",one->name,one->value);
}
NCONF_free(conf);
}
make文件:
TARGET=test143
CC=gcc
BIN=$(APPHOME)/bin
COMINCLUDE=-I$(APPHOME)/programs/c_files/include/
WARN=-g -Wall
THREAD=-lpthread
LIB=-L$(APPHOME)/lib -lpubfun -lcrypto#需要crypto库
$(TARGET):
@echo "/********************BEGIN TO MAKE********************/"
@echo "begin make $@.mak"
$(CC) -o $(TARGET) $(TARGET).c $(COMINCLUDE) $(WARN) $(THREAD) $(LIB)
mv $(TARGET) $(BIN)
@echo "/********************END TO MAKE********************/"
DEPENDANCES:
cd $(APPHOME)/programs/c_files/pubFun &&make