Example #1
0
/*---------------------------------------------------------------------------*
 *	check if date/month/year is a holiday
 *---------------------------------------------------------------------------*/
int
isholiday(int d, int m, int y)
{
	struct holiday *ch = NULL;

	if (firsth == NULL)
		return(0);

	ch = firsth;

	for (;;)
	{
		if (ch->day == d && ch->month == m)
		{
			if (ch->year == 0)
			{
				DBGL(DL_MSG, (logit(LL_DBG, "isholiday: %d.%d is a holiday!", d, m)));
				return(1);
			}
			else if (ch->year == y)
			{
				DBGL(DL_MSG, (logit(LL_DBG, "isholiday: %d.%d.%d is a holiday!", d, m, y)));
				return(1);
			}
		}

		if (ch->next == NULL)
			break;

		ch = ch->next;
	}
	return(0);
}
Example #2
0
/*---------------------------------------------------------------------------*
 *	select next remote number to dial (last was unsuccesfull)
 *---------------------------------------------------------------------------*/
void
select_next_dialno(cfg_entry_t *cep)
{
	if(cep->remote_numbers_count < 1)
	{
		dolog(LL_ERR, "select_next_dialno: remote_numbers_count < 1!");
		return;
	}

	if(cep->remote_numbers_count == 1)
	{
		strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
		DBGL(DL_DIAL, (dolog(LL_DBG, "select_next_dialno: only one no, no = %s", cep->remote_phone_dialout)));
		cep->last_remote_number = 0;
		return;
	}

	/* mark last try as bad */

	cep->remote_numbers[cep->last_remote_number].flag = RNF_IDLE;

	/* next one to try */
	
	cep->last_remote_number++;

	if(cep->last_remote_number >= cep->remote_numbers_count)
		cep->last_remote_number = 0;

	strcpy(cep->remote_phone_dialout, cep->remote_numbers[cep->last_remote_number].number);
	
	DBGL(DL_DIAL, (dolog(LL_DBG, "select_next_dialno: index=%d, no=%s",
		cep->last_remote_number,
		cep->remote_numbers[cep->last_remote_number].number)));
}									
Example #3
0
/*--------------------------------------------------------------------------*
 *	set channel state to idle
 *--------------------------------------------------------------------------*/
int
set_channel_idle(struct isdn_ctrl_state *ctrl, int channel)
{
	if (ctrl == NULL) {
		logit(LL_ERR, "set_channel_idle: invalid controller");
		return(ERROR);
	}
		
	if (channel < 0 || channel >= ctrl->nbch)
	{
		DBGL(DL_CNST, (logit(LL_DBG, "set_channel_idle: controller [%d] invalid channel %d", ctrl->isdnif, channel)));
		return(ERROR);
	}

	if (ctrl->stateb[channel] == CHAN_IDLE)
	{
		DBGL(DL_CNST, (logit(LL_DBG, "set_channel_idle: controller [%d] channel B%d already idle!", ctrl->isdnif, channel)));
	}
	else
	{
		ctrl->stateb[channel] = CHAN_IDLE;
		DBGL(DL_CNST, (logit(LL_DBG, "set_channel_idle: controller [%d] channel B%d set to IDLE!", ctrl->isdnif, channel)));
	}
		
	return(GOOD);
}
Example #4
0
/*--------------------------------------------------------------------------*
 *	set controller state to UP/DOWN
 *--------------------------------------------------------------------------*/
int
set_controller_state(int controller, int state)
{
	if((controller < 0) || (controller >= ncontroller))
	{
		dolog(LL_ERR, "set_controller_state: invalid controller number [%d]!", controller);
		return(ERROR);
	}

	if(state == CTRL_UP)
	{
		isdn_ctrl_tab[controller].state = CTRL_UP;
		DBGL(DL_CNST, (dolog(LL_DBG, "set_controller_state: controller [%d] set UP!", controller)));
	}
	else if (state == CTRL_DOWN)
	{
		isdn_ctrl_tab[controller].state = CTRL_DOWN;
		DBGL(DL_CNST, (dolog(LL_DBG, "set_controller_state: controller [%d] set DOWN!", controller)));
	}
	else
	{
		dolog(LL_ERR, "set_controller_state: invalid controller state [%d]!", state);
		return(ERROR);
	}
	return(GOOD);
}		
Example #5
0
/*--------------------------------------------------------------------------*
 *	set channel state to idle
 *--------------------------------------------------------------------------*/
int
set_channel_idle(int controller, int channel)
{
	if((controller < 0) || (controller >= ncontroller))
	{
		dolog(LL_ERR, "set_channel_idle: invalid controller number [%d]!", controller);
		return(ERROR);
	}
		
	if ((channel < 0) || (channel >= isdn_ctrl_tab[controller].nbch))
			{
		dolog(LL_ERR, "set_channel_busy: controller [%d] invalid channel [%d]!", controller, channel);
		return(ERROR);
			}

	if (isdn_ctrl_tab[controller].stateb[channel] == CHAN_IDLE)
			{
	    DBGL(DL_CNST, (dolog(LL_DBG, "set_channel_idle: controller [%d] channel B%d already idle!", controller, channel+1)));
			}
			else
			{
	    isdn_ctrl_tab[controller].stateb[channel] = CHAN_IDLE;
	    DBGL(DL_CNST, (dolog(LL_DBG, "set_channel_idle: controller [%d] channel B%d set to IDLE!", controller, channel+1)));
	}
	return(GOOD);
}
Example #6
0
int log_data(MYSQL **db_conn, alog_t *log)
{
	char sql[4096];
	snprintf(sql,sizeof(sql),"insert into waf_log_cdate(time,host,url,"
				"src_ip,dst_ip,src_port,dst_port,"
				"sig_id, catalog,action,method,"
				"msg,agent,cookie,raw) "
                "values(%d,\"%s\",\"%s\","
                "\"%s\",\"%s\",%d, %d,"
                "\"%s\",\"%s\",%d,\"%s\","
                "\"%s\",\"%s\",\"%s\",\"%s\")",
                        (int)log->time,log->host,log->url,
                        log->src_ip,log->dst_ip,log->src_port,log->dst_port,
                        log->id,log->catalog,log->action,log->method,
                        log->msg,log->agent,log->cookie,log->raw);
	DBGL("%s\n",sql);
	if (*db_conn != NULL) {
		if (mysql_query(*db_conn, sql)) {
			printf("%s\n", mysql_error(*db_conn));
			recon_log_db();			
			if (mysql_query(*db_conn, sql)) {
				printf("caution :log db is error \n ");
				return -1;
			}
		}
	}	

	return 0;
}
Example #7
0
/*---------------------------------------------------------------------------*
 *	init controller state array
 *---------------------------------------------------------------------------*/
