Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /********************************************************************************************************* |
| 2 | * Software License Agreement (BSD License) * |
| 3 | * Author: Alexandre Westfahl <awestfahl@freediameter.net> * |
| 4 | * * |
| 5 | * Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * |
| 6 | * * |
| 7 | * All rights reserved. * |
| 8 | * Based on ta_conf.l (Sebastien Decugis <sdecugis@freediameter.net>) * |
| 9 | * * |
| 10 | * Redistribution and use of this software in source and binary forms, with or without modification, are * |
| 11 | * permitted provided that the following conditions are met: * |
| 12 | * * |
| 13 | * * Redistributions of source code must retain the above * |
| 14 | * copyright notice, this list of conditions and the * |
| 15 | * following disclaimer. * |
| 16 | * * |
| 17 | * * Redistributions in binary form must reproduce the above * |
| 18 | * copyright notice, this list of conditions and the * |
| 19 | * following disclaimer in the documentation and/or other * |
| 20 | * materials provided with the distribution. * |
| 21 | * * |
| 22 | * * Neither the name of the Teraoka Laboratory nor the * |
| 23 | * names of its contributors may be used to endorse or * |
| 24 | * promote products derived from this software without * |
| 25 | * specific prior written permission of Teraoka Laboratory * |
| 26 | * * |
| 27 | * * |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
| 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
| 30 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
| 31 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
| 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
| 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
| 34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
| 35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
| 36 | *********************************************************************************************************/ |
| 37 | |
| 38 | |
| 39 | |
| 40 | %{ |
| 41 | #include "app_sip.h" |
| 42 | /* Include yacc tokens definitions */ |
| 43 | #include "app_sip.tab.h" |
| 44 | |
| 45 | /* Update the column information */ |
| 46 | #define YY_USER_ACTION { \ |
| 47 | yylloc->first_column = yylloc->last_column + 1; \ |
| 48 | yylloc->last_column = yylloc->first_column + yyleng - 1; \ |
| 49 | } |
| 50 | |
| 51 | /* Avoid warning with newer flex */ |
| 52 | #define YY_NO_INPUT |
| 53 | |
| 54 | %} |
| 55 | |
| 56 | %option bison-bridge bison-locations |
| 57 | %option noyywrap |
| 58 | %option nounput |
| 59 | |
| 60 | %% |
| 61 | |
| 62 | /* Update the line count */ |
| 63 | \n { |
| 64 | yylloc->first_line++; |
| 65 | yylloc->last_line++; |
| 66 | yylloc->last_column=0; |
| 67 | } |
| 68 | |
| 69 | /* Eat all spaces but not new lines */ |
| 70 | ([[:space:]]{-}[\n])+ ; |
| 71 | /* Eat all comments */ |
| 72 | #.*$ ; |
| 73 | |
| 74 | /* Recognize any integer */ |
| 75 | [-]?[[:digit:]]+ { |
| 76 | /* Convert this to an integer value */ |
| 77 | int ret=0; |
| 78 | ret = sscanf(yytext, "%i", &yylval->integer); |
| 79 | if (ret != 1) { |
| 80 | /* No matching: an error occurred */ |
| 81 | fd_log_debug("Unable to convert the value '%s' to a valid number: %s", yytext, strerror(errno)); |
| 82 | return LEX_ERROR; /* trig an error in yacc parser */ |
| 83 | /* Maybe we could REJECT instead of failing here? */ |
| 84 | } |
| 85 | return INTEGER; |
| 86 | } |
| 87 | |
| 88 | /* Recognize quoted strings -- we do not support escaped \" in the string currently. */ |
| 89 | \"[^\"]+\" { |
| 90 | /* Match a quoted string. Let's be very permissive. */ |
| 91 | yylval->string = strdup(yytext+1); |
| 92 | if (!yylval->string) { |
| 93 | fd_log_debug("Unable to copy the string '%s': %s", yytext, strerror(errno)); |
| 94 | TRACE_DEBUG(INFO, "strdup failed"); |
| 95 | return LEX_ERROR; /* trig an error in yacc parser */ |
| 96 | } |
| 97 | yylval->string[strlen(yytext) - 2] = '\0'; |
| 98 | return QSTRING; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | |
| 103 | /* Recognize the tokens */ |
| 104 | (?i:"mysql_login") { |
| 105 | return ASMYSQL_LOGIN; |
| 106 | } |
| 107 | |
| 108 | (?i:"mysql_password") { |
| 109 | return ASMYSQL_PASSWORD; |
| 110 | } |
| 111 | |
| 112 | (?i:"mysql_database") { |
| 113 | return ASMYSQL_DATABASE; |
| 114 | } |
| 115 | |
| 116 | (?i:"mysql_server") { |
| 117 | return ASMYSQL_SERVER; |
| 118 | } |
| 119 | |
| 120 | (?i:"mysql_port") { |
| 121 | return ASMYSQL_PORT; |
| 122 | } |
| 123 | (?i:"rtr_port") { |
| 124 | return RTR_PORT; |
| 125 | } |
| 126 | (?i:"ppr_port") { |
| 127 | return PPR_PORT; |
| 128 | } |
| 129 | (?i:"mode") { |
| 130 | return MODE; |
| 131 | } |
| 132 | |
| 133 | (?i:"datasource") { |
| 134 | return DATASOURCE; |
| 135 | } |
| 136 | |
| 137 | (?i:"mysql") { |
| 138 | yylval->integer = ASMYSQL; |
| 139 | return INTEGER; |
| 140 | } |
| 141 | (?i:"dsserver") { |
| 142 | yylval->integer = MODE_DSSERVER; |
| 143 | return INTEGER; |
| 144 | } |
| 145 | |
| 146 | (?i:"sl") { |
| 147 | yylval->integer = MODE_SL; |
| 148 | return INTEGER; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | |
| 153 | /* Valid single characters for yyparse */ |
| 154 | [=;] { return yytext[0]; } |
| 155 | |
| 156 | /* Unrecognized sequence, if it did not match any previous pattern */ |
| 157 | [^[:space:]"*=>;\n]+ { |
| 158 | fd_log_debug("Unrecognized text on line %d col %d: '%s'.", yylloc->first_line, yylloc->first_column, yytext); |
| 159 | return LEX_ERROR; |
| 160 | } |
| 161 | |
| 162 | %% |