Esempio n. 1
0
void near FiltOverride(void *v, char *words[], char *line)
{
  OVRLIST ol=malloc(sizeof(*ol));
  int idx;

  NW(line);

  if (!ol)
    NoMem();

/* 0        1       2         3          4 */
/* override message msg_reply sysop/1234 R */

  if (!*words[1])
  {
    printf("Error!  No menu name specified for override on line %d!\n", linenum);
    return;
  }

  if (!*words[3])
  {
    printf("Error!  No access control string specified for override on line %d!\n", linenum);
    return;
  }

  if ((idx=tsearch(words[2], silt_table, silt_table_size)) != -1)
    ol->or.opt=silt_table[idx].opt;
  else Unknown_Ctl(linenum, words[2]);

  if (*words[4])
    ol->or.name=*words[4];
  else ol->or.name=0;

  if (PFI(v)->marea)
  {
    HeapAdd(&PMI(v)->h, &ol->or.menuname, words[1]);
    HeapAdd(&PMI(v)->h, &ol->or.acs, words[3]);

    /* Add this to the linked list of override options */

    ol->next=PMI(v)->ol;
    PMI(v)->ol=ol;

    PMI(v)->ma.num_override++;
  }
  else
  {
    HeapAdd(&PFI(v)->h, &ol->or.menuname, words[1]);
    HeapAdd(&PFI(v)->h, &ol->or.acs, words[3]);

    /* Add this to the linked list of override options */

    ol->next=PFI(v)->ol;
    PFI(v)->ol=ol;

    PFI(v)->fa.num_override++;
  }
}
Esempio n. 2
0
AbstractList<T> & LinearList<T>::insert(int k,T& x)//在第k个元素之前插入数据
{
	if(k<1 || k>length+1)
		throw OutOfBounds();
	if(length==MaxSize)
		throw NoMem();

	for(int i=length-1;i>=k-1;--i)
	{
		elem[i+1]=elem[i];
	}
	elem[k-1]=x;
	length++;
	return *this;
}
Esempio n. 3
0
BOOL COMMAPI ComOpen(LPTSTR pszDevice, HCOMM *phc, DWORD dwRxBuf, DWORD dwTxBuf)
{
  /* dwRxBuf and dwTxBuf appear to be minimum serial buffer sizes. */
  
  int h = -1; /* fd */
  struct sockaddr_in serv_addr;

#if 0
  /* Attempt to open the specified communications port */
  if ((h=CreateFile(pszDevice,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    &sa,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
                    (OSCOMMHANDLE)0))==INVALID_HANDLE_VALUE)
  {
    return FALSE;
  }
#endif

  serv_addr.sin_port = 0;

  if ((pszDevice[0] == '/') || (strncasecmp(pszDevice, "Com/", 4) == 0))
  {
    /* modem or pipe */
    h = open(pszDevice, O_RDWR, 0666);
    if (h < 1)
      return FALSE;
  }
  else
  {
    /* port number to listen on */
    int			port = atoi(pszDevice);
    int32              junk;

    if (!port && (strncasecmp(pszDevice, "com", 3) == 0))
      port = atoi(pszDevice + 3);

    if (port == 1)
    {
      /* Special port: stdin */
      h = STDIN_FILENO;
      serv_addr.sin_port = 0;
      goto openIt;
    }
      
    if (!port)
      port = 2001;

    if ((h = socket(AF_INET, SOCK_STREAM, 0)) < 0)
      return FALSE;

    serv_addr.sin_family=AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port=htons((short)port);

    junk = AF_INET;
    setsockopt(h, SOL_SOCKET, SO_REUSEADDR, (char *)&junk, sizeof(junk));

    if (bind(h, (struct sockaddr *) &serv_addr, sizeof(serv_addr)))
    {
      close(h);
      return FALSE;
    }

    if (listen(h, 1))
    {
      close(h);
      return FALSE;
    }
  } 

openIt:
  
  /* Now attempt to register this handle to get our threads going */
  if (!ComOpenHandle(h, phc, dwRxBuf, dwTxBuf))
  {
    close(h);
    return FALSE;
  }

  (*phc)->device = strdup(pszDevice);
  if (serv_addr.sin_port)
  {
    (*phc)->saddr_p = malloc(sizeof(serv_addr));
    if (!(*phc)->saddr_p)
      NoMem();

    *((*phc)->saddr_p) = serv_addr;
  }
  else
    (*phc)->saddr_p = NULL;

  return TRUE;
}
Esempio n. 4
0
void my_new_handler()
{
	throw NoMem();
}
Esempio n. 5
0
int VerbParse(void *pfi, struct _vbtab *verbs, char *line)
{
  char *words[MAX_PARSE_WORDS], *p;
  char szFirstWord[PATHLEN];
  struct _vbtab *pvt;
  int w, rc;

  rc=FALSE;

  Strip_Trailing(line, '\n');

  if ((p=strchr(line, '%')) != NULL)
    *p='\0';

  if ((p=strchr(line, ';')) != NULL)
    *p='\0';

  /* Speed up parsing if we're only looking for the first word */

  if (!verbs)
  {
    words[0]=szFirstWord;
    getword(line, words[0], ctl_delim, 1);
  }
  else
  {
    for (w=0; w < MAX_PARSE_WORDS; w++)
    {
      if ((words[w]=malloc(PATHLEN))==NULL)
        NoMem();

      if (w==0 || *words[w-1])
        getword(line, words[w], ctl_delim, w+1);
      else
        *words[w]=0;
    }
  }

  /* Find this in verb table */

  if (verbs)
    for (pvt=verbs; pvt->verb && !eqstri(words[0], pvt->verb); pvt++)
      ;

  /* If we didn't get a match */

  if (!verbs || !pvt->verb)
  {
    if (eqstri(words[0], "end"))
      rc=TRUE;
    else if (*words[0] && verbs)
      Unknown_Ctl(linenum, words[0]);
  }
  else
  {
    /* If we have a filter function, call it with a ptr to the second word */

    if (pvt->f)
      (*pvt->f)(pfi, words, fchar(line, ctl_delim, 2));

    /* Add this to a zstr heap, if necessary */

    if (pvt->pzstr)
      HeapAdd(&PFI(pfi)->h, pvt->pzstr, fchar(line, ctl_delim, 2));
  }

  /* Deallocate the space used for these words */

  if (verbs)
    for (w=0; w < MAX_PARSE_WORDS; w++)
      free(words[w]);

  linenum++;

  return rc;
}
Esempio n. 6
0
BOOL COMMAPI IpComOpen(LPTSTR pszDevice, HCOMM *phc, DWORD dwRxBuf, DWORD dwTxBuf)
{
  int			fd = -1; 	/**< file descriptor */
  struct sockaddr_un 	serv_addr;
  short			portnum = 0;
  COMMHANDLE		h = NULL;
  char			tmpPath[PATH_MAX];
  h = CommHandle_fromFileHandle(h, -1);

  if (strncasecmp(pszDevice, "Com", 3) == 0)
    pszDevice += 3;

  if (pszDevice[0] == ':')
    pszDevice++;

  portnum=atoi(pszDevice);

  sprintf(sockpath, "%s/%s%d", getcwd(tmpPath, PATH_MAX), SOCKPATH, portnum);
  sprintf(lockpath, "%s/%s%d.lck", getcwd(tmpPath, PATH_MAX), SOCKPATH, portnum);

  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
  {
    logit("!Unable to create AF_INET socket! (%s)", strerror(errno));
    return FALSE;
  }

  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, sockpath);
  unlink(serv_addr.sun_path);
  unlink(lockpath);

  if (bind(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)))
  {
    logit("!Unable to bind to port %i! (%s)", (int)portnum, strerror(errno));
    close(fd);
    return FALSE;
  }

  /* No listen backlog. See ComIsOnline() */
  if (listen(fd, 1))
  {
    logit("!Unable to listen on port %i! (%s)", (int)portnum, strerror(errno));
    close(fd);
    return FALSE;
  }

  /* Now attempt to initialize this handle */
  if (!ComOpenHandle(h, phc, dwRxBuf, dwTxBuf))
  {
    close(fd);
    return FALSE;
  }

  (*phc)->listenfd	= fd;
  (*phc)->device 	= strdup(pszDevice);
  (*phc)->saddr_p 	= malloc(sizeof(serv_addr));
  if ((!(*phc)->saddr_p) || (!(*phc)->device))
    NoMem();
  *((*phc)->saddr_p) = serv_addr;

  return TRUE;
}