void
init_controller(void)
{
	int i;
	int max = 0;
	msg_ctrl_info_req_t mcir;
	
	remove_all_ctrl_state();
	for (i=0; i <= max; i++)
	{
		mcir.controller = i;
		
		if ((ioctl(isdnfd, I4B_CTRL_INFO_REQ, &mcir)) < 0)
			continue;

		max = mcir.max_isdnif;

		/* init controller tab */

		if ((init_controller_state(i, mcir.devname, mcir.cardname, mcir.tei, mcir.nbch)) == ERROR)
		{
			logit(LL_ERR, "init_controller: init_controller_state for controller %d failed", i);
			do_exit(1);
		}
	}
	DBGL(DL_RCCF, (logit(LL_DBG, "init_controller: found %d ISDN controller(s)", max)));
}
Example #8
0
/*---------------------------------------------------------------------------*
 *	dial succeded, store this number as the last successful
 *---------------------------------------------------------------------------*/
void
select_this_dialno(cfg_entry_t *cep)
{
	cep->remote_numbers[cep->last_remote_number].flag = RNF_SUCC;
	
	DBGL(DL_DIAL, (dolog(LL_DBG, "select_this_dialno: index = %d, no = %s",
		cep->last_remote_number,
		cep->remote_numbers[cep->last_remote_number].number)));
}
int
kogmo_rtdb_kill_procs (kogmo_rtdb_handle_t *db_h, int sig)
{
  int i;
  CHK_DBH("kogmo_rtdb_kill_procs",db_h,0);
  DBGL(DBGL_APP,"killing connected processes with signal %i..", sig);
  for(i=0;i<KOGMO_RTDB_PROC_MAX;i++)
    {
      if(db_h->ipc_h.shm_p->proc[i].proc_oid != 0 )
        {
          DBGL(DBGL_APP,"killing process %s [OID %lli, PID %i]",
                  db_h->ipc_h.shm_p->proc[i].name,
                  (long long int)db_h->ipc_h.shm_p->proc[i].proc_oid,
                  db_h->ipc_h.shm_p->proc[i].pid);
          kill ( db_h->ipc_h.shm_p->proc[i].pid, sig);
        }
    }
  return 0;
}
Example #10
0
/*--------------------------------------------------------------------------*
 *	get number of free channels for controller
 *--------------------------------------------------------------------------*/
int
get_free_channels(struct isdn_ctrl_state *ctrl)
{
	if (ctrl == NULL) {
		logit(LL_ERR, "get_free_channels: invalid controller!");
		return(ERROR);
	}
	DBGL(DL_CNST, (logit(LL_DBG, "get_free_channels: ctrl %d, %d chan free", ctrl->isdnif, ctrl->freechans)));
	return (ctrl->freechans);
}		
/*! \brief Allocate Memory for Object Data with Object Data Heap.
 * For internal use only.
 * returns Index-Pointer relative to Heap begin.
 */
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_alloc (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objsize_t size )
{
    void *ptr = NULL;
    void *base = db_h->localdata_p->heap;

    DBGL(DBGL_DB,"mem_alloc: heap pointers: base %p",
         db_h->localdata_p->heap);

    DBGL(DBGL_DB,"mem_alloc: %lli bytes (%lli used, %lli free)",
         (long long int) size,
         (long long int) db_h->localdata_p->heap_used,
         (long long int) db_h->localdata_p->heap_free);
    if ( size <= 0 ) return -1;

    // speedup: round size to page_size (achieved with tlsf parameters)
    kogmo_rtdb_heap_lock(db_h);
#if defined(RTMALLOC_tlsf)
    ptr = malloc_ex (size, base);
#elif defined(RTMALLOC_suba)
    ptr = suba_alloc(db_h->heapinfo, size, 0/* dont zero*/);
#else
    if ( size <= db_h->localdata_p->heap_free )
    {
        ptr = base + db_h->localdata_p->heap_used;
    }
#endif
    DBG("mem_malloc: at %p",ptr);
    if ( ptr == NULL )
    {
        kogmo_rtdb_heap_unlock(db_h);
        ERR("object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free", size,
            (long long int) db_h->localdata_p->heap_free );
        return -1;
    }
    db_h->localdata_p->heap_free -= size;
    db_h->localdata_p->heap_used += size;
    kogmo_rtdb_heap_unlock(db_h);
    memset (ptr, 0, size);
    DBG("allocated mem cleared");
    return ptr-base;
}
Example #12
0
/*--------------------------------------------------------------------------*
 *	get number of free channels for controller
 *--------------------------------------------------------------------------*/
int
get_free_channels(int controller)
{
	if((controller < 0) || (controller >= ncontroller))
	{
		dolog(LL_ERR, "get_free_channels: invalid controller number [%d]!", controller);
		return(ERROR);
	}
	DBGL(DL_CNST, (dolog(LL_DBG, "get_free_channels: ctrl %d, %d chan free", controller, isdn_ctrl_tab[controller].freechans)));
	return(isdn_ctrl_tab[controller].freechans);
}		
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_attach (kogmo_rtdb_handle_t *db_h)
{
#if !defined(RTMALLOC_tlsf)
    kogmo_rtdb_objsize_t size = db_h->localdata_p->heap_size;
    void *base = db_h->localdata_p ->heap;
#endif
#if defined(RTMALLOC_tlsf)
    DBGL(DBGL_DB,"mem_attach(tlsf)");
// do nothing
#elif defined(RTMALLOC_suba)
    db_h->heapinfo =
        suba_init(base, size, 0/*rst*/, 0);
    DBGL(DBGL_DB,"mem_attach(suba) at %p with %p",base,db_h->heapinfo);
    if(db_h->heapinfo == NULL) return KOGMO_RTDB_ERR_INVALID;
#else
    DBGL(DBGL_DB,"mem_attach(static)");
// do nothing
#endif
    return 0;
}
Example #14
0
/*--------------------------------------------------------------------------*
 *	set controller state to UP/DOWN
 *--------------------------------------------------------------------------*/
