text: /*
     Copyright (c) 2012, Stanislav Yakush(st.yakush@yandex.ru)
     All rights reserved.
  
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
      * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
      * Neither the name of the EagleMQ nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.
  
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
  #ifndef __UTILS_H__
  #define __UTILS_H__
  
  #include <stdarg.h>
  #include <stdint.h>
  
  #define MESSAGE_BUFFER_SIZE 256
  
  #define TO_LOWER(c) (unsigned char)(c | 0x20)
  #define IS_ALPHA(c) (TO_LOWER(c) >= 'a' && TO_LOWER(c) <= 'z')
  #define IS_NUM(c) ((c) >= '0' && (c) <= '9')
  #define IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c))
  #define IS_EXTRA1(c) ((c) == '_' || (c) == '-' || (c) == '.')
  #define IS_EXTRA2(c) ((c) == '*' || (c) == '?' || (c) == '[' || (c) == ']' || (c) == '\\')
  #define IS_EXTRA3(c) (IS_EXTRA1(c) || IS_EXTRA2(c))
  
  #define strlenz(s) (strlen(s) + 1)
  
  typedef enum { INFO_LEVEL, WARNING_LEVEL, FATAL_LEVEL, LOG_ONLY_LEVEL } message_level;
  
  void enable_log(const char *logfile);
  void disable_log();
  void warning(const char *fmt,...);
  void info(const char *fmt,...);
  void fatal(const char *fmt,...);
  void wlog(const char *fmt,...);
  
  int pattern_match_length(const char *string, int slength, const char *pattern, int plength, int nocase);
  int pattern_match(const char *string, const char *pattern, int nocase);
  
  uint64_t make_message_tag(uint32_t msg_counter, uint32_t time);
  
  long long memtoll(const char *value, int *err);
  
  int check_input_buffer1(char *buffer, size_t size);
  int check_input_buffer2(char *buffer, size_t size);
  int check_input_buffer3(char *buffer, size_t size);
  
  #endif
  