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

📄 ospf_nvram.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ospf_nvram.c - OSPF nvram *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01d,14aug03,kkz Changed nvram to ospf_nvram01c,02jun03,agi removed unused functions01b,30may03,agi undefined NVRAM_DEBUG01a,28may03,agi created (ported from RWOS)*//* defines */#define GLOBAL_FILE#define ILLEGAL_SECTION_INDEX 0xff/* includes */#include "stddef.h"#include "stdio.h"#include "string.h"#include "ospf.h"#include "ospf_vnvram.h"#include "taskLib.h"#if defined (__RAM_FILE__)static char *cptr_current_string;#endif#undef NVRAM_DEBUG#ifdef NVRAM_DEBUG#define nvram_printf(_x)    { printf _x; }#else#define nvram_printf(_x)#endif /* nvram_printf */extern BOOLEAN nvram_is_parameter_enabled (char *cptr_parameter_string);/****************************************************************************/static enum TEST read_router_ini_parameters (char *cptr_name_of_ini_file,ULONG location_of_ini_file);static enum TEST router_management_parameters (char *cptr_string_from_config_file,char *cptr_value_string);static BYTE get_section_name (char *cptr_section_name);static enum TEST read_router_ini_section_parameters (char *cptr_name_of_ini_file,ULONG location_of_ini_file,    char *cptr_section_name,void *vptr_location_of_configuration_table);static char *section_name_array[] = {"","","","","","","","","","","","","","",""};static OSPF_CONFIGURATION_TABLE *sptr_configuration_table[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,};#if defined (__RAM_FILE__)static char *find_cr_newline (char *cptr_string_from_config_file);static enum TEST get_string_from_memory_file_image (char *cptr_return_string,USHORT size_of_return_string,        ULONG location_of_ini_file);#else    static enum TEST parse_section_ini_parameters (char *string_from_ini_file,ULONG location_of_ini_file,        void *vptr_location_of_configuration_table);#endif /* __RAM_FILE *//****************************************************************************/enum TEST ospf_initialize_nvram (char *cptr_file_name,ULONG location_of_ini_file,char *cptr_section_name,    void *vptr_location_of_configuration_table){    enum TEST return_code;    static  SEM_ID  nvram_mutex;    OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_initialize_nvram\r\n");    if (nvram_mutex == NULL)        {        nvram_mutex = semMCreate (SEM_Q_FIFO |SEM_DELETE_SAFE );        if (nvram_mutex == NULL)            {            return (FAIL);            }        }    semTake (nvram_mutex, WAIT_FOREVER);    if (cptr_section_name == NULL)        {        return_code = read_router_ini_parameters (cptr_file_name, location_of_ini_file);        }    else        {        return_code = read_router_ini_section_parameters (cptr_file_name, location_of_ini_file,cptr_section_name,            vptr_location_of_configuration_table);        }    memset (section_name_array, 0x00, sizeof (section_name_array));    memset (sptr_configuration_table, 0x00, sizeof (sptr_configuration_table));    ospf_nvram.number_of_configurations = (BYTE)0;    semGive (nvram_mutex);    return (return_code);}/****************************************************************************/static enum TEST read_router_ini_parameters (char *cptr_name_of_ini_file,ULONG location_of_ini_file){    char *cptr_value_string;    char string_from_ini_file[256];#if !defined (__RAM_FILE__)    FILE *filptr_ini_file;#endif    if ((cptr_name_of_ini_file == NULL) && (location_of_ini_file == 0x00000000L))        {        nvram_printf (("NVRAM: No Configuration File Given!\r\n"));        return (FAIL);        }    else        {#if !defined (__RAM_FILE__)        nvram_printf (("NVRAM: File Open\r\n",cptr_name_of_ini_file));        if ((filptr_ini_file =  fopen (cptr_name_of_ini_file, "r")) == NULL)            {            nvram_printf (("NVRAM: Could not find %s file, \r\n",cptr_name_of_ini_file));            return (FAIL);            }#endif        }#if !defined (__RAM_FILE__)    nvram_printf (("NVRAM: Current Configuration Setup in %s\r\n",cptr_name_of_ini_file));#else    nvram_printf (("NVRAM: Current Configuration Setup at %08lx\r\n",location_of_ini_file));#endif    ospf_nvram.current_configuration_section_index = ILLEGAL_SECTION_INDEX;    ospf_nvram.display_configuration_file = TRUE;#if !defined (__RAM_FILE__)    while (fgets (string_from_ini_file,sizeof (string_from_ini_file),filptr_ini_file) != NULL)#else    cptr_current_string = NULL;    while (get_string_from_memory_file_image (string_from_ini_file,sizeof (string_from_ini_file),location_of_ini_file) == PASS)#endif        {        if (string_from_ini_file[0] == '/' && string_from_ini_file[1] == '/')            {            continue;            }        cptr_value_string = strchr (string_from_ini_file, '=');        if (cptr_value_string == NULL)            {            if (string_from_ini_file[0] != '[' && string_from_ini_file[1] != '[')                {                continue;                }            }        else            {            cptr_value_string++;        /* skip equals */            while(*cptr_value_string && *cptr_value_string <= ' ')                {                cptr_value_string++; /* skip any white space after equals */                }            }        if (ospf_nvram.display_configuration_file == TRUE)            {#if !defined (__RAM_FILE__)            nvram_printf (("%s",string_from_ini_file));#else            nvram_printf (("%s\r\n",string_from_ini_file));#endif            }        if (router_management_parameters (string_from_ini_file,cptr_value_string) == FAIL)            {#if !defined (__RAM_FILE__)           fclose (filptr_ini_file);#endif            return (FAIL);            }        }#if !defined (__RAM_FILE__)   fclose (filptr_ini_file);    PARAMETER_NOT_USED (location_of_ini_file);#endif    return (PASS);}/****************************************************************************/static void add_section_name_and_configuration_table_pointer (char *cptr_section_name,    OSPF_CONFIGURATION_TABLE *sptr_configuration_table_to_add){    section_name_array[ospf_nvram.number_of_configurations] = cptr_section_name;    sptr_configuration_table[ospf_nvram.number_of_configurations] = sptr_configuration_table_to_add;    ospf_nvram.number_of_configurations = (BYTE) (ospf_nvram.number_of_configurations + 1);}/****************************************************************************/static enum TEST read_router_ini_section_parameters (char *cptr_name_of_ini_file,ULONG location_of_ini_file,    char *cptr_section_name,void *vptr_location_of_configuration_table){    char *cptr_value_string;    char string_from_ini_file[256];#if !defined (__RAM_FILE__)    FILE *filptr_ini_file;#endif    if (vptr_location_of_configuration_table == NULL)        {        return (FAIL);        }    add_section_name_and_configuration_table_pointer (cptr_section_name, vptr_location_of_configuration_table);    if ((cptr_name_of_ini_file == NULL) && (location_of_ini_file == 0x00000000L))        {        nvram_printf (("NVRAM: No Configuration File Given!\r\n"));        return (FAIL);        }    else        {#if !defined (__RAM_FILE__)        nvram_printf (("File Open\r\n",cptr_name_of_ini_file));        #if (_BYTE_ORDER == _BIG_ENDIAN)        filptr_ini_file = fopen (cptr_name_of_ini_file, "r");        #else        filptr_ini_file = fopen (cptr_name_of_ini_file, "rt");        #endif        if (filptr_ini_file== NULL)            {            nvram_printf (("NVRAM: Could not find %s file, \r\n",cptr_name_of_ini_file));            return (FAIL);            }#endif        }#if !defined (__RAM_FILE__)    nvram_printf (("NVRAM: Current Configuration Setup in %s\r\n",cptr_name_of_ini_file));#else    nvram_printf (("NVRAM: Current Configuration Setup at %08lx\r\n",location_of_ini_file));#endif        ospf_nvram.current_configuration_section_index = ILLEGAL_SECTION_INDEX;    ospf_nvram.display_configuration_file = TRUE;#if !defined (__RAM_FILE__)    while (fgets (string_from_ini_file,sizeof (string_from_ini_file),filptr_ini_file) != NULL)#else    cptr_current_string = NULL;    while (get_string_from_memory_file_image (string_from_ini_file,sizeof (string_from_ini_file),location_of_ini_file) == PASS)#endif        {        if (string_from_ini_file[0] == '/' && string_from_ini_file[1] == '/')            {            continue;            }        else if ((cptr_value_string = strchr (string_from_ini_file,'=')) == NULL)            {            continue;            }        cptr_value_string++;        /* skip equals */        while(*cptr_value_string && *cptr_value_string <= ' ')            {            cptr_value_string++; /* skip any white space after equals */            }        if (ospf_nvram.display_configuration_file == TRUE)            {#if !defined (__RAM_FILE__)            nvram_printf (("%s",string_from_ini_file));#else            nvram_printf (("%s\r\n",string_from_ini_file));

⌨️ 快捷键说明

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