int
set_controller_state(struct isdn_ctrl_state *ctrl, int state)
{
	if (ctrl == NULL) {
		logit(LL_ERR, "set_controller_state: invalid controller");
		return(ERROR);
	}

	if (state == CTRL_UP) {
		ctrl->state = CTRL_UP;
		DBGL(DL_CNST, (logit(LL_DBG, "set_controller_state: controller [%d] set UP!", ctrl->isdnif)));
	}
	else if (state == CTRL_DOWN)
	{
		ctrl->state = CTRL_DOWN;
		DBGL(DL_CNST, (logit(LL_DBG, "set_controller_state: controller [%d] set DOWN!", ctrl->isdnif)));
	}
	else
	{
		logit(LL_ERR, "set_controller_state: invalid controller state [%d]!", state);
		return(ERROR);
	}
	return(GOOD);
}		
void
kogmo_rtdb_obj_mem_destroy (kogmo_rtdb_handle_t *db_h)
{
    void *base = db_h->localdata_p->heap;
    DBGL(DBGL_DB,"mem_destroy: release %p, %lli bytes were used, %lli free",
         base,
         (long long int) db_h->localdata_p->heap_used,
         (long long int) db_h->localdata_p->heap_free);
#if defined(RTMALLOC_tlsf)
    destroy_memory_pool (base);
#elif defined(RTMALLOC_suba)
// do nothing
#else
// do nothing
#endif
}
Example #16
0
/*--------------------------------------------------------------------------*
 *	increment number of free channels for controller
 *--------------------------------------------------------------------------*/
int
incr_free_channels(struct isdn_ctrl_state *ctrl)
{
	if (ctrl == NULL) {
		logit(LL_ERR, "incr_free_channels: invalid controller!");
		return(ERROR);
	}
	if (ctrl->freechans < MAX_CHANCTRL)
	{
		ctrl->freechans++;
		DBGL(DL_CNST, (logit(LL_DBG, "incr_free_channels: ctrl %d, now %d chan free", ctrl->isdnif, ctrl->freechans)));
		return(GOOD);
	}
	else
	{
		logit(LL_ERR, "incr_free_channels: controller [%d] already 2 free chans!", ctrl->isdnif);
		return(ERROR);
	}
}		
Example #17
0
/*--------------------------------------------------------------------------*
 *	increment number of free channels for controller
 *--------------------------------------------------------------------------*/
int
incr_free_channels(int controller)
{
	if((controller < 0) || (controller >= ncontroller))
	{
		dolog(LL_ERR, "incr_free_channels: invalid controller number [%d]!", controller);
		return(ERROR);
	}
	if(isdn_ctrl_tab[controller].freechans < isdn_ctrl_tab[controller].nbch)
	{
		(isdn_ctrl_tab[controller].freechans)++;
		DBGL(DL_CNST, (dolog(LL_DBG, "incr_free_channels: ctrl %d, now %d chan free", controller, isdn_ctrl_tab[controller].freechans)));
		return(GOOD);
	}
	else
	{
		dolog(LL_ERR, "incr_free_channels: controller [%d] already %d free chans!", controller, isdn_ctrl_tab[controller].nbch);
		return(ERROR);
	}
}		
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_init (kogmo_rtdb_handle_t *db_h)
{
    kogmo_rtdb_objsize_t size = db_h->localdata_p->heap_size;
    kogmo_rtdb_objsize_t free;
    void *base = db_h->localdata_p->heap;
    DBGL(DBGL_DB,"mem_init: %i bytes at %p", size, base);
#if defined(RTMALLOC_tlsf)
    free = init_memory_pool (size, base);
#elif defined(RTMALLOC_suba)
    db_h->heapinfo =
        suba_init(base, size, 1/*rst*/, 1024/*mincell*/);
    free = size;
#else
    free = size;
#endif
    db_h->localdata_p->heap_free = free;
    db_h->localdata_p->heap_used = 0;
    return free;
}
Example #19
0
/*---------------------------------------------------------------------------*
 *	get the currently active rate
 *---------------------------------------------------------------------------*/
static int
getrate(int rate_type )
{
	struct tm *ptr;
	time_t now;
	register struct rates *hd;
	int time_now;

	if ((!got_rate) ||
	   (rate_type >= NRATES) ||
	   (rate_type == INVALID_RATE))
	{
		return -1;
	}

	time(&now);			/* get current time */

	ptr = localtime(&now);

	time_now = ptr->tm_hour*60 + ptr->tm_min;

	/* walk thru the rates for weekday until rate for current time found */

	for (hd = rates[rate_type][ptr->tm_wday]; hd; hd = hd->next)
	{
		/* current time within window ? */
		if ((time_now >= hd->start_time ) &&
		    (time_now < hd->end_time ))
		{
			DBGL(DL_RATES, (logit(LL_DBG, "rate=%d sec/unit (day=%d, beg=%d:%2.2d, end=%d:%2.2d, current=%d:%2.2d)",
				hd->rate,
				ptr->tm_wday,
				hd->start_time/60, hd->start_time%60,
				hd->end_time/60, hd->end_time%60,
				time_now/60, time_now%60)));
				
			return hd->rate;
		}
	}
	return -1;
}
Example #20
0
/*--------------------------------------------------------------------------*
 *	init controller state table entry
 *--------------------------------------------------------------------------*/
