| 1 |
/********************************************************************************************************* |
| 2 |
* Software License Agreement (BSD License) * |
| 3 |
* Author: Alexandre Westfahl <[email protected]> * |
| 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 <[email protected]>) * |
| 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 "test_sip.h" |
| 42 |
/* Include yacc tokens definitions */ |
| 43 |
#include "test_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 |
|
| 104 |
/* Recognize the tokens */ |
| 105 |
(?i:"username") { |
| 106 |
return TESTSIP_USERNAME; |
| 107 |
} |
| 108 |
|
| 109 |
(?i:"password") { |
| 110 |
return TESTSIP_PASSWORD; |
| 111 |
} |
| 112 |
|
| 113 |
(?i:"sip_aor") { |
| 114 |
return TESTSIP_SIPAOR; |
| 115 |
} |
| 116 |
|
| 117 |
(?i:"destination_realm") { |
| 118 |
return TESTSIP_DESTREALM; |
| 119 |
} |
| 120 |
|
| 121 |
(?i:"destination_sip") { |
| 122 |
return TESTSIP_DESTSIP; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
/* Valid single characters for yyparse */ |
| 129 |
[=;] { return yytext[0]; } |
| 130 |
|
| 131 |
/* Unrecognized sequence, if it did not match any previous pattern */ |
| 132 |
[^[:space:]"*=>;\n]+ { |
| 133 |
fd_log_debug("Unrecognized text on line %d col %d: '%s'.", yylloc->first_line, yylloc->first_column, yytext); |
| 134 |
return LEX_ERROR; |
| 135 |
} |
| 136 |
|
| 137 |
%% |