"Fossies" - the Fresh Open Source Software Archive

Member "monit-5.28.0/src/l.l" (28 Mar 2021, 36020 Bytes) of package /linux/privat/monit-5.28.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "l.l" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.27.2_vs_5.28.0.

    1 /*
    2  * Copyright (C) Tildeslash Ltd. All rights reserved.
    3  *
    4  * This program is free software: you can redistribute it and/or modify
    5  * it under the terms of the GNU Affero General Public License version 3.
    6  *
    7  * This program is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  * GNU General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Affero General Public License
   13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   14  *
   15  * In addition, as a special exception, the copyright holders give
   16  * permission to link the code of portions of this program with the
   17  * OpenSSL library under certain conditions as described in each
   18  * individual source file, and distribute linked combinations
   19  * including the two.
   20  *
   21  * You must obey the GNU Affero General Public License in all respects
   22  * for all of the code used other than OpenSSL.
   23  */
   24 
   25 
   26 %option noyywrap
   27 
   28 
   29 %{
   30 
   31 /*
   32  * DESCRIPTION
   33  *
   34  *   Lexical grammar for tokenizing the control file.
   35  *
   36  */
   37 
   38 #include "config.h"
   39 
   40 #ifdef HAVE_STRING_H
   41 #include <string.h>
   42 #endif
   43 
   44 #ifdef HAVE_GLOB_H
   45 #include <glob.h>
   46 #endif
   47 
   48 #ifdef HAVE_STRINGS_H
   49 #include <strings.h>
   50 #endif
   51 
   52 #include "monit.h"
   53 #include "y.tab.h"
   54 
   55 // libmonit
   56 #include "util/Str.h"
   57 
   58 
   59 // we don't use yyinput => do not generate it
   60 #define YY_NO_INPUT
   61 
   62 #define MAX_STACK_DEPTH 512
   63 
   64 int buffer_stack_ptr = 0;
   65 
   66 struct buffer_stack_s {
   67         int             lineno;
   68         char           *currentfile;
   69         YY_BUFFER_STATE buffer;
   70 } buffer_stack[MAX_STACK_DEPTH];
   71 
   72 int lineno = 1;
   73 int arglineno = 1;
   74 char *currentfile = NULL;
   75 char *argcurrentfile = NULL;
   76 char *argyytext = NULL;
   77 typedef enum {
   78         Proc_State,
   79         File_State,
   80         FileSys_State,
   81         Dir_State,
   82         Host_State,
   83         System_State,
   84         Fifo_State,
   85         Program_State,
   86         Net_State,
   87         None_State
   88 } __attribute__((__packed__)) Check_State;
   89 
   90 static Check_State check_state = None_State;
   91 
   92 /* Prototypes */
   93 extern void yyerror(const char *,...);
   94 extern void yyerror2(const char *,...);
   95 extern void yywarning(const char *,...);
   96 extern void yywarning2(const char *,...);
   97 static void steplinenobycr(char *);
   98 static void save_arg(void);
   99 static void include_file(char *);
  100 static char *handle_quoted_string(char *);
  101 static void push_buffer_state(YY_BUFFER_STATE, char*);
  102 static int  pop_buffer_state(void);
  103 static URL_T create_URL(char *proto);
  104 
  105 %}
  106 
  107 ws             [ \r\t]+
  108 wws            [ \r\t;,()]+
  109 number         [0-9]+
  110 real           [0-9]+([.][0-9]+)?
  111 str            [^\000-\041@:{}"';(),%]+
  112 address        [^\000-\041<>{}\[\]]+
  113 addrname       [^\000-\037@<>{}\[\]]+
  114 hostname       {str}(\.{str})*
  115 dec-octet      [0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
  116 h16            [0-9A-Fa-f]{1,4}
  117 ipv4           {dec-octet}\.{dec-octet}\.{dec-octet}\.{dec-octet}
  118 ls32           {h16}:{h16}|{ipv4}
  119 ipv6           ({h16}:){6}{ls32}|::({h16}:){5}{ls32}|({h16})?::({h16}:){4}{ls32}|(({h16}:){0,1}{h16})?::({h16}:){3}{ls32}|(({h16}:){0,2}{h16})?::({h16}:){2}{ls32}|(({h16}:){0,3}{h16})?::{h16}:{ls32}|(({h16}:){0,4}{h16})?::{ls32}|(({h16}:){0,5}{h16})?::{h16}|(({h16}:){0,6}{h16})?::
  120 greater        ("more"|"greater"|"gt"|">"|"older")
  121 greaterorequal ("ge"|">=")
  122 less           ("less"|"lt"|"<"|"newer")
  123 lessorequal    ("le"|"<=")
  124 equal          ("equal"|"eq"|"=="|"=")
  125 notequal       ("notequal"|"ne"|"!=")
  126 loadavg1       load(avg)[ ]*(\([ ]*1[ ]*(m|min)?[ ]*\))?
  127 loadavg5       load(avg)[ ]*\([ ]*5[ ]*(m|min)?[ ]*\)
  128 loadavg15      load(avg)[ ]*\([ ]*15[ ]*(m|min)?[ ]*\)
  129 cpuuser        cpu[ ]*(usage)*[ ]*\([ ]*(us|usr|user)?[ ]*\)
  130 cpusyst        cpu[ ]*(usage)*[ ]*\([ ]*(sy|sys|system)?[ ]*\)
  131 cpuwait        cpu[ ]*(usage)*[ ]*\([ ]*(wa|wait)?[ ]*\)
  132 cpunice        cpu[ ]*(usage)*[ ]*\([ ]*nice[ ]*\)
  133 cpuhardirq     cpu[ ]*(usage)*[ ]*\([ ]*hardirq[ ]*\)
  134 cpusoftirq     cpu[ ]*(usage)*[ ]*\([ ]*softirq[ ]*\)
  135 cpusteal       cpu[ ]*(usage)*[ ]*\([ ]*steal[ ]*\)
  136 cpuguest       cpu[ ]*(usage)*[ ]*\([ ]*guest[ ]*\)
  137 cpuguestnice   cpu[ ]*(usage)*[ ]*\([ ]*guestnice[ ]*\)
  138 startarg       start{ws}?(program)?{ws}?([=]{ws})?["]
  139 stoparg        stop{ws}?(program)?{ws}?([=]{ws})?["]
  140 restartarg     restart{ws}?(program)?{ws}?([=]{ws})?["]
  141 execarg        exec(ute)?{ws}?["]
  142 pathtokarg     path{ws}?["]
  143 percent        ("percent"|"%")
  144 byte           ("byte"|"bytes"|"b")("/s")?
  145 kilobyte       ("kilobyte"|"kilobytes"|"kb")("/s")?
  146 megabyte       ("megabyte"|"megabytes"|"mb")("/s")?
  147 gigabyte       ("gigabyte"|"gigabytes"|"gb")("/s")?
  148 millisecond    ("millisecond"|"milliseconds"|"ms")
  149 second         ("second"|"seconds"|"s")
  150 minute         ("minute"|"minutes"|"m")
  151 hour           ("hour"|"hours"|"h")
  152 day            ("day"|"days")
  153 month          ("month"|"months")
  154 atime          ("atime"|"access time"|"access timestamp")
  155 ctime          ("ctime"|"change time"|"change timestamp")
  156 mtime          ("mtime"|"modification time"|"modification timestamp"|"modify time"|"modify timestamp")
  157 
  158 %x ARGUMENT_COND DEPEND_COND SERVICE_COND URL_COND ADDRESS_COND STRING_COND EVERY_COND HTTP_HEADER_COND INCLUDE
  159 
  160 %%
  161 
  162 {wws}             { /* Wide white space */ }
  163 (#.*)?\\?\n?      { lineno++; }
  164 
  165 is                {/* EMPTY */}
  166 as                {/* EMPTY */}
  167 are               {/* EMPTY */}
  168 for               {/* EMPTY */}
  169 via               {/* EMPTY */}
  170 on(ly)?           {/* EMPTY */}
  171 with(in|out)?     {/* EMPTY */}
  172 program(s)?       {/* EMPTY */}
  173 and               {/* EMPTY */}
  174 has               {/* EMPTY */}
  175 using             {/* EMPTY */}
  176 use               {/* EMPTY */}
  177 the               {/* EMPTY */}
  178 to                {/* EMPTY */}
  179 sum               {/* EMPTY */}
  180 than              {/* EMPTY */}
  181 usage             {/* EMPTY */}
  182 was               {/* EMPTY */}
  183 times             {/* EMPTY */}
  184 but               {/* EMPTY */}
  185 of                {/* EMPTY */}
  186 or                {/* EMPTY */}
  187 does              {/* EMPTY */}
  188 per               {/* EMPTY */}
  189 in                {/* EMPTY */}
  190 last              {/* EMPTY */}
  191 rate              {/* EMPTY */}
  192 capacity          {/* EMPTY */}
  193 activity          {/* EMPTY */}
  194 option(s)?        {/* EMPTY */}
  195 ssl[ \t]+disable  {/* EMPTY */}
  196 disable[ \t]+ssl  {/* EMPTY */}
  197 
  198 {startarg}        { BEGIN(ARGUMENT_COND); return START; }
  199 {stoparg}         { BEGIN(ARGUMENT_COND); return STOP; }
  200 {restartarg}      { BEGIN(ARGUMENT_COND); return RESTART; }
  201 {execarg}         { BEGIN(ARGUMENT_COND); return EXEC; }
  202 {pathtokarg}      {
  203                         if (check_state == Program_State) {
  204                                 BEGIN(ARGUMENT_COND); // Parse Path for program as arguments
  205                                 return PATHTOK;
  206                         } else {
  207                                 unput('"');
  208                                 return PATHTOK;
  209                         }
  210                   }
  211 
  212 if                { return IF; }
  213 then              { return THEN; }
  214 failed            { return FAILED; }
  215 tls               { return SSLTOKEN; }
  216 ssl               { return SSLTOKEN; }
  217 ssl[ \t]+enable   { return SSLTOKEN; }
  218 enable[ ]+ssl     { return SSLTOKEN; }
  219 enable            { return ENABLE; }
  220 disable           { return DISABLE; }
  221 verify            { return VERIFY; }
  222 valid             { return VALID; }
  223 certificate       { return CERTIFICATE; }
  224 cacertificatefile { return CACERTIFICATEFILE; }
  225 cacertificatepath { return CACERTIFICATEPATH; }
  226 set               { return SET; }
  227 daemon            { return DAEMON; }
  228 delay             { return DELAY; }
  229 terminal          { return TERMINAL; }
  230 batch             { return BATCH; }
  231 log               { return LOGFILE; }
  232 logfile           { return LOGFILE; }
  233 syslog            { return SYSLOG; }
  234 facility          { return FACILITY; }
  235 httpd             { return HTTPD; }
  236 address           { return ADDRESS; }
  237 interface         { return INTERFACE; }
  238 link              { return LINK; }
  239 packet(s)?("/s")? { return PACKET; }
  240 bytein            { return BYTEIN; }
  241 byteout           { return BYTEOUT; }
  242 packetin          { return PACKETIN; }
  243 packetout         { return PACKETOUT; }
  244 upload(ed)?       { return UPLOAD; }
  245 download(ed)?     { return DOWNLOAD; }
  246 up                { return UP; }
  247 down              { return DOWN; }
  248 saturation        { return SATURATION; }
  249 speed             { return SPEED; }
  250 total             { return TOTAL; }
  251 clientpemfile     { return CLIENTPEMFILE; }
  252 allowselfcertification  { return ALLOWSELFCERTIFICATION; }
  253 selfsigned        { return SELFSIGNED; }
  254 certmd5           { return CERTMD5; }
  255 pemfile           { return PEMFILE; }
  256 pemchain          { return PEMCHAIN; }
  257 pemkey            { return PEMKEY; }
  258 rsakey            { return RSAKEY; }
  259 init              { return INIT; }
  260 allow             { return ALLOW; }
  261 reject            { return REJECTOPT; }
  262 read[-]?only      { return READONLY; }
  263 disk              { return DISK; }
  264 read              { return READ; }
  265 write             { return WRITE; }
  266 service[ ]?time   { return SERVICETIME; }
  267 operation(s)?("/s")? { return OPERATION; }
  268 pidfile           { return PIDFILE; }
  269 idfile            { return IDFILE; }
  270 statefile         { return STATEFILE; }
  271 path              { return PATHTOK; }
  272 start             { return START; }
  273 stop              { return STOP; }
  274 port(number)?     { return PORT; }
  275 unix(socket)?     { return UNIXSOCKET; }
  276 ipv4              { return IPV4; }
  277 ipv6              { return IPV6; }
  278 type              { return TYPE; }
  279 proto(col)?       { return PROTOCOL; }
  280 tcp               { return TCP; }
  281 tcpssl            { return TCPSSL; }
  282 udp               { return UDP; }
  283 alert             { return ALERT; }
  284 noalert           { return NOALERT; }
  285 mail-format       { return MAILFORMAT; }
  286 resource          { return RESOURCE; }
  287 restart(s)?       { return RESTART; }
  288 cycle(s)?         { return CYCLE;}
  289 timeout           { return TIMEOUT; }
  290 retry             { return RETRY; }
  291 checksum          { return CHECKSUM; }
  292 mailserver        { return MAILSERVER; }
  293 host              { return HOST; }
  294 hostheader        { return HOSTHEADER; }
  295 method            { return METHOD; }
  296 get               { return GET; }
  297 head              { return HEAD; }
  298 status            { return STATUS; }
  299 default           { return DEFAULT; }
  300 http              { return HTTP; }
  301 https             { return HTTPS; }
  302 apache-status     { return APACHESTATUS; }
  303 ftp               { return FTP; }
  304 smtp              { return SMTP; }
  305 smtps             { return SMTPS; }
  306 postfix-policy    { return POSTFIXPOLICY; }
  307 pop               { return POP; }
  308 pops              { return POPS; }
  309 imap              { return IMAP; }
  310 imaps             { return IMAPS; }
  311 clamav            { return CLAMAV; }
  312 dns               { return DNS; }
  313 mysql             { return MYSQL; }
  314 mysqls            { return MYSQLS; }
  315 nntp              { return NNTP; }
  316 ntp3              { return NTP3; }
  317 ssh               { return SSH; }
  318 redis             { return REDIS; }
  319 mongodb           { return MONGODB; }
  320 fail2ban          { return FAIL2BAN; }
  321 sieve             { return SIEVE; }
  322 spamassassin      { return SPAMASSASSIN; }
  323 dwp               { return DWP; }
  324 ldap2             { return LDAP2; }
  325 ldap3             { return LDAP3; }
  326 rdate             { return RDATE; }
  327 lmtp              { return LMTP; }
  328 rsync             { return RSYNC; }
  329 tns               { return TNS; }
  330 pgsql             { return PGSQL; }
  331 websocket         { return WEBSOCKET; }
  332 mqtt              { return MQTT; }
  333 origin            { return ORIGIN; }
  334 version           { return VERSIONOPT; }
  335 sip               { return SIP; }
  336 gps               { return GPS; }
  337 radius            { return RADIUS; }
  338 memcache          { return MEMCACHE; }
  339 target            { return TARGET; }
  340 maxforward        { return MAXFORWARD; }
  341 mode              { return MODE; }
  342 active            { return ACTIVE; }
  343 passive           { return PASSIVE; }
  344 manual            { return MANUAL; }
  345 onreboot          { return ONREBOOT; }
  346 nostart           { return NOSTART; }
  347 laststate         { return LASTSTATE; }
  348 uid               { return UID; }
  349 euid              { return EUID; }
  350 security          { return SECURITY; }
  351 attribute(s)?     { return ATTRIBUTE; }
  352 gid               { return GID; }
  353 request           { return REQUEST; }
  354 secret            { return SECRET; }
  355 loglimit          { return LOGLIMIT; }
  356 closelimit        { return CLOSELIMIT; }
  357 dnslimit          { return DNSLIMIT; }
  358 keepalivelimit    { return KEEPALIVELIMIT; }
  359 replylimit        { return REPLYLIMIT; }
  360 requestlimit      { return REQUESTLIMIT; }
  361 startlimit        { return STARTLIMIT; }
  362 waitlimit         { return WAITLIMIT; }
  363 gracefullimit     { return GRACEFULLIMIT; }
  364 cleanuplimit      { return CLEANUPLIMIT; }
  365 mem(ory)?         { return MEMORY; }
  366 swap              { return SWAP; }
  367 total[ ]?mem(ory)? { return TOTALMEMORY; }
  368 core              { return CORE; }
  369 cpu               { return CPU; }
  370 total[ ]?cpu      { return TOTALCPU; }
  371 child(ren)?       { return CHILDREN; }
  372 thread(s)?        { return THREADS; }
  373 time(stamp)?      { return TIME; }
  374 changed           { return CHANGED; }
  375 -sslv2            { return NOSSLV2; }
  376 -sslv3            { return NOSSLV3; }
  377 -tlsv1            { return NOTLSV1; }
  378 -tlsv11           { return NOTLSV11; }
  379 -tlsv12           { return NOTLSV12; }
  380 -tlsv13           { return NOTLSV13; }
  381 sslv2             { return SSLV2; }
  382 sslv3             { return SSLV3; }
  383 tlsv1             { return TLSV1; }
  384 tlsv11            { return TLSV11; }
  385 tlsv12            { return TLSV12; }
  386 tlsv13            { return TLSV13; }
  387 cipher(s)?        { return CIPHER; }
  388 auto              { return AUTO; }
  389 sslauto           { return AUTO; }
  390 inode(s)?         { return INODE; }
  391 space             { return SPACE; }
  392 free              { return TFREE; }
  393 perm(ission)?     { return PERMISSION; }
  394 exec(ute)?        { return EXEC; }
  395 size              { return SIZE; }
  396 uptime            { return UPTIME; }
  397 responsetime      { return RESPONSETIME; }
  398 basedir           { return BASEDIR; }
  399 slot(s)?          { return SLOT; }
  400 eventqueue        { return EVENTQUEUE; }
  401 match(ing)?       { return MATCH; }
  402 not               { return NOT; }
  403 ignore            { return IGNORE; }
  404 connection        { return CONNECTION; }
  405 unmonitor         { return UNMONITOR; }
  406 action            { return ACTION; }
  407 icmp              { return ICMP; }
  408 ping              { return PING; }
  409 ping4             { return PING4; }
  410 ping6             { return PING6; }
  411 echo              { return ICMPECHO; }
  412 send              { return SEND; }
  413 expect            { return EXPECT; }
  414 expectbuffer      { return EXPECTBUFFER; }
  415 limits            { return LIMITS; }
  416 sendexpectbuffer  { return SENDEXPECTBUFFER; }
  417 filecontentbuffer { return FILECONTENTBUFFER; }
  418 httpcontentbuffer { return HTTPCONTENTBUFFER; }
  419 programoutput     { return PROGRAMOUTPUT; }
  420 networktimeout    { return NETWORKTIMEOUT; }
  421 programtimeout    { return PROGRAMTIMEOUT; }
  422 stoptimeout       { return STOPTIMEOUT; }
  423 starttimeout      { return STARTTIMEOUT; }
  424 restarttimeout    { return RESTARTTIMEOUT; }
  425 cleartext         { return CLEARTEXT; }
  426 md5               { return MD5HASH; }
  427 sha1              { return SHA1HASH; }
  428 crypt             { return CRYPT; }
  429 signature         { return SIGNATURE; }
  430 nonexist(s)?      { return NONEXIST; }
  431 exist(s)?         { return EXIST; }
  432 invalid           { return INVALID; }
  433 data              { return DATA; }
  434 recovered         { return RECOVERED; }
  435 passed            { return PASSED; }
  436 succeeded         { return SUCCEEDED; }
  437 else              { return ELSE; }
  438 mmonit            { return MMONIT; }
  439 url               { return URL; }
  440 content           { return CONTENT; }
  441 pid               { return PID; }
  442 ppid              { return PPID; }
  443 count             { return COUNT; }
  444 repeat            { return REPEAT; }
  445 reminder          { return REMINDER; }
  446 instance          { return INSTANCE; }
  447 hostname          { return HOSTNAME; }
  448 username          { return USERNAME; }
  449 password          { return PASSWORD; }
  450 credentials       { return CREDENTIALS; }
  451 register          { return REGISTER; }
  452 fsflag(s)?        { return FSFLAG; }
  453 fips              { return FIPS; }
  454 filedescriptors   { return FILEDESCRIPTORS; }
  455 {byte}            { return BYTE; }
  456 {kilobyte}        { return KILOBYTE; }
  457 {megabyte}        { return MEGABYTE; }
  458 {gigabyte}        { return GIGABYTE; }
  459 {loadavg1}        { return LOADAVG1; }
  460 {loadavg5}        { return LOADAVG5; }
  461 {loadavg15}       { return LOADAVG15; }
  462 {cpuuser}         { return CPUUSER; }
  463 {cpusyst}         { return CPUSYSTEM; }
  464 {cpuwait}         { return CPUWAIT; }
  465 {cpunice}         { return CPUNICE; }
  466 {cpuhardirq}      { return CPUHARDIRQ; }
  467 {cpusoftirq}      { return CPUSOFTIRQ; }
  468 {cpusteal}        { return CPUSTEAL; }
  469 {cpuguest}        { return CPUGUEST; }
  470 {cpuguestnice}    { return CPUGUESTNICE; }
  471 {greater}         { return GREATER; }
  472 {greaterorequal}  { return GREATEROREQUAL; }
  473 {less}            { return LESS; }
  474 {lessorequal}     { return LESSOREQUAL; }
  475 {equal}           { return EQUAL; }
  476 {notequal}        { return NOTEQUAL; }
  477 {millisecond}     { return MILLISECOND; }
  478 {second}          { return SECOND; }
  479 {minute}          { return MINUTE; }
  480 {hour}            { return HOUR; }
  481 {day}             { return DAY; }
  482 {month}           { return MONTH; }
  483 {atime}           { return ATIME; }
  484 {ctime}           { return CTIME; }
  485 {mtime}           { return MTIME; }
  486 
  487 include           { BEGIN(INCLUDE); }
  488 
  489 not[ ]+every      {
  490                     BEGIN(EVERY_COND);
  491                     return NOTEVERY;
  492                   }
  493 
  494 every             {
  495                     BEGIN(EVERY_COND);
  496                     return EVERY;
  497                   }
  498 
  499 depend(s)?[ \t]+(on[ \t]*)? {
  500                     BEGIN(DEPEND_COND);
  501                     return DEPENDS;
  502                   }
  503 
  504 check[ \t]+(process[ \t])? {
  505                     BEGIN(SERVICE_COND);
  506                     check_state = Proc_State;
  507                     return CHECKPROC;
  508                   }
  509 
  510 check[ \t]+(program[ \t])? {
  511                     BEGIN(SERVICE_COND);
  512                     check_state = Program_State;
  513                     return CHECKPROGRAM;
  514                   }
  515 
  516 check[ \t]+device { /* Filesystem alias for backward compatibility  */
  517                     BEGIN(SERVICE_COND);
  518                     check_state = FileSys_State;
  519                     return CHECKFILESYS;
  520                   }
  521 
  522 check[ \t]+filesystem {
  523                     BEGIN(SERVICE_COND);
  524                     check_state = FileSys_State;
  525                     return CHECKFILESYS;
  526                   }
  527 
  528 check[ \t]+file   {
  529                     BEGIN(SERVICE_COND);
  530                     check_state = File_State;
  531                     return CHECKFILE;
  532                   }
  533 
  534 check[ \t]+directory {
  535                     BEGIN(SERVICE_COND);
  536                     check_state = Dir_State;
  537                     return CHECKDIR;
  538                   }
  539 
  540 check[ \t]+host   {
  541                     BEGIN(SERVICE_COND);
  542                     check_state = Host_State;
  543                     return CHECKHOST;
  544                   }
  545 
  546 check[ \t]+network {
  547                     BEGIN(SERVICE_COND);
  548                     check_state = Net_State;
  549                     return CHECKNET;
  550                   }
  551 
  552 check[ \t]+fifo   {
  553                     BEGIN(SERVICE_COND);
  554                     check_state = Fifo_State;
  555                     return CHECKFIFO;
  556                   }
  557 
  558 check[ \t]+program   {
  559                     BEGIN(SERVICE_COND);
  560                     check_state = Program_State;
  561                     return CHECKPROGRAM;
  562                   }
  563 
  564 check[ \t]+system {
  565                     BEGIN(SERVICE_COND);
  566                     check_state = System_State;
  567                     return CHECKSYSTEM;
  568                   }
  569 
  570 group[ \t]+       {
  571                     BEGIN(STRING_COND);
  572                     return GROUP;
  573                   }
  574 
  575 "http headers"{ws} {
  576                         BEGIN(HTTP_HEADER_COND);
  577                         return '[';
  578                   }
  579 
  580 [a-zA-Z0-9]+"://" {
  581                     yylval.url = create_URL(Str_ndup(yytext, strlen(yytext)-3));
  582                     BEGIN(URL_COND);
  583                   }
  584 
  585 {number}          {
  586                     yylval.number = atoi(yytext);
  587                     save_arg();
  588                     return NUMBER;
  589                   }
  590 
  591 {real}            {
  592                     yylval.real = atof(yytext);
  593                     save_arg();
  594                     return REAL;
  595                   }
  596 
  597 {percent}         {
  598                     return PERCENT;
  599                   }
  600 
  601 [a-zA-Z0-9]{str}  {
  602                     yylval.string = Str_dup(yytext);
  603                     save_arg();
  604                     return STRING;
  605                   }
  606 
  607 \"[/][^\"\n]*\"   {
  608                     yylval.string = handle_quoted_string(yytext);
  609                     save_arg();
  610                     return PATH;
  611                   }
  612 
  613 \'[/][^\'\n]*\'   {
  614                     yylval.string = handle_quoted_string(yytext);
  615                     save_arg();
  616                     return PATH;
  617                   }
  618 
  619 \"[^\"]*\"        {
  620                     steplinenobycr(yytext);
  621                     yylval.string = handle_quoted_string(yytext);
  622                     save_arg();
  623                     return STRING;
  624                   }
  625 
  626 \'[^\']*\'        {
  627                     steplinenobycr(yytext);
  628                     yylval.string = handle_quoted_string(yytext);
  629                     save_arg();
  630                     return STRING;
  631                   }
  632 
  633 {str}[@]{str}     {
  634                     yylval.string = Str_dup(yytext);
  635                     save_arg();
  636                     return MAILADDR;
  637                   }
  638 
  639 [/]{str}          {
  640                      yylval.string = Str_dup(yytext);
  641                      save_arg();
  642                     return PATH;
  643                   }
  644 
  645 "/"               {
  646                      yylval.string = Str_dup(yytext);
  647                      save_arg();
  648                     return PATH;
  649                   }
  650 
  651 "from:"[ \t]* {
  652                       yylval.address = Address_new();
  653                       BEGIN(ADDRESS_COND);
  654                       return MAILFROM;
  655                   }
  656 
  657 "reply-to:"[ \t]* {
  658                       yylval.address = Address_new();
  659                       BEGIN(ADDRESS_COND);
  660                       return MAILREPLYTO;
  661                   }
  662 
  663 "subject:"[^}\n]* {
  664                       char *p = yytext+strlen("subject:");
  665                       yylval.string = Str_trim(Str_dup(p));
  666                       save_arg();
  667                       return MAILSUBJECT;
  668                   }
  669 
  670 "message:"[^}]*   {
  671                       char *p = yytext+strlen("message:");
  672                       steplinenobycr(yytext);
  673                       yylval.string = Str_trim(Str_dup(p));
  674                       save_arg();
  675                       return MAILBODY;
  676                   }
  677 
  678 {hostname}        {
  679                       yylval.string = Str_dup(yytext);
  680                       save_arg();
  681                       return STRING;
  682                   }
  683 
  684 {ipv4}[/]?[0-9]{0,2} {
  685                       yylval.string = Str_dup(yytext);
  686                       save_arg();
  687                       return STRING;
  688                   }
  689 
  690 {ipv6}[/]?[0-9]{0,3} {
  691                       yylval.string = Str_dup(yytext);
  692                       save_arg();
  693                       return STRING;
  694                   }
  695 
  696 [\"\']            {
  697                       yyerror("unbalanced quotes");
  698                   }
  699 
  700 <SERVICE_COND>{
  701 
  702   {ws}            ;
  703 
  704   [\n]            {
  705                     lineno++;
  706                   }
  707 
  708   {str}           {
  709                     yylval.string = Str_dup(yytext);
  710                     BEGIN(INITIAL);
  711                     save_arg();
  712                     return SERVICENAME;
  713                   }
  714 
  715   \"[^\000-\037\"\n]+\" {
  716                     yylval.string = handle_quoted_string(yytext);
  717                     BEGIN(INITIAL);
  718                     save_arg();
  719                     return SERVICENAME;
  720                   }
  721 
  722   \'[^\000-\037\"\n]+\' {
  723                     yylval.string = handle_quoted_string(yytext);
  724                     BEGIN(INITIAL);
  725                     save_arg();
  726                     return SERVICENAME;
  727                   }
  728 
  729   [\"]|[\']       {
  730                       yyerror("unbalanced quotes");
  731                   }
  732 
  733 }
  734 
  735 <DEPEND_COND>{
  736 
  737   {wws}           ;
  738 
  739   {wws}?[\n]{wws}? {
  740                     lineno++;
  741                   }
  742 
  743   {str}           {
  744                     yylval.string = Str_dup(yytext);
  745                     save_arg();
  746                     return SERVICENAME;
  747                   }
  748 
  749   \"[^\000-\037\"\n]+\" {
  750                     yylval.string = handle_quoted_string(yytext);
  751                     save_arg();
  752                     return SERVICENAME;
  753                   }
  754 
  755   \'[^\000-\037\"\n]+\' {
  756                     yylval.string = handle_quoted_string(yytext);
  757                     save_arg();
  758                     return SERVICENAME;
  759                   }
  760 
  761   [ \r\n\t]+[^,]  {
  762                     steplinenobycr(yytext);
  763                     unput(yytext[strlen(yytext)-1]);
  764                     BEGIN(INITIAL);
  765                   }
  766 
  767 }
  768 
  769 <ARGUMENT_COND>{
  770 
  771   {ws}            ;
  772 
  773   [\n]            {
  774                     lineno++;
  775                   }
  776 
  777   \"              {
  778                       BEGIN(INITIAL);
  779                   }
  780 
  781   \'[^\']*\'      {
  782                       steplinenobycr(yytext);
  783                       yylval.string = handle_quoted_string(yytext);
  784                       save_arg();
  785                       return STRING;
  786                   }
  787 
  788   \'              {
  789                       yyerror("unbalanced quotes");
  790                   }
  791 
  792   [^ \t\n\"]+     {
  793                       yylval.string = Str_dup(yytext);
  794                       save_arg();
  795                       return STRING;
  796                   }
  797 
  798 }
  799 
  800 <URL_COND>{
  801 
  802   {ws}|[\n]       {
  803                       BEGIN(INITIAL);
  804                       if (! yylval.url->hostname)
  805                                 yyerror("missing hostname in URL");
  806                       if (! yylval.url->path)
  807                                 yylval.url->path = Str_dup("/");
  808                       yylval.url->url = Str_cat("%s://[%s]:%d%s%s%s",
  809                                 yylval.url->protocol,
  810                                 /* possible credentials are hidden */
  811                                 yylval.url->hostname,
  812                                 yylval.url->port,
  813                                 yylval.url->path,
  814                                 yylval.url->query ? "?" : "",
  815                                 yylval.url->query ? yylval.url->query : "");
  816                       save_arg();
  817                       return URLOBJECT;
  818                   }
  819 
  820   [^:@ ]+/[:][^@: ]+[@] {
  821                       yylval.url->user = Str_dup(yytext);
  822                   }
  823 
  824   [:][^@ ]+[@]    {
  825                       yytext++;
  826                       yylval.url->password = Str_ndup(yytext, strlen(yytext)-1);
  827                   }
  828 
  829   ([a-zA-Z0-9\-]+)([.]([a-zA-Z0-9\-]+))* {
  830                       yylval.url->hostname = Str_dup(yytext);
  831                   }
  832 
  833   \[[0-9a-zA-Z.:%]+\] {
  834                       yylval.url->hostname = Str_ndup(yytext + 1, yyleng - 2);
  835                       yylval.url->ipv6 = true;
  836                   }
  837 
  838   [:]{number}     {
  839                       yylval.url->port = atoi(++yytext);
  840                   }
  841 
  842   [/][^?#\r\n ]*  {
  843                       yylval.url->path = Util_urlEncode(yytext, false);
  844                   }
  845 
  846   [?][^#\r\n ]*   {
  847                       yylval.url->query = Util_urlEncode(++yytext, false);
  848                   }
  849 
  850   [#][^\r\n ]*    {
  851                       /* EMPTY - reference is ignored */
  852                   }
  853 
  854 }
  855 
  856 <ADDRESS_COND>{
  857 
  858    [}\n]        {
  859                         if (yytext[0] == '}')
  860                                 yyless(0);
  861                         BEGIN(INITIAL);
  862                         if (! yylval.address->address)
  863                                 yyerror("missing address");
  864                         save_arg();
  865                         return ADDRESSOBJECT;
  866                 }
  867 
  868   {address}     {
  869                         yylval.address->address = Str_dup(yytext);
  870                 }
  871 
  872   {addrname}    {
  873                         char *name = Str_unquote(Str_dup(yytext));
  874                         if (name) {
  875                                 if (*name)
  876                                         yylval.address->name = name;
  877                                 else
  878                                         // Empty quoted string
  879                                         FREE(name);
  880                         }
  881                 }
  882 
  883   [<>:\[\]]     {
  884                         // Ignore
  885                 }
  886 
  887   .             {
  888                         BEGIN(INITIAL);
  889                         yyerror("invalid mail format");
  890                 }
  891 }
  892 
  893 <STRING_COND>{
  894 
  895   {str}           {
  896                     yylval.string = Str_dup(yytext);
  897                     BEGIN(INITIAL);
  898                     save_arg();
  899                     return STRINGNAME;
  900                   }
  901 
  902   \"{str}\"       {
  903                     yylval.string = handle_quoted_string(yytext);
  904                     BEGIN(INITIAL);
  905                     save_arg();
  906                     return STRINGNAME;
  907                   }
  908 
  909   \'{str}\'       {
  910                     yylval.string = handle_quoted_string(yytext);
  911                     BEGIN(INITIAL);
  912                     save_arg();
  913                     return STRINGNAME;
  914                   }
  915 
  916   [\"\']          {
  917                       yyerror("unbalanced quotes");
  918                   }
  919 
  920 }
  921 
  922 <EVERY_COND>{
  923 
  924   {ws}            ;
  925 
  926   {number}        {
  927                     yylval.number = atoi(yytext);
  928                     BEGIN(INITIAL);
  929                     save_arg();
  930                     return NUMBER;
  931                   }
  932 
  933   ['"]{ws}?[0-9,*-]+{ws}[0-9,*-]+{ws}[0-9,*-]+{ws}[0-9,*-]+{ws}[0-9,*-]+{ws}?['"] { // A minimal syntax check of the cron format string; 5 fields separated with white-space
  934                     yylval.string = Str_dup(Str_unquote(yytext));
  935                     BEGIN(INITIAL);
  936                     save_arg();
  937                     return TIMESPEC;
  938                   }
  939 
  940   .               {
  941                       BEGIN(INITIAL);
  942                       yyerror("invalid every format");
  943                   }
  944 
  945 }
  946 
  947 <HTTP_HEADER_COND>{
  948 
  949         {wws}   ;
  950 
  951         "["     ;
  952 
  953         [\n]    {
  954                         lineno++;
  955                 }
  956 
  957         ([^\t\r\n,\[\]:]+)/[:] { // name/:
  958                         save_arg();
  959                 }
  960 
  961         [:](({ws}?["][^"]+["])|({ws}?['][^']+['])|([^\r\n\],:]+)) { // : value
  962                         yylval.string = Str_cat("%s:%s", Str_trim(argyytext), Str_unquote(yytext + 1));
  963                         save_arg();
  964                         return HTTPHEADER;
  965                 }
  966 
  967         "]"     {
  968                         BEGIN(INITIAL);
  969                         save_arg();
  970                         return ']';
  971                 }
  972 
  973         .       {
  974                         BEGIN(INITIAL);
  975                         yyerror("invalid HTTP header list format");
  976                 }
  977 
  978 }
  979 
  980 
  981 <INITIAL,ARGUMENT_COND,SERVICE_COND,DEPEND_COND,URL_COND,ADDRESS_COND,STRING_COND,EVERY_COND,HTTP_HEADER_COND>. {
  982                       check_state = None_State;
  983                       return yytext[0];
  984                   }
  985 
  986 
  987 <INCLUDE>[ \t]*      /* eat the whitespace */
  988 
  989 <INCLUDE>\"[^\"\r\n]+\" { /* got the include file name with double quotes */
  990                      char *temp = Str_dup(yytext);
  991                      Str_unquote(temp);
  992                      include_file(temp);
  993                      FREE(temp);
  994                      BEGIN(INITIAL);
  995                    }
  996 
  997 <INCLUDE>\'[^\'\r\n]+\' { /* got the include file name with single quotes*/
  998                      char *temp = Str_dup(yytext);
  999                      Str_unquote(temp);
 1000                      include_file(temp);
 1001                      FREE(temp);
 1002                      BEGIN(INITIAL);
 1003                    }
 1004 
 1005 <INCLUDE>[^ \t\r\n]+ { /* got the include file name without quotes*/
 1006                      char *temp = Str_dup(yytext);
 1007                      include_file(temp);
 1008                      FREE(temp);
 1009                      BEGIN(INITIAL);
 1010                    }
 1011 
 1012 
 1013 <<EOF>>           {
 1014 
 1015                        BEGIN(INITIAL);
 1016                        check_state = None_State;
 1017                        if (! pop_buffer_state())
 1018                                 yyterminate();
 1019                   }
 1020 
 1021 %%
 1022 
 1023 /*
 1024  * Do lineno++ for every occurrence of '\n' in a string.  This is
 1025  * necessary whenever a yytext has an unknown number of CRs.
 1026  */
 1027 
 1028 static void steplinenobycr(char *string) {
 1029 
 1030         char *pos = string;
 1031 
 1032         while (*pos)
 1033         if ('\n' == *pos++) {
 1034                 lineno++;
 1035         }
 1036 
 1037 }
 1038 
 1039 
 1040 static char *handle_quoted_string(char *string) {
 1041         char *buf = Str_dup(string);
 1042         Str_unquote(buf);
 1043         Util_handleEscapes(buf);
 1044         return buf;
 1045 }
 1046 
 1047 
 1048 static void _include(const char *path) {
 1049         if (Str_cmp(Run.files.control, path) == 0) {
 1050                 yywarning("Include loop detected when trying to include %s", path);
 1051                 return;
 1052         }
 1053         for (int i = 0; i < buffer_stack_ptr; i++) {
 1054                 if (Str_cmp(buffer_stack[i].currentfile, path) == 0) {
 1055                         yywarning("Include loop detected when trying to include %s", path);
 1056                         return;
 1057                 }
 1058         }
 1059         FILE *_yyin = fopen(path, "r");
 1060         if (! _yyin)
 1061                 yyerror("Cannot include file '%s' -- %s", path, STRERROR);
 1062         else
 1063                 push_buffer_state(yy_create_buffer(_yyin, YY_BUF_SIZE), (char *)path);
 1064 }
 1065 
 1066 
 1067 static void include_file(char *pattern) {
 1068         glob_t globbuf;
 1069         errno = 0;
 1070         if (glob(pattern, GLOB_MARK, NULL, &globbuf) == 0) {
 1071                 for (size_t i = 0; i < globbuf.gl_pathc; i++) {
 1072                         size_t filename_length = strlen(globbuf.gl_pathv[i]);
 1073                         if ((filename_length == 0) || (globbuf.gl_pathv[i][filename_length - 1] == '~' ) || (globbuf.gl_pathv[i][filename_length - 1] == '/'))
 1074                                 continue; // skip subdirectories and file backup copies
 1075                         _include(globbuf.gl_pathv[i]);
 1076                 }
 1077                 globfree(&globbuf);
 1078         } else if (errno != 0) {
 1079                 yywarning("Include failed -- %s", STRERROR);
 1080         } // else no include files found -- silently ignore
 1081 }
 1082 
 1083 
 1084 static void push_buffer_state(YY_BUFFER_STATE buffer, char *filename) {
 1085         if (buffer_stack_ptr >= MAX_STACK_DEPTH) {
 1086                 yyerror("include files limit reached");
 1087                 exit( 1 );
 1088         }
 1089 
 1090         buffer_stack[buffer_stack_ptr].lineno = lineno;
 1091         buffer_stack[buffer_stack_ptr].currentfile = currentfile;
 1092         buffer_stack[buffer_stack_ptr].buffer = YY_CURRENT_BUFFER;
 1093 
 1094         buffer_stack_ptr++;
 1095 
 1096         lineno = 1;
 1097         currentfile = Str_dup(filename);
 1098 
 1099         yy_switch_to_buffer(buffer);
 1100 
 1101         BEGIN(INITIAL);
 1102 
 1103 }
 1104 
 1105 
 1106 static int pop_buffer_state(void) {
 1107 
 1108         if ( --buffer_stack_ptr < 0 ) {
 1109 
 1110                 return 0;
 1111 
 1112         } else {
 1113 
 1114                 fclose(yyin);
 1115                 lineno = buffer_stack[buffer_stack_ptr].lineno;
 1116 
 1117                 FREE(currentfile);
 1118                 currentfile = buffer_stack[buffer_stack_ptr].currentfile;
 1119 
 1120                 yy_delete_buffer(YY_CURRENT_BUFFER);
 1121                 yy_switch_to_buffer(buffer_stack[buffer_stack_ptr].buffer);
 1122 
 1123         }
 1124 
 1125         return 1;
 1126 
 1127 }
 1128 
 1129 
 1130 static void save_arg(void) {
 1131         arglineno = lineno;
 1132         argcurrentfile = currentfile;
 1133         FREE(argyytext);
 1134         argyytext = Str_dup(yytext);
 1135 }
 1136 
 1137 
 1138 static URL_T create_URL(char *proto) {
 1139         URL_T url;
 1140         ASSERT(proto);
 1141         NEW(url);
 1142         url->protocol = proto;
 1143         if (IS(url->protocol, "https")) {
 1144                 url->port = 443;
 1145 #ifndef HAVE_OPENSSL
 1146                 yyerror("HTTPS protocol not supported -- SSL support disabled" );
 1147 #endif
 1148         } else if (IS(url->protocol, "http")) {
 1149                 url->port = 80;
 1150         } else {
 1151                 yyerror("URL protocol not supported -- ");
 1152         }
 1153         return url;
 1154 }
 1155