static int
init_controller_state(int controller, const char *devnam, const char *cardname, int tei, int nbch)
{
	struct isdn_ctrl_state *ctrl;
	int i;

	ctrl = malloc(sizeof *ctrl);
	if (ctrl == NULL) {
		logit(LL_ERR, "init_controller_state: out of memory");
		return(ERROR);
	}
	
	/* init controller state entry */

	memset(ctrl, 0, sizeof *ctrl);
	strncpy(ctrl->device_name,
	    devnam, 
	    sizeof(ctrl->device_name)-1);
	strncpy(ctrl->controller,
	    cardname, 
	    sizeof(ctrl->controller)-1);
	ctrl->isdnif = controller;
	ctrl->protocol = PROTOCOL_DSS1;
	ctrl->state = CTRL_UP;
	ctrl->nbch = nbch;
	for (i = 0; i < ctrl->nbch; i++)
		ctrl->stateb[i] = CHAN_IDLE;
	ctrl->freechans = MAX_CHANCTRL;
	ctrl->tei = tei;
	ctrl->l1stat = LAYER_IDLE;
	ctrl->l2stat = LAYER_IDLE;
	ctrl->firmware = NULL;
	DBGL(DL_RCCF, (logit(LL_DBG, "init_controller_state: controller %d (%s) is %s",
	   controller, devnam, cardname)));

	/* add to list */
	add_ctrl_state(ctrl);

	return(GOOD);
}	
Example #21
0
/*---------------------------------------------------------------------------*
 *	init controller state array
 *---------------------------------------------------------------------------*/
void
init_controller(void)
{
	int i;
	int max = 1;
	msg_ctrl_info_req_t mcir;
	
	for(i=0; i < max; i++)
	{
		mcir.controller = i;
		
		if((ioctl(isdnfd, I4B_CTRL_INFO_REQ, &mcir)) < 0)
		{
			dolog(LL_ERR, "init_controller: ioctl I4B_CTRL_INFO_REQ failed: %s", strerror(errno));
			do_exit(1);
		}

		if((ncontroller = max = mcir.ncontroller) == 0)
		{
			dolog(LL_ERR, "init_controller: no ISDN controller found!");
			do_exit(1);
		}

		if(mcir.ctrl_type == -1 || mcir.card_type == -1)
		{
			dolog(LL_ERR, "init_controller: ctrl/card is invalid!");
			do_exit(1);
		}

		/* init controller tab */

		if((init_controller_state(i, mcir.ctrl_type, mcir.card_type, mcir.tei, mcir.nbch)) == ERROR)
		{
			dolog(LL_ERR, "init_controller: init_controller_state for controller %d failed", i);
			do_exit(1);
		}
	}
	DBGL(DL_RCCF, (dolog(LL_DBG, "init_controller: found %d ISDN controller(s)", max)));
}
Example #22
0
int log_traffic(tlog_t *tlog)
{
	char sql[1024];
	snprintf(sql,sizeof(sql),"insert into waf_status_cdate(agent,cli_recv,svr_recv,"
							  "new_conn, now_conn)"
							 "values(%d,%ld,%ld,%ld,%ld)",	
						     g_cfg.wafid, tlog->clirecv, tlog->svrrecv,
							 tlog->nlive, tlog->nowlive);
	DBGL("%s\n",sql);
	if (m_db_log != NULL) {
		if (mysql_query(m_db_log, sql)) {
			printf("%s\n", mysql_error(m_db_log));
			recon_log_db();			
			if (mysql_query(m_db_log, sql)) {
				printf("caution :log db is error \n ");
				return -1;
			}
		}
	}
	
	return 0;
}
void
kogmo_rtdb_obj_mem_free (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objsize_t idx,
                         kogmo_rtdb_objsize_t size )
{
#if defined(RTMALLOC_tlsf)
    void *base = db_h->localdata_p->heap;
#endif
    void *ptr = db_h->localdata_p->heap + idx;
    DBGL(DBGL_DB,"mem_free: %i bytes at %p", size, ptr);
    kogmo_rtdb_heap_lock(db_h);
#if defined(RTMALLOC_tlsf)
    free_ex (ptr, base);
    db_h->localdata_p->heap_free += size;
    db_h->localdata_p->heap_used -= size;
#elif defined(RTMALLOC_suba)
    suba_free (db_h-> heapinfo, ptr);
    db_h->localdata_p->heap_free += size;
    db_h->localdata_p->heap_used -= size;
#else
// do nothing
#endif
    kogmo_rtdb_heap_unlock(db_h);
}
Example #24
0
/*--------------------------------------------------------------------------*
 *	init active controller
 *--------------------------------------------------------------------------*/
void
init_active_controller(void)
{
	struct isdn_ctrl_state *cst = NULL;
	int ret, fd;
	int i, numctrl;

#if 0
	/* XXX - replace by something useful */
	int controller;
	char cmdbuf[MAXPATHLEN+128];

	for (controller = 0; controller < ncontroller; controller++)
	{
		if (isdn_ctrl_tab[controller].ctrl_type == CTRL_TINADD)
		{
			DBGL(DL_RCCF, (logit(LL_DBG, "init_active_controller, tina-dd %d: executing [%s %d]", unit, tinainitprog, unit)));
			
			snprintf(cmdbuf, sizeof(cmdbuf), "%s %d", tinainitprog, unit);

			if ((ret = system(cmdbuf)) != 0)
			{
				logit(LL_ERR, "init_active_controller, tina-dd %d: %s returned %d!", unit, tinainitprog, ret);
				do_exit(1);
			}
		}
	}
#endif

	numctrl = count_ctrl_states();
	for (cst = get_first_ctrl_state(), i = 0;
	    i < numctrl;
	    cst = find_ctrl_state(i++)) {

		/*
		 *  Generic microcode loading. If a controller has
		 *  defined a microcode file, load it using the 
		 *  I4B_CTRL_DOWNLOAD ioctl.
		 */
		if (cst->firmware != NULL) {
			struct isdn_dr_prot idp;
			struct isdn_download_request idr;

			fd = open(cst->firmware, O_RDONLY);
			if (fd < 0) {
				logit(LL_ERR, "init_active_controller %d: "
				    "open %s: %s!", cst->isdnif, cst->firmware,
				    strerror(errno)); 
				do_exit(1);
			}

			idp.bytecount = lseek(fd, 0, SEEK_END);
			idp.microcode = mmap(0, idp.bytecount, PROT_READ,
			    MAP_SHARED, fd, 0);
			if (idp.microcode == MAP_FAILED) {
				logit(LL_ERR, "init_active_controller %d: "
				    "mmap %s: %s!", cst->isdnif, cst->firmware,
				    strerror(errno));
				do_exit(1);
			}

			DBGL(DL_RCCF, (logit(LL_DBG, "init_active_controller "
			    "%d: loading firmware from [%s]", cst->isdnif,
			    cst->firmware)));

			idr.controller = cst->isdnif;
			idr.numprotos = 1;
			idr.protocols = &idp;

			ret = ioctl(isdnfd, I4B_CTRL_DOWNLOAD, &idr,
			    sizeof(idr));
			if (ret) {
				logit(LL_ERR, "init_active_controller %d: "
				    "load %s: %s!", cst->isdnif, cst->firmware,
				    strerror(errno));
				do_exit(1);
			}

			munmap(idp.microcode, idp.bytecount);
			close(fd);
		}
	}
}	
Example #25
0
/*---------------------------------------------------------------------------*
 *	program entry
 *---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
	int i;
	msg_vr_req_t mvr;

#ifdef I4B_EXTERNAL_MONITOR
	int sockfd = -1;		/* local monitor socket */
