Logo Search packages:      
Sourcecode: smstools version File versions  Download package

whitelist.c

/*
SMS Server Tools 3
Copyright (C) Keijo Kasvi
http://smstools3.kekekasvi.com/

Based on SMS Server Tools 2 from Stefan Frings
http://www.meinemullemaus.de/

This program is free software unless you got it under another license directly
from the author. You can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation.
Either version 2 of the License, or (at your option) any later version.
*/

#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "whitelist.h"
#include "extras.h"
#include "logging.h"
#include "alarm.h"
#include "smsd_cfg.h"

/* Used with >= 3.1x */
int inwhitelist_q(char* msisdn, char *queuename)
{
  FILE* file;
  char line[256];
  char* posi;
  char current_queue[32];
  int result = 1;
  int i;

  if (whitelist[0]) // is a whitelist file specified?
  {
    file=fopen(whitelist,"r");
    if (file)
    {
      *current_queue = 0;
      result = 0;
      while (fgets(line,sizeof(line),file))
      {
        posi=strchr(line,'#');     // remove comment
        if (posi)
          *posi=0;
        cutspaces(line);
        i = strlen(line);
        if (i > 0)
        {
          if (line[0] == '[' && line[i -1] == ']' && i -2 < sizeof(current_queue))
          {
            line[i -1] = 0;
            strcpy(current_queue, line +1);
          }
          else
          if (strncmp(msisdn,line,strlen(line))==0)
          {
            result = 1;
            break;
          }  
          else if (msisdn[0]=='s' && strncmp(msisdn+1,line,strlen(line))==0)
          {
            result = 1;
            break;
          }
        }  
      }  
      fclose(file);
      if (result == 1 && *current_queue && !(*queuename))
        strcpy(queuename, current_queue);
    }  
    else
    {
      writelogfile0(LOG_CRIT,"smsd", tb_sprintf("Stopping. Cannot read whitelist file %s.",whitelist));
      alarm_handler0(LOG_CRIT,"smsd", tb);
      //remove_pid(pidfile);
      //signal(SIGTERM,SIG_IGN);
      //kill(0,SIGTERM);
      //exit(127);
      abnormal_termination(1);
    }
  }      

  return result;
}

/* Used with < 3.1x */
int inwhitelist(char* msisdn)
{
  FILE* file;
  char line[256];
  char* posi;
  if (whitelist[0]) // is a whitelist file specified?
  {
    file=fopen(whitelist,"r");
    if (file)
    {
      while (fgets(line,sizeof(line),file))
      {
        posi=strchr(line,'#');     // remove comment
        if (posi)
          *posi=0;
        cutspaces(line);
        if (strlen(line)>0)
        {
          if (strncmp(msisdn,line,strlen(line))==0)
          {
            fclose(file);
            return 1;
          }
          else if (msisdn[0]=='s' && strncmp(msisdn+1,line,strlen(line))==0)
          {
            fclose(file);
            return 1;
          }
        }
      }
      fclose(file);
      return 0;
    }
    else
    {
      writelogfile0(LOG_CRIT,"smsd", tb_sprintf("Stopping. Cannot read whitelist file %s.",whitelist));
      alarm_handler0(LOG_CRIT,"smsd", tb);
      //remove_pid(pidfile);
      //signal(SIGTERM,SIG_IGN);
      //kill(0,SIGTERM);
      //exit(127);
      abnormal_termination(1);
    }
  }
  return 1;
}

Generated by  Doxygen 1.6.0   Back to index