Navigation


Changeset 304:ad3c46016584 in freeDiameter for extensions/app_radgw/rgw_conf.y


Ignore:
Timestamp:
May 14, 2010, 5:26:53 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added install directives for cmake; also allow default directory to seek for extensions and configuration files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/rgw_conf.y

    r258 r304  
    5353#include "rgw_conf.tab.h"       /* bison is not smart enough to define the YYLTYPE before including this code, so... */
    5454
    55 #include <sys/stat.h>
    5655#include <sys/socket.h>
    5756#include <arpa/inet.h>
     
    9796        else
    9897                fd_log_debug("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s);
    99 }
    100 
    101 /* This function checks a string value is a valid filename */
    102 static int is_valid_file( char * candidate )
    103 {
    104         int ret;
    105         struct stat buffer;
    106        
    107         ret = stat(candidate, &buffer);
    108         if (ret != 0) {
    109                 fd_log_debug("Error on file '%s': %s.\n", candidate, strerror(errno));
    110                 return 0;
    111         }
    112 
    113         /* Ok this candidate is valid */
    114         return 1;
    11598}
    11699
     
    161144%token <ss>     IP
    162145
    163 %type <string>  FILENAME
     146%type <string>  FINDFILEEXT
    164147
    165148/* simple tokens */
     
    197180                               
    198181/* -------------------------------------- */
    199 FILENAME:               QSTRING
    200                         {
    201                                 /* Verify this is a valid file */
    202                                 if (!is_valid_file($1)) {
    203                                         yyerror (&yylloc, conffile, "Error on file name, aborting...");
    204                                         YYERROR;
    205                                 }
    206                                 $$ = $1;
     182FINDFILEEXT:            QSTRING
     183                        {
     184                                char * fname = $1;
     185                                FILE * fd;
     186                               
     187                                /* First, check if the file exists */
     188                                fd = fopen(fname, "r");
     189                                if ((fd == NULL) && (*fname != '/')) {
     190                                        char * bkp = fname;
     191                                        CHECK_MALLOC_DO( fname = malloc( strlen(bkp) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ),
     192                                                { yyerror (&yylloc, conffile, "Not enough memory"); YYERROR; } );
     193                                        sprintf(fname, DEFAULT_EXTENSIONS_PATH "/%s", bkp);
     194                                        free(bkp);
     195                                        fd = fopen(fname, "r");
     196                                }
     197                                if (fd == NULL) {
     198                                        int ret = errno;
     199                                        TRACE_DEBUG(INFO, "Unable to open file %s for reading: %s\n", fname, strerror(ret));
     200                                        yyerror (&yylloc, conffile, "Error adding plugin");
     201                                        YYERROR;
     202                                }
     203                                fclose(fd);
     204                               
     205                                $$ = fname;
    207206                        }
    208207                        ;
     
    214213                                free(plgconffile); plgconffile = NULL;
    215214                        }
    216                         PLG_PREFIX '=' FILENAME plg_attributes ';'
     215                        PLG_PREFIX '=' FINDFILEEXT plg_attributes ';'
    217216                        {
    218217                                /* Add this extension in the list */
Note: See TracChangeset for help on using the changeset viewer.