#ifndef I4B_NOTCPIP_MONITOR
	int remotesockfd = -1;		/* tcp/ip monitor socket */
#endif
#endif

	setlocale (LC_ALL, "");

	while ((i = getopt(argc, argv, "mc:d:fFlL:Pr:s:t:u:")) != -1)
	{
		switch (i)
		{
#ifdef I4B_EXTERNAL_MONITOR
			case 'm':
				inhibit_monitor = 1;
				break;
#endif

			case 'c':
				configfile = optarg;
				break;

#ifdef DEBUG
			case 'd':
				if(*optarg == 'n')
					debug_noscreen = 1;
				else if((sscanf(optarg, "%i", &debug_flags)) == 1)
					do_debug = 1;
				else
					usage();
				break;
#endif

			case 'f':
				do_fullscreen = 1;
				do_fork = 0;
#ifndef USE_CURSES
				fprintf(stderr, "Sorry, no fullscreen mode available - daemon compiled without USE_CURSES\n");
				exit(1);
#endif
				break;

			case 'F':
				do_fork = 0;
				break;

			case 'l':
				uselogfile = 1;
				break;

			case 'L':
				strlcpy(logfile, optarg, sizeof(logfile));
				break;

			case 'P':
				do_print = 1;
				break;

			case 'r':
				rdev = optarg;
				do_rdev = 1;
				break;

			case 's':
				if(isdigit(*optarg))
				{
					int facility;
					logfacility = strtoul(optarg, NULL, 10);
					facility = logfacility << 3;

					if((facility < LOG_KERN) ||
					   (facility > LOG_FTP && facility < LOG_LOCAL0) ||
					   (facility > LOG_LOCAL7))
					{
						fprintf(stderr, "Error, option -s has invalid logging facility %d", logfacility);
						usage();
					}
					logfacility = facility;
				}
				else
				{
					fprintf(stderr, "Error: option -s requires a numeric argument!\n");
					usage();
				}
				break;

			case 't':
				ttype = optarg;
				do_ttytype = 1;
				break;

			case 'u':
				if(isdigit(*optarg))
				{
					unit_length = strtoul(optarg, NULL, 10);
					if(unit_length < ULSRC_CMDLMIN)
						unit_length = ULSRC_CMDLMIN;
					else if(unit_length > ULSRC_CMDLMAX)
						unit_length = ULSRC_CMDLMAX;
					got_unitlen = 1;
				}
				else
				{
					fprintf(stderr, "Error: option -T requires a numeric argument!\n");
					usage();
				}
				break;

			case '?':
			default:
				usage();
				break;
		}
	}
#ifdef DEBUG
	if(!do_debug)
		debug_noscreen = 0;
#endif

	if(!do_print)
	{
		umask(UMASK);	/* set our umask ... */

		init_log();	/* initialize the logging subsystem */
	}

	check_pid();	/* check if we are already running */

	if(!do_print)
	{
		if(do_fork || (do_fullscreen && do_rdev)) /* daemon mode ? */
			daemonize();

		write_pid();	/* write our pid to file */

		/* set signal handler(s) */

		signal(SIGCHLD, sigchild_handler); /* process handling	*/
		signal(SIGHUP,  rereadconfig);	/* reread configuration	*/
		signal(SIGUSR1, reopenfiles);	/* reopen acct/log files*/
		signal(SIGPIPE, SIG_IGN);	/* handled manually	*/
		signal(SIGINT,  do_exit);	/* clean up on SIGINT	*/
		signal(SIGTERM, do_exit);	/* clean up on SIGTERM	*/
		signal(SIGQUIT, do_exit);	/* clean up on SIGQUIT	*/
	}

	/* open isdn device */

	if((isdnfd = open(I4BDEVICE, O_RDWR)) < 0)
	{
		dolog(LL_ERR, "main: cannot open %s: %s", I4BDEVICE, strerror(errno));
		exit(1);
	}

	/* check kernel and userland have same version/release numbers */

	if((ioctl(isdnfd, I4B_VR_REQ, &mvr)) < 0)
	{
		dolog(LL_ERR, "main: ioctl I4B_VR_REQ failed: %s", strerror(errno));
		do_exit(1);
	}

	if(mvr.version != VERSION)
	{
		dolog(LL_ERR, "main: version mismatch, kernel %d, daemon %d", mvr.version, VERSION);
		do_exit(1);
	}

	if(mvr.release != REL)
	{
		dolog(LL_ERR, "main: release mismatch, kernel %d, daemon %d", mvr.release, REL);
		do_exit(1);
	}

	if(mvr.step != STEP)
	{
		dolog(LL_ERR, "main: step mismatch, kernel %d, daemon %d", mvr.step, STEP);
		do_exit(1);
	}

	/* init controller state array */

	init_controller();

	/* read runtime configuration file and configure ourselves */

	configure(configfile, 0);

	if(config_error_flag)
	{
		dolog(LL_ERR, "there were %d error(s) in the configuration file, terminating!", config_error_flag);
		exit(1);
	}

	/* set controller ISDN protocol */

	init_controller_protocol();

	/* init active controllers, if any */

	signal(SIGCHLD, SIG_IGN);		/*XXX*/

	init_active_controller();

	signal(SIGCHLD, sigchild_handler);	/*XXX*/

	/* handle the rates stuff */

	if((i = readrates(ratesfile)) == ERROR)
	{
		if(rate_error != NULL)
			dolog(LL_ERR, "%s", rate_error);
		exit(1);
	}

	if(i == GOOD)
	{
		got_rate = 1;	/* flag, ratesfile read and ok */
		DBGL(DL_RCCF, (dolog(LL_DBG, "ratesfile %s read successfully", ratesfile)));
	}
	else
	{
		if(rate_error != NULL)
			dolog(LL_WRN, "%s", rate_error);
	}

	/* if writing accounting info, open file, set unbuffered */

	if(useacctfile)
	{
		if((acctfp = fopen(acctfile, "a")) == NULL)
		{
			dolog(LL_ERR, "ERROR, can't open acctfile %s for writing, terminating!", acctfile);
			exit(1);
		}
		setvbuf(acctfp, NULL, _IONBF, 0);
	}

	/* initialize alias processing */

	if(aliasing)
		init_alias(aliasfile);

	/* init holidays */

	init_holidays(holidayfile);

	/* init remote monitoring */

#ifdef I4B_EXTERNAL_MONITOR
	if(do_monitor)
	{
		monitor_init();
		sockfd = monitor_create_local_socket();
#ifndef I4B_NOTCPIP_MONITOR
		remotesockfd = monitor_create_remote_socket(monitorport);
#endif
	}
#endif

	/* in case fullscreendisplay, initialize */

#ifdef USE_CURSES
	if(do_fullscreen)
	{
		init_screen();
	}
#endif

	/* init realtime priority */

#ifdef USE_RTPRIO
  	if(rt_prio != RTPRIO_NOTUSED)
  	{
  		struct rtprio rtp;

  		rtp.type = RTP_PRIO_REALTIME;
  		rtp.prio = rt_prio;

  		if((rtprio(RTP_SET, getpid(), &rtp)) == -1)
  		{
			dolog(LL_ERR, "rtprio failed: %s", strerror(errno));
			do_exit(1);
		}
	}
#endif

	starttime = time(NULL);	/* get starttime */

	srandom(580403);	/* init random number gen */

	mloop(		/* enter loop of no return .. */
#ifdef I4B_EXTERNAL_MONITOR
		sockfd
#ifndef I4B_NOTCPIP_MONITOR
		, remotesockfd
#endif
#endif
		);
	do_exit(0);
	return(0);
}
int
kogmo_rtdb_objmeta_purge_procs (kogmo_rtdb_handle_t *db_h)
{
  int i;
  kogmo_rtdb_objid_t err;

  CHK_DBH("kogmo_rtdb_objmeta_purge_procs",db_h,0);

  for(i=0;i<KOGMO_RTDB_PROC_MAX;i++)
    {
      if(db_h->ipc_h.shm_p->proc[i].proc_oid != 0 )
        {
          err = kill ( db_h->ipc_h.shm_p->proc[i].pid , 0);
          if ( err == -1 && errno == ESRCH )
            {
              kogmo_rtdb_obj_info_t used_objmeta;
              kogmo_rtdb_objid_list_t objlist;
              int j, immediately_delete;
              kogmo_rtdb_objid_t err;

              immediately_delete = db_h->ipc_h.shm_p->proc[i].flags & KOGMO_RTDB_CONNECT_FLAGS_IMMEDIATELYDELETE;

              DBGL(DBGL_APP,"DEAD PROCESS: %s [OID %lli, PID %i]",
                      db_h->ipc_h.shm_p->proc[i].name,
                      (long long int)db_h->ipc_h.shm_p->proc[i].proc_oid,
                      db_h->ipc_h.shm_p->proc[i].pid);

              err = kogmo_rtdb_obj_searchinfo_deleted (db_h, "", 0, 0,
                        db_h->ipc_h.shm_p->proc[i].proc_oid, 0, objlist, 0);
              if (err < 0 )
                {
                  DBGL(DBGL_APP,"search for objectlist failed: %d",err);
                }
              else
                {
                  DBGL(DBGL_APP,"dead process has %i objects to%s delete",err,
                       immediately_delete ? " immediately":"");
                  for (j=0; objlist[j] != 0; j++ )
                    {
                      err = kogmo_rtdb_obj_readinfo (db_h, objlist[j], 0, &used_objmeta );
                      if ( err >= 0 && used_objmeta.flags.persistent )
                        {
                          DBGL(DBGL_APP,"keeping persistent object '%s'",used_objmeta.name);
                          continue;
                        }
                       else
                         {
                           used_objmeta.oid = objlist[j]; // enough for delete
                         }
                        kogmo_rtdb_obj_delete_imm(db_h, &used_objmeta, immediately_delete);
                    }
                }

              kogmo_rtdb_ipc_mutex_lock (&db_h->ipc_h.shm_p->proc_lock);
              memset(&db_h->ipc_h.shm_p->proc[i],0,sizeof(struct kogmo_rtdb_ipc_process_t));
              db_h->ipc_h.shm_p->proc_free++;
              kogmo_rtdb_ipc_mutex_unlock (&db_h->ipc_h.shm_p->proc_lock);
            }
        }
    }
  return 0;
}
Example #27
0
/*---------------------------------------------------------------------------*
 *	read in and init holidayes
 *---------------------------------------------------------------------------*/
void 
init_holidays(char *filename)
{
	FILE *fp;
	unsigned char buffer[MAXBUFSZ + 1];
	struct holiday *newh = NULL;
	struct holiday *lasth = NULL;
	int ret;
	int day, month, year;
	
	firsth = NULL;
	
	if ((fp = fopen(filename, "r")) == NULL)
	{
		logit(LL_ERR, "init_holiday: error opening holidayfile %s: %s!", filename, strerror(errno));
		exit(1);
	}

	while((fgets(buffer, MAXBUFSZ, fp)) != NULL)
	{
		if (buffer[0] == '#'  || buffer[0] == ' ' ||
		   buffer[0] == '\t' || buffer[0] == '\n')
		{
			continue;
		}

		ret = sscanf(buffer, "%d.%d.%d", &day, &month, &year);

		if (ret != 3)
		{
			ret = sscanf(buffer, "%d.%d", &day, &month);
			if (ret != 2)
			{
				logit(LL_ERR, "init_holiday: parse error for string [%s]!", buffer);
				exit(1);
			}
			year = 0;
		}

		if ((newh = (struct holiday *) malloc(sizeof(struct holiday))) == NULL)
		{
			logit(LL_ERR, "init_holiday: malloc failed for struct holiday!\n");
			exit(1);
		}

		if (year)
		{
			DBGL(DL_MSG, (logit(LL_DBG, "init_holidays: add %d.%d.%d", day, month, year)));
		}
		else
		{
			DBGL(DL_MSG, (logit(LL_DBG, "init_holidays: add %d.%d", day, month)));
		}
		
		newh->day = day;
		newh->month = month;
		newh->year = year;
		newh->next = NULL;
		
		if (firsth == NULL || lasth == NULL)
		{
			firsth = newh;
		}
		else
		{
			lasth->next = newh;
		}
		lasth = newh;			
	}
	fclose(fp);
}
Example #28
0
/*--------------------------------------------------------------------------*
 *	init active or capi controller
 *--------------------------------------------------------------------------*/
void
init_active_controller(void)
{
	int ret;
	int unit = 0;
	int controller;
	char cmdbuf[MAXPATHLEN+128];

	for(controller = 0; controller < ncontroller; controller++)
	{
		if(isdn_ctrl_tab[controller].ctrl_type == CTRL_TINADD)
		{
			DBGL(DL_RCCF, (dolog(LL_DBG, "init_active_controller, tina-dd %d: executing [%s %d]", unit, tinainitprog, unit)));
			
			snprintf(cmdbuf, sizeof(cmdbuf), "%s %d", tinainitprog, unit);

			if((ret = system(cmdbuf)) != 0)
			{
				dolog(LL_ERR, "init_active_controller, tina-dd %d: %s returned %d!", unit, tinainitprog, ret);
				do_exit(1);
			}
		}

		/*
		 *  Generic microcode loading. If a controller has
		 *  defined a microcode file, load it using the
		 *  I4B_CTRL_DOWNLOAD ioctl.
		 */
		
		if(isdn_ctrl_tab[controller].firmware != NULL)
		{
		    int fd, ret;
		    struct isdn_dr_prot idp;
		    struct isdn_download_request idr;

		    fd = open(isdn_ctrl_tab[controller].firmware, O_RDONLY);
		    if (fd < 0) {
			dolog(LL_ERR, "init_active_controller %d: open %s: %s!",
			    controller, isdn_ctrl_tab[controller].firmware,
			    strerror(errno));
			do_exit(1);
		    }

		    idp.bytecount = lseek(fd, 0, SEEK_END);
		    idp.microcode = mmap(0, idp.bytecount, PROT_READ,
					 MAP_SHARED, fd, 0);
		    if (idp.microcode == MAP_FAILED) {
			dolog(LL_ERR, "init_active_controller %d: mmap %s: %s!",
			    controller, isdn_ctrl_tab[controller].firmware,
			    strerror(errno));
			do_exit(1);
		    }
		    
		    DBGL(DL_RCCF, (dolog(LL_DBG, "init_active_controller %d: loading firmware from [%s]", controller, isdn_ctrl_tab[controller].firmware)));

		    idr.controller = controller;
		    idr.numprotos = 1;
		    idr.protocols = &idp;
		    
		    ret = ioctl(isdnfd, I4B_CTRL_DOWNLOAD, &idr, sizeof(idr));
		    if (ret) {
			dolog(LL_ERR, "init_active_controller %d: load %s: %s!",
			    controller, isdn_ctrl_tab[controller].firmware,
			    strerror(errno));
			do_exit(1);
		    }

		    munmap(idp.microcode, idp.bytecount);
		    close(fd);
		}
	}
}	
Example #29
0
/*---------------------------------------------------------------------------*
 *	parse rates file
 *---------------------------------------------------------------------------*/
int
readrates(char *filename)
{
	char buffer[MAXPATHLEN];
	register char *bp;
	struct rates *rt, *ort;
	int rateindx;
	int indx;
	int line = 0;
	FILE *fp;
	int first;
#if DEBUG
	int i, j;
#endif
	
	indx = 0;
	rt = ort = NULL;

	if ((fp = fopen(filename, "r")) == NULL)
	{
		snprintf(error, sizeof(error), "error open %s: %s", filename, sys_errlist[errno]);
		rate_error = error;
		return(WARNING);
	}

	while((fgets(buffer, MAXPATHLEN, fp)) != NULL)
	{
		line++;

/* comments */
		if (buffer[0] == '#'  || buffer[0] == ' ' ||
		   buffer[0] == '\t' || buffer[0] == '\n')
		{
			continue;
		}

		bp = &buffer[0];

		/* rate type */

		if (*bp == 'r' && *(bp+1) == 'a' && isdigit((unsigned char)*(bp+2)))
		{
				rateindx = *(bp+2) - '0';
				bp += 3;

				/* eat space delimiter */

				while(isspace((unsigned char)*bp))
					bp++;
		}
		else
		{
			snprintf(error, sizeof(error), "rates: invalid rate type %c%c%c in line %d", *bp, *(bp+1), *(bp+2), line);
			goto rate_error;
		}
		if (rateindx >= NRATES)
		{
			snprintf(error, sizeof(error), "rates: invalid rate index %d in line %d", rateindx, line);
			goto rate_error;
		}

		/* day */
		
		if (isdigit((unsigned char)*bp) && *bp >= '0' && *bp <= '6')
		{
			indx = *bp - '0';

			DBGL(DL_RATES, (logit(LL_DBG, "rates: index = %d", indx)));
		}
		else
		{
			snprintf(error, sizeof(error), "rates: invalid day digit %c in line %d", *bp, line);
			goto rate_error;
		}

		if (rates[rateindx][indx] == NULL)
		{
			rt = (struct rates *)malloc(sizeof (struct rates));
			if (rt == NULL)
			{
				snprintf(error, sizeof(error), "rates: cannot malloc space for rate structure");
				goto rate_error;
		  	}
			rt->next = NULL;
		  	rates[rateindx][indx] = rt;
		}

		bp++;
		
		/* eat space delimiter */

		while(isspace((unsigned char)*bp))
			bp++;

		/* now loop to get the rates entries */

		first = 1;
		
		while(*bp && isdigit((unsigned char)*bp))
		{
			int hour = 0;
			int min = 0;

			if (first)
			{
				first = 0;
			}
			else
			{
				ort = rt;
	
				rt = (struct rates *)malloc(sizeof (struct rates));
				if (rt == NULL)
				{
					snprintf(error, sizeof(error), "rates: cannot malloc space2 for rate structure");
					goto rate_error;
			  	}
				ort->next = rt;
				rt->next = NULL;
			}
			
			/* start hour */
			
			if (isdigit((unsigned char)*bp) && isdigit((unsigned char)*(bp+1)))
			{
				hour = atoi(bp);
				bp += 2;
			}
		  	else
			{
				snprintf(error, sizeof(error), "rates: start_hr error in line %d", line);
				goto rate_error;
		  	}

			/* point */
			
		  	if (*bp == '.')
		  	{
		  		bp++;
		  	}
		  	else
		  	{
				snprintf(error, sizeof(error), "rates: no '.' after start_hr in line %d", line);
				goto rate_error;
			}
		  	
			/* start minute */
			
			if (isdigit((unsigned char)*bp) && isdigit((unsigned char)*(bp+1)))
			{
				min = atoi(bp);
				bp += 2;
			}
		  	else
			{
				snprintf(error, sizeof(error), "rates: start_min error in line %d", line);
				goto rate_error;
		  	}

			rt->start_time = hour*60 + min;

			/* minus */
			
		  	if (*bp == '-')
		  	{
		  		bp++;
		  	}
		  	else
		  	{
				snprintf(error, sizeof(error), "rates: no '-' after start_min in line %d", line);
				goto rate_error;
			}

			/* end hour */
			
			if (isdigit((unsigned char)*bp) && isdigit((unsigned char)*(bp+1)))
			{
				hour = atoi(bp);
				bp += 2;
			}
		  	else
			{
				snprintf(error, sizeof(error), "rates: end_hr error in line %d", line);
				goto rate_error;
		  	}

			/* point */
			
		  	if (*bp == '.')
		  	{
		  		bp++;
		  	}
		  	else
		  	{
				snprintf(error, sizeof(error), "rates: no '.' after end_hr in line %d", line);
				goto rate_error;
			}
		  	
			/* end minute */
			
			if (isdigit((unsigned char)*bp) && isdigit((unsigned char)*(bp+1)))
			{
				min = atoi(bp);
				bp += 2;
			}
		  	else
			{
				snprintf(error, sizeof(error), "rates: end_min error in line %d", line);
				goto rate_error;
		  	}

			/* if hour is 0 assume it means midnight */
			if ( hour == 0 )
				hour = 24;
			rt->end_time = hour * 60 + min;

			if ( rt->end_time <= rt->start_time )
				{
				snprintf(error, sizeof(error), "rates: end_time must be greater than start_time %d", line);
				goto rate_error;
				}

			/* colon */
			
		  	if (*bp == ':')
		  	{
		  		bp++;
		  	}
		  	else
		  	{
				snprintf(error, sizeof(error), "rates: no ':' after end_min in line %d", line);
				goto rate_error;
			}

			/* time */
			
			if (isdigit((unsigned char)*bp))
			{
				rt->rate = atoi(bp);
				while(!isspace((unsigned char)*bp))
					bp++;
			}
		  	else
			{
				snprintf(error, sizeof(error), "rates: first rate digit error in line %d", line);
				goto rate_error;
		  	}

			/* eat space delimiter */

			while(isspace((unsigned char)*bp))
				bp++;
		}
	}

#if DEBUG
	if (debug_flags & DL_RATES)
	{
		for (j = 0; j < NRATES; j++)
		{
			for (i = 0; i < NDAYS; i++)
			{
				if (rates [j][i] != NULL)
				{
					rt = rates [j][i];
					for (; rt; rt = rt->next)
					{
						logit(LL_DBG, "rates: index %d day %d = %d.%2.2d-%d.%2.2d:%d",
							j, i, rt->start_time/60, rt->start_time%60,
							rt->end_time/60,rt->end_time%60,rt->rate);
					}
				}
				else
				{
					logit(LL_DBG, "rates: NO entry for day %d !!\n", i);
				}
			}
		}
	}
#endif
	fclose(fp);
	return(GOOD);

rate_error:
	fclose(fp);
	rate_error = error;
	return(ERROR);
}
Example #30
0
/*---------------------------------------------------------------------------*
 *	select the first remote number to dial according to the
 *	dial strategy
 *---------------------------------------------------------------------------*/
void
select_first_dialno(cfg_entry_t *cep)
{
	int i, j;

	if(cep->keypad[0] != '\0')
		return;

	if(cep->remote_numbers_count < 1)
	{
		dolog(LL_ERR, "select_first_dialno: remote_numbers_count < 1!");
		return;
	}

	if(cep->remote_numbers_count == 1)
	{
		strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
		DBGL(DL_DIAL, (dolog(LL_DBG, "select_first_dialno: only one no, no = %s", cep->remote_phone_dialout)));
		cep->last_remote_number = 0;
		return;
	}

	if(cep->remote_numbers_handling == RNH_FIRST)
	{
		strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
		DBGL(DL_DIAL, (dolog(LL_DBG, "select_first_dialno: use first, no = %s", cep->remote_phone_dialout)));
		cep->last_remote_number = 0;
		return;
	}

	i = cep->last_remote_number;
	   
	for(j = cep->remote_numbers_count; j > 0; j--)
	{
		if(cep->remote_numbers[i].flag == RNF_SUCC)
		{
			if(cep->remote_numbers_handling == RNH_LAST)
			{
				strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
				DBGL(DL_DIAL, (dolog(LL_DBG, "select_first_dialno: use last, no = %s", cep->remote_phone_dialout)));
				cep->last_remote_number = i;
				return;
			}
			else
			{
				if(++i >= cep->remote_numbers_count)
					i = 0;

				strcpy(cep->remote_phone_dialout, cep->remote_numbers[i].number);
				DBGL(DL_DIAL, (dolog(LL_DBG, "select_first_dialno: use next, no = %s", cep->remote_phone_dialout)));
				cep->last_remote_number = i;
				return;
			}
		}

		if(++i >= cep->remote_numbers_count)
			i = 0;
	}
	strcpy(cep->remote_phone_dialout, cep->remote_numbers[0].number);
	DBGL(DL_DIAL, (dolog(LL_DBG, "select_first_dialno: no last found (use 0), no = %s", cep->remote_phone_dialout)));
	cep->last_remote_number = 0;	
}