示例#1
0
文件: win32.c 项目: angelol/iOpenVPN
void
win32_signal_clear (struct win32_signal *ws)
{
  CLEAR (*ws);
}
示例#2
0
static void
plugin_open_item (struct plugin *p,
		  const struct plugin_option *o,
		  struct openvpn_plugin_string_list **retlist,
		  const char **envp,
		  const int init_point)
{
  ASSERT (p->initialized);

  /* clear return list */
  if (retlist)
    *retlist = NULL;

  if (!p->plugin_handle && init_point == p->requested_initialization_point)
    {
      struct gc_arena gc = gc_new ();

      dmsg (D_PLUGIN_DEBUG, "PLUGIN_INIT: PRE");
      plugin_show_args_env (D_PLUGIN_DEBUG, o->argv, envp);

      /*
       * Call the plugin initialization
       */
      if (p->open3) {
        struct openvpn_plugin_args_open_in args = { p->plugin_type_mask,
                                                    (const char ** const) o->argv,
                                                    (const char ** const) envp,
                                                    &callbacks,
                                                    SSLAPI };
        struct openvpn_plugin_args_open_return retargs;

        CLEAR(retargs);
        retargs.return_list = retlist;
        if ((*p->open3)(OPENVPN_PLUGINv3_STRUCTVER, &args, &retargs) == OPENVPN_PLUGIN_FUNC_SUCCESS) {
          p->plugin_type_mask = retargs.type_mask;
          p->plugin_handle = retargs.handle;
        } else {
          p->plugin_handle = NULL;
        }
      } else if (p->open2)
	p->plugin_handle = (*p->open2)(&p->plugin_type_mask, o->argv, envp, retlist);
      else if (p->open1)
	p->plugin_handle = (*p->open1)(&p->plugin_type_mask, o->argv, envp);
      else
	ASSERT (0);

      msg (D_PLUGIN, "PLUGIN_INIT: POST %s '%s' intercepted=%s %s",
	   p->so_pathname,
	   print_argv (o->argv, &gc, PA_BRACKET),
	   plugin_mask_string (p->plugin_type_mask, &gc),
	   (retlist && *retlist) ? "[RETLIST]" : "");
      
      if ((p->plugin_type_mask | plugin_supported_types()) != plugin_supported_types())
	msg (M_FATAL, "PLUGIN_INIT: plugin %s expressed interest in unsupported plugin types: [want=0x%08x, have=0x%08x]",
	     p->so_pathname,
	     p->plugin_type_mask,
	     plugin_supported_types());

      if (p->plugin_handle == NULL)
	msg (M_FATAL, "PLUGIN_INIT: plugin initialization function failed: %s",
	     p->so_pathname);

      gc_free (&gc);
    }
}
示例#3
0
int main(int argc, char **argv)
{
        struct v4l2_format              fmt;
        struct v4l2_buffer              buf;
        struct v4l2_requestbuffers      req;
        enum v4l2_buf_type              type;
        fd_set                          fds;
        struct timeval                  tv;
        int                             r, fd = -1;
        unsigned int                    i, n_buffers;
        char                            *dev_name = "/dev/video0";
        char                            out_name[256];
        FILE                            *fout;
        struct buffer                   *buffers;

        fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
        if (fd < 0) {
                perror("Cannot open device");
                exit(EXIT_FAILURE);
        }

        CLEAR(fmt);
        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        fmt.fmt.pix.width       = 1920;
        fmt.fmt.pix.height      = 1080;
        fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
        fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
        xioctl(fd, VIDIOC_S_FMT, &fmt);
        if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) {
                printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
                exit(EXIT_FAILURE);
        }
        if ((fmt.fmt.pix.width != 640) || (fmt.fmt.pix.height != 480))
                printf("Warning: driver is sending image at %dx%d\n",
                        fmt.fmt.pix.width, fmt.fmt.pix.height);

        CLEAR(req);
        req.count = 2;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_MMAP;
        xioctl(fd, VIDIOC_REQBUFS, &req);

        buffers = calloc(req.count, sizeof(*buffers));
        for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
                CLEAR(buf);

                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory      = V4L2_MEMORY_MMAP;
                buf.index       = n_buffers;

                xioctl(fd, VIDIOC_QUERYBUF, &buf);

                buffers[n_buffers].length = buf.length;
                buffers[n_buffers].start = v4l2_mmap(NULL, buf.length,
                              PROT_READ | PROT_WRITE, MAP_SHARED,
                              fd, buf.m.offset);

                if (MAP_FAILED == buffers[n_buffers].start) {
                        perror("mmap");
                        exit(EXIT_FAILURE);
                }
        }

        for (i = 0; i < n_buffers; ++i) {
                CLEAR(buf);
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;
                buf.index = i;
                xioctl(fd, VIDIOC_QBUF, &buf);
        }
        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        xioctl(fd, VIDIOC_STREAMON, &type);
        for (i = 0; i < 20; i++) {
                do {
                        FD_ZERO(&fds);
                        FD_SET(fd, &fds);

                        /* Timeout. */
                        tv.tv_sec = 2;
                        tv.tv_usec = 0;

                        r = select(fd + 1, &fds, NULL, NULL, &tv);
                } while ((r == -1 && (errno = EINTR)));
                if (r == -1) {
                        perror("select");
                        return errno;
                }

                CLEAR(buf);
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;
                xioctl(fd, VIDIOC_DQBUF, &buf);

                sprintf(out_name, "grabber%03d.ppm", i);
                fout = fopen(out_name, "w");
                if (!fout) {
                        perror("Cannot open image");
                        exit(EXIT_FAILURE);
                }
                fprintf(fout, "P6\n%d %d 255\n",
                        fmt.fmt.pix.width, fmt.fmt.pix.height);
                fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);
                fclose(fout);

                xioctl(fd, VIDIOC_QBUF, &buf);
        }

        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        xioctl(fd, VIDIOC_STREAMOFF, &type);
        for (i = 0; i < n_buffers; ++i)
                v4l2_munmap(buffers[i].start, buffers[i].length);
        v4l2_close(fd);

        return 0;
}
示例#4
0
void mainScreen(void){
	uint32 ReadWord;
	int16 xvalue,yvalue;
	ft_char8_t StringArray[100];

		Ft_Gpu_CoCmd_Dlstart(phost);
		Ft_App_WrCoCmd_Buffer(phost,CLEAR_COLOR_RGB(64,64,64));
		Ft_App_WrCoCmd_Buffer(phost,CLEAR(1,1,1));
		Ft_App_WrCoCmd_Buffer(phost,COLOR_RGB(255,255,255));

		Ft_Gpu_CoCmd_Button(phost, 10, 200, 130, 30, 28, 0, "Smart Mirror");
		if(!saved){
			Ft_Gpu_CoCmd_Button(phost, 200, 200, 110, 30, 28, 0, "Save data");
		} else{
			Ft_Gpu_CoCmd_Button(phost, 200, 200, 110, 30, 28, 0, "Saved");
		}

		StringArray[0] = '\0';
		strcat(StringArray,"Outside: ");
		Ft_Gpu_Hal_Dec2Ascii(StringArray,(ft_int32_t)tempOut);
		strcat(StringArray," C");
		Ft_Gpu_CoCmd_Text(phost, 10, 20, 26, 0, StringArray);
		
		StringArray[0] = '\0';
		strcat(StringArray,"Inside: ");
		Ft_Gpu_Hal_Dec2Ascii(StringArray,(ft_int32_t)tempIn);
		strcat(StringArray," C");
		Ft_Gpu_CoCmd_Text(phost, 10, 40, 26, 0, StringArray);
		
		StringArray[0] = '\0';
		strcat(StringArray,"Engine: ");
		Ft_Gpu_Hal_Dec2Ascii(StringArray,(ft_int32_t)tempEngine);
		strcat(StringArray," C");
		Ft_Gpu_CoCmd_Text(phost, 10, 60, 26, 0, StringArray);

		StringArray[0] = '\0';
		strcat(StringArray,"GPS: ");
		Ft_Gpu_CoCmd_Text(phost, 220, 20, 26, 0, StringArray);

		ReadWord = Ft_Gpu_Hal_Rd32(phost, REG_TOUCH_DIRECT_XY);
		yvalue = (int16)(ReadWord & 0xffff);
		xvalue = (int16)((ReadWord>>16) & 0xffff);

		if(xvalue > 70 && xvalue < 460 && yvalue > 70 && yvalue < 190){
			printf("Smart mirror \n");
			screenNR = 2;
		} else if(xvalue > 630 && xvalue < 950 && yvalue > 70 && yvalue < 190){
			saved = !saved;
			printf("Save Data = %i\n", saved);
		} else
			printf("x = %i y = %i\n", xvalue, yvalue);

		Ft_App_WrCoCmd_Buffer(phost,DISPLAY());
		Ft_Gpu_CoCmd_Swap(phost);

		/* Download the commands into fifo */
		Ft_App_Flush_Co_Buffer(phost);

		/* Wait till coprocessor completes the operation */
		Ft_Gpu_Hal_WaitCmdfifo_empty(phost);
		Ft_Gpu_Hal_Sleep(30);
}
示例#5
0
void CCompactAndRecoverStep::Cleanup()
	{
	CLEAR( iContactsDatabase2 );
	CPerformanceFunctionalityBase::Cleanup();
	}
示例#6
0
/*
 - matcher - the actual matching engine
 == static int matcher(struct re_guts *g, const char *string, \
 ==	size_t nmatch, regmatch_t pmatch[], int eflags);
 */
static int			/* 0 success, REG_NOMATCH failure */
matcher(struct re_guts *g,
	const char *string,
	size_t nmatch,
	regmatch_t pmatch[],
	int eflags)
{
	const char *endp;
	int i;
	struct match mv;
	struct match *m = &mv;
	const char *dp;
	const sopno gf = g->firststate+1;	/* +1 for OEND */
	const sopno gl = g->laststate;
	const char *start;
	const char *stop;
	/* Boyer-Moore algorithms variables */
	const char *pp;
	int cj, mj;
	const char *mustfirst;
	const char *mustlast;
	int *matchjump;
	int *charjump;

	/* simplify the situation where possible */
	if (g->cflags&REG_NOSUB)
		nmatch = 0;
	if (eflags&REG_STARTEND) {
		start = string + pmatch[0].rm_so;
		stop = string + pmatch[0].rm_eo;
	} else {
		start = string;
		stop = start + strlen(start);
	}
	if (stop < start)
		return(REG_INVARG);

	/* prescreening; this does wonders for this rather slow code */
	if (g->must != NULL) {
		if (g->charjump != NULL && g->matchjump != NULL) {
			mustfirst = g->must;
			mustlast = g->must + g->mlen - 1;
			charjump = g->charjump;
			matchjump = g->matchjump;
			pp = mustlast;
			for (dp = start+g->mlen-1; dp < stop;) {
				/* Fast skip non-matches */
				while (dp < stop && charjump[(int)*dp])
					dp += charjump[(int)*dp];

				if (dp >= stop)
					break;

				/* Greedy matcher */
				/* We depend on not being used for
				 * for strings of length 1
				 */
				while (*--dp == *--pp && pp != mustfirst);

				if (*dp == *pp)
					break;

				/* Jump to next possible match */
				mj = matchjump[pp - mustfirst];
				cj = charjump[(int)*dp];
				dp += (cj < mj ? mj : cj);
				pp = mustlast;
			}
			if (pp != mustfirst)
				return(REG_NOMATCH);
		} else {
			for (dp = start; dp < stop; dp++)
				if (*dp == g->must[0] &&
				    stop - dp >= g->mlen &&
				    memcmp(dp, g->must, (size_t)g->mlen) == 0)
					break;
			if (dp == stop)		/* we didn't find g->must */
				return(REG_NOMATCH);
		}
	}

	/* match struct setup */
	m->g = g;
	m->eflags = eflags;
	m->pmatch = NULL;
	m->lastpos = NULL;
	m->offp = string;
	m->beginp = start;
	m->endp = stop;
	STATESETUP(m, 4);
	SETUP(m->st);
	SETUP(m->fresh);
	SETUP(m->tmp);
	SETUP(m->empty);
	CLEAR(m->empty);
	ZAPSTATE(&m->mbs);

	/* Adjust start according to moffset, to speed things up */
	if (g->moffset > -1)
		start = ((dp - g->moffset) < start) ? start : dp - g->moffset;

	/* this loop does only one repetition except for backrefs */
	for (;;) {
		endp = fast(m, start, stop, gf, gl);
		if (endp == NULL) {		/* a miss */
			if (m->pmatch != NULL)
				free((char *)m->pmatch);
			if (m->lastpos != NULL)
				free((char *)m->lastpos);
			STATETEARDOWN(m);
			return(REG_NOMATCH);
		}
		if (nmatch == 0 && !g->backrefs)
			break;		/* no further info needed */

		/* where? */
		assert(m->coldp != NULL);
		for (;;) {
			NOTE("finding start");
			endp = slow(m, m->coldp, stop, gf, gl);
			if (endp != NULL)
				break;
			assert(m->coldp < m->endp);
			m->coldp += XMBRTOWC(NULL, m->coldp,
			    m->endp - m->coldp, &m->mbs, 0);
		}
		if (nmatch == 1 && !g->backrefs)
			break;		/* no further info needed */

		/* oh my, he wants the subexpressions... */
		if (m->pmatch == NULL)
			m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
							sizeof(regmatch_t));
		if (m->pmatch == NULL) {
			STATETEARDOWN(m);
			return(REG_ESPACE);
		}
		for (i = 1; i <= m->g->nsub; i++)
			m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
		if (!g->backrefs && !(m->eflags&REG_BACKR)) {
			NOTE("dissecting");
			dp = dissect(m, m->coldp, endp, gf, gl);
		} else {
			if (g->nplus > 0 && m->lastpos == NULL)
				m->lastpos = malloc((g->nplus+1) *
						sizeof(const char *));
			if (g->nplus > 0 && m->lastpos == NULL) {
				free(m->pmatch);
				STATETEARDOWN(m);
				return(REG_ESPACE);
			}
			NOTE("backref dissect");
			dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
		}
		if (dp != NULL)
			break;

		/* uh-oh... we couldn't find a subexpression-level match */
		assert(g->backrefs);	/* must be back references doing it */
		assert(g->nplus == 0 || m->lastpos != NULL);
		for (;;) {
			if (dp != NULL || endp <= m->coldp)
				break;		/* defeat */
			NOTE("backoff");
			endp = slow(m, m->coldp, endp-1, gf, gl);
			if (endp == NULL)
				break;		/* defeat */
			/* try it on a shorter possibility */
#ifndef NDEBUG
			for (i = 1; i <= m->g->nsub; i++) {
				assert(m->pmatch[i].rm_so == -1);
				assert(m->pmatch[i].rm_eo == -1);
			}
#endif
			NOTE("backoff dissect");
			dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
		}
		assert(dp == NULL || dp == endp);
		if (dp != NULL)		/* found a shorter one */
			break;

		/* despite initial appearances, there is no match here */
		NOTE("false alarm");
		/* recycle starting later */
		start = m->coldp + XMBRTOWC(NULL, m->coldp,
		    stop - m->coldp, &m->mbs, 0);
		assert(start <= stop);
	}

	/* fill in the details if requested */
	if (nmatch > 0) {
		pmatch[0].rm_so = m->coldp - m->offp;
		pmatch[0].rm_eo = endp - m->offp;
	}
	if (nmatch > 1) {
		assert(m->pmatch != NULL);
		for (i = 1; i < nmatch; i++)
			if (i <= m->g->nsub)
				pmatch[i] = m->pmatch[i];
			else {
				pmatch[i].rm_so = -1;
				pmatch[i].rm_eo = -1;
			}
	}

	if (m->pmatch != NULL)
		free((char *)m->pmatch);
	if (m->lastpos != NULL)
		free((char *)m->lastpos);
	STATETEARDOWN(m);
	return(0);
}
示例#7
0
void BookPGNReadFromFile (const char *file)
/****************************************************************************
 *
 *  To read a game from a PGN file and store out the hash entries to book.
 *
 ****************************************************************************/
{
   FILE *fp;
   int moveno, ngames = 0;
   time_t t1, t2;
   double et;
   int error;

   /* TODO: Fix reading from file */

   et = 0.0;
   t1 = time(NULL);

   fp = fopen (file, "r");
   if (fp == NULL)
   {
     fprintf(stderr, "Cannot open file %s: %s\n", 
	     file, strerror(errno));
     return;
   }
   yyin = fp;

   /* Maybe add some more clever error handling later */
   if (BookBuilderOpen() != BOOK_SUCCESS)
     return;
   newpos = existpos = 0;
   data_dest = DEST_BOOK;

   while(1) {
     InitVars ();
     NewPosition ();
     CLEAR (flags, MANUAL);
     CLEAR (flags, THINK);
     myrating = opprating = 0;

     error = yylex();
     if (error) break;

     ngames++;
     if (ngames % 10 == 0) printf("Games processed: %d\r",ngames);
     fflush(stdout);
   }

   fclose (fp);
   if (BookBuilderClose() != BOOK_SUCCESS) {
     perror("Error writing opening book during BookBuilderClose");
   }

   /* Reset the board otherwise we leave the last position in the book
      on the board. */
   InitVars ();
   NewPosition ();
   CLEAR (flags, MANUAL);
   CLEAR (flags, THINK);
   myrating = opprating = 0;

   t2 = time(NULL);
   et += difftime(t2, t1);
   putchar('\n');

   /* Handle divide-by-zero problem */
   if (et < 0.5) { et = 1.0; };

   printf("Time = %.0f seconds\n", et);
   printf("Games compiled: %d\n",ngames);
   printf("Games per second: %f\n",ngames/et);
   printf("Positions scanned: %d\n",newpos+existpos);
   printf("Positions per second: %f\n",(newpos+existpos)/et);
   printf("New & unique added: %d positions\n",newpos);
   printf("Duplicates not added: %d positions\n",existpos);
}
示例#8
0
int main(int argc, char **argv) {
	char buf[4096];
	pid_t chld_listener=-1, chld_sender=-1;
	uint8_t status=0, msg_type=0, ecount=0;
	size_t msg_len=0;
	struct sigaction chsa;
	uint8_t *ptr=NULL;
	int lports=IPC_BINDPORT_START;
	uint8_t all_done=0;
	char verbose_level[4];
	drone_t *c=NULL;

	ident=IDENT_MASTER;
	ident_name_ptr=IDENT_MASTER_NAME;

	CLEAR(buf);

	s=(settings_t *)xmalloc(sizeof(settings_t));
	memset(s, 0, sizeof(settings_t));
	s->vi=(interface_info_t *)xmalloc(sizeof(interface_info_t));
	memset(s->vi, 0, sizeof(interface_info_t));

	s->forked=0; /* not required, for clarity */

	/* s->display=&display_builtin; */

	getconfig_argv(argc, argv);

	if (s->interface_str == NULL) {
		if (get_default_route_interface(&s->interface_str) != 1) {
			MSG(M_WARN, "Can't find default route, and matching device, using default interface `%s'", DEFAULT_NETDEV);
			s->interface_str=xstrdup(DEFAULT_NETDEV);
		}
		if (s->verbose > 1) {
			MSG(M_VERB, "Using interface %s", s->interface_str);
		}
	}

	if (!(GET_OVERRIDE())) {
		/* let the listener tell us then, the user didnt request a specific address */
		CLEAR(s->vi->myaddr_s); CLEAR(s->vi->hwaddr_s);
		sprintf(s->vi->myaddr_s, "0.0.0.0");
		sprintf(s->vi->hwaddr_s, "00:00:00:00:00:00");
		memset(&s->vi->myaddr, 0, sizeof(s->vi->myaddr));
		memset(&s->vi->hwaddr, 0, sizeof(s->vi->hwaddr));
        }
	else {
		/* complete the information we need like hwaddr, cause its impossible to specify that currently */
		if (s->verbose > 1) MSG(M_DBG2, "Spoofing from `%s [%s]'", s->vi->myaddr_s, s->vi->hwaddr_s);

		/* the ip info is already filled in, so just complete the rest */
		CLEAR(s->vi->hwaddr_s);
		sprintf(s->vi->hwaddr_s, "00:00:00:00:00:00");
		memset(&s->vi->hwaddr, 0, sizeof(s->vi->hwaddr));
	}
	s->vi->mtu=0; /* the listener HAS to tell us this, seeing as how the real limitation is there */

	time(&(s->s_time));

	if (s->forklocal) {
		if (s->verbose > 5) MSG(M_DBG2, "children will be forked, setting up signal handler for them");

		memset(&chsa, 0, sizeof(chsa));
		chsa.sa_handler=&child_dead;
		if (sigaction(SIGCHLD, &chsa, NULL) < 0) {
			MSG(M_ERR, "Cant register SIGCHLD handler");
			terminate(TERM_ERROR);
		}
	}

	arc4random_stir();

	if (init_modules() < 0) {
		MSG(M_ERR, "Can't initialize module structures, quiting");
		terminate(TERM_ERROR);
	}

	if (ipc_init() < 0) {
		MSG(M_ERR, "Cant initialize IPC, quiting");
		terminate(TERM_ERROR);
	}

	if (s->verbose > 0) {
		char low[32], high[32];
		uint32_t ips=0;

		CLEAR(low); CLEAR(high);
		ips=ntohl(s->_low_ip);
		snprintf(low, sizeof(low) -1, "%s", inet_ntoa((*(struct in_addr *)&ips)));
		ips=ntohl(s->_high_ip);
		snprintf(high, sizeof(high) -1, "%s", inet_ntoa((*(struct in_addr *)&ips)));

		MSG(M_VERB, "Scanning: %s -> %s : %s from %s [%s] at %u pps", low, high, (s->mode == MODE_ARPSCAN ? "Arp" : s->port_str), s->vi->myaddr_s, s->vi->hwaddr_s, s->pps);
	}

	if (s->verbose > 3) MSG(M_DBG1, "Main process id is %d", getpid());

	snprintf(verbose_level, sizeof(verbose_level) -1, "%d", s->verbose);

	/* initialize senders */
	if ((s->forklocal & FORK_LOCAL_SENDER) == FORK_LOCAL_SENDER) {
		if (s->drone_str == NULL) {
			s->drone_str=xstrdup(DEF_SENDER);
			if (s->verbose > 5) MSG(M_DBG2, "Added default sender to drone list `%s'", s->drone_str);
		}
		else {
			char newstr[128];

			CLEAR(newstr);
			snprintf(newstr, sizeof(newstr) -1, "%s,%s", s->drone_str, DEF_SENDER);
			xfree(s->drone_str);
			s->drone_str=xstrdup(newstr);
		}

		chld_sender=fork();
		if (chld_sender < 0) {
			MSG(M_ERR, "Can't fork sender: %s", strerror(errno));
			terminate(TERM_ERROR);
		}
		if (chld_sender == 0) {
			char *argz[5];
			char *envz[2];

			argz[0]=SENDERNAME;
			argz[1]=s->mod_dir;
			argz[2]=verbose_level;
			argz[3]=s->interface_str;
			argz[4]=NULL;

			envz[0]='\0';

			execve(SENDER_PATH, argz, envz);
			MSG(M_ERR, "execve %s fails", SENDER_PATH);
			terminate(TERM_ERROR);
		}
		child_running++;
		s->forklocal &= ~(FORK_LOCAL_SENDER);
	}
	else if (s->verbose > 5) {
		MSG(M_DBG2, "No local sender will be forked");
	}

	/* initialize listeners */
	if ((s->forklocal & FORK_LOCAL_LISTENER) == FORK_LOCAL_LISTENER) {
		if (s->drone_str == NULL) {
			s->drone_str=xstrdup(DEF_LISTENER);
			if (s->verbose > 5) MSG(M_DBG2, "Adding default listener to drone list");
		}
		else {
			char newstr[128];

			CLEAR(newstr);
			snprintf(newstr, sizeof(newstr) -1, "%s,%s", s->drone_str, DEF_LISTENER);
			xfree(s->drone_str);
			s->drone_str=xstrdup(newstr);
		}

		chld_listener=fork();
		if (chld_listener < 0) {
			MSG(M_ERR, "Can't fork listener: %s", strerror(errno));
			terminate(TERM_ERROR);
		}
		if (chld_listener == 0) {
			char *argz[7];
			char *envz[2];
			char mtu[8];

			CLEAR(mtu);
			snprintf(mtu, sizeof(mtu) -1, "%u", s->vi->mtu);

			argz[0]=LISTENERNAME;
			argz[1]=s->mod_dir;
			argz[2]=verbose_level;
			argz[3]=s->interface_str;
			argz[4]=s->vi->myaddr_s;
			argz[5]=s->vi->hwaddr_s;
			argz[6]=NULL;

			envz[0]='\0';

			execve(LISTENER_PATH, argz, envz);
			MSG(M_ERR, "execve %s fails", LISTENER_PATH);
			terminate(TERM_ERROR);
		}
		child_running++;
		s->forklocal &= ~(FORK_LOCAL_LISTENER);
	}
	else if (s->verbose > 5) {
		MSG(M_DBG2, "No local listener will be forked");
	}

	/* we need these modules cause we are hardcoded as a output conduit for now XXX */
	if (init_output_modules() < 0) {
		MSG(M_ERR, "Can't initialize output module structures, quiting");
		terminate(TERM_ERROR);
	}
	if (init_report_modules() < 0) {
		MSG(M_ERR, "Can't initialize report module structures, quiting");
		terminate(TERM_ERROR);
	}

	if (s->verbose > 2) MSG(M_DBG1, "drones: %s", s->drone_str);

	if (parse_drone_list((const char *)s->drone_str) < 0) {
		terminate(TERM_ERROR);
	}
	else if (s->verbose > 5) {
		MSG(M_DBG1, "Drone list `%s' parsed correctly", s->drone_str);
	}

	/* do stuff to figure out if there are working drones */
	if (s->verbose > 4) MSG(M_DBG1, "Drone list is %d big, connecting to them.", s->dlh->size);

	do {
		uint8_t *dummy=NULL;
		struct sockaddr_in lbind;

		c=s->dlh->head;

		if (c == NULL) {
			MSG(M_ERR, "no drones?, thats not going to work");
			terminate(TERM_ERROR);
		}

		for (c=s->dlh->head ; c != NULL ; c=c->next) {
			if (s->verbose > 6) MSG(M_DBG1, "THIS NODE -> status: %d type: %s host: %s port: %d socket: %d (%d out of %d ready)", c->status, (c->type == DRONE_TYPE_SENDER ? "Sender" : "Listener") , inet_ntoa(c->dsa.sin_addr), ntohs(c->dsa.sin_port), c->s, all_done, s->dlh->size);

			if (ecount > MAX_ERRORS) {
				MSG(M_ERR, "Too many errors, exiting now");
				terminate(TERM_ERROR);
			}

			switch (c->status) {

				/* connect to it */
				case DRONE_STATUS_UNKNOWN:
					memset(&lbind, 0, sizeof(lbind));
					lbind.sin_port=htons(lports++);

					if (c->s == -1 && create_client_socket(c, (struct sockaddr_in *)&lbind) < 0) {
						c->s=-1;
						usleep(50000);
						ecount++;
					}
					else {
						c->status=DRONE_STATUS_CONNECTED;
					}
					break;

				/* find out what it is */
				case DRONE_STATUS_CONNECTED:
					c->type=DRONE_TYPE_UNKNOWN;
					if (send_message(c->s, MSG_IDENT, MSG_STATUS_OK, dummy, 0) < 0) {
						ecount++;
						MSG(M_ERR, "Cant ident message node, marking as dead");
						if (ecount > MAX_ERRORS) {
							mark_dead(c);
							break;
						}
					}
					else {
						if (get_singlemessage(c->s, &msg_type, &status, &ptr, &msg_len) != 1) {
							MSG(M_ERR, "Unexpected message response from fd %d, marking as dead", c->s);
							mark_dead(c);
						}
						switch (msg_type) {
							case MSG_IDENTSENDER:
								c->type=DRONE_TYPE_SENDER;
								s->senders++;
								break;
							case MSG_IDENTLISTENER:
								c->type=DRONE_TYPE_LISTENER;
								s->listeners++;
								break;
							default:
								MSG(M_ERR, "Unknown drone type from message %s", strmsgtype(msg_type));
								c->type=DRONE_TYPE_UNKNOWN;
						}

						if (send_message(c->s, MSG_ACK, MSG_STATUS_OK, dummy, 0) < 0) {
							MSG(M_ERR, "Cant ack ident message from node on fd %d, marking as dead", c->s);
							mark_dead(c);
						}

						c->status=DRONE_STATUS_IDENT;
					}
					break;

				/* wait for it to say its ready */
				case DRONE_STATUS_IDENT:
					if (get_singlemessage(c->s, &msg_type, &status, &ptr, &msg_len) != 1) {
						MSG(M_ERR, "Unexpected message reply from drone on fd %d, marking as dead", c->s);
						mark_dead(c);
					}
					else if (msg_type == MSG_READY) {
						c->status=DRONE_STATUS_READY;
						if (s->verbose > 3) MSG(M_DBG1, "drone on fd %d is ready", c->s);
						if (c->type == DRONE_TYPE_LISTENER) {
							union {
								listener_info_t *l;
								uint8_t *ptr;
							} l_u;
							struct in_addr ia;

							if (msg_len != sizeof(listener_info_t)) {
								MSG(M_ERR, "Listener didnt send me the correct information, marking dead");
								mark_dead(c);
							}
							l_u.ptr=ptr;
							s->vi->myaddr.sin_addr.s_addr=l_u.l->myaddr;
							ia.s_addr=s->vi->myaddr.sin_addr.s_addr;
							s->vi->mtu=l_u.l->mtu;
							memcpy(s->vi->hwaddr, l_u.l->hwaddr, THE_ONLY_SUPPORTED_HWADDR_LEN);
							snprintf(s->vi->hwaddr_s, sizeof(s->vi->hwaddr_s) -1, "%.02x:%.02x:%.02x:%.02x:%.02x:%.02x", l_u.l->hwaddr[0], l_u.l->hwaddr[1], l_u.l->hwaddr[2], l_u.l->hwaddr[3], l_u.l->hwaddr[4], l_u.l->hwaddr[5]);
							snprintf(s->vi->myaddr_s, sizeof(s->vi->myaddr_s) -1, "%s", inet_ntoa(ia));

							if (s->verbose > 2) MSG(M_DBG1, "Listener info gave me the following address information `%s [%s]' with mtu %u", s->vi->myaddr_s, s->vi->hwaddr_s, s->vi->mtu);
						}
					}
					else {
						MSG(M_ERR, "drone isnt ready on fd %d, marking as dead", c->s);
						mark_dead(c);
					}
					break;

				case DRONE_STATUS_READY:
					all_done++;
					break;

				case DRONE_STATUS_DEAD:
					all_done++;
					MSG(M_WARN, "Dead drone in list on fd %d", c->s);
					break;

			} /* switch node status */
		} /* step though list */
	} while (all_done < s->dlh->size);

	/* XXX remove this and fix */
	if (s->senders == 0 && GET_SENDDRONE()) {
		/* XXX */
		MSG(M_ERR, "No senders for scan, giving up and rudley disconnecting from other drones without warning");
		terminate(TERM_ERROR);
	}

	if (s->listeners == 0 && GET_LISTENDRONE()) {
		/* XXX */
		MSG(M_ERR, "No listeners for scan, giving up and rudley disconnecting from other drones without warning");
		terminate(TERM_ERROR);
	}

	if (s->verbose > 5) MSG(M_DBG2, "Running scan");
	run_mode();

	time(&(s->e_time));

	if (s->verbose > 4) MSG(M_DBG2, "Main shuting down output modules");
	fini_output_modules();
	fini_report_modules();
	if (s->verbose > 4) MSG(M_DBG2, "Main exiting");

	terminate(TERM_NORMAL);
}
示例#9
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_parsepropex(PRIM_PROTOTYPE)
{
	struct inst*	oper1 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper2 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper3 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper4 = NULL; /* prevents reentrancy issues! */
	stk_array*		vars;
	const char*		mpi;
	char*			str = 0;
	array_iter		idx;
	extern int		varc; /* from msgparse.c */
	int				mvarcnt = 0;
	char*			buffers = NULL;
	int				novars;
	int				hashow = 0;
	int				i;
	int             len;
	char			tname[BUFFER_LEN];
	char			buf[BUFFER_LEN];

	CHECKOP(4);

	oper4 = POP(); /* int:Private */
	oper3 = POP(); /* dict:Vars */
	oper2 = POP(); /* str:Prop */
	oper1 = POP(); /* ref:Object */

	if (mlev < 3)
		abort_interp("Mucker level 3 or greater required.");

	if (oper1->type != PROG_OBJECT)
		abort_interp("Non-object argument. (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument. (2)");
	if (oper3->type != PROG_ARRAY)
		abort_interp("Non-array argument. (3)");
	if (oper3->data.array && (oper3->data.array->type != ARRAY_DICTIONARY))
		abort_interp("Dictionary array expected. (3)");
	if (oper4->type != PROG_INTEGER)
		abort_interp("Non-integer argument. (4)");

	if (!valid_object(oper1))
		abort_interp("Invalid object. (1)");
	if (!oper2->data.string)
		abort_interp("Empty string argument. (2)");
	if ((oper4->data.number != 0) && (oper4->data.number != 1))
		abort_interp("Integer of 0 or 1 expected. (4)");

	CHECKREMOTE(oper1->data.objref);

	if (!prop_read_perms(ProgUID, oper1->data.objref, oper2->data.string->data, mlev))
		abort_interp("Permission denied.");

	len = oper2->data.string->length;
	strcpyn(tname, sizeof(tname), oper2->data.string->data);
	while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
		tname[len] = '\0';
	}

	mpi		= get_property_class(oper1->data.objref, tname);
	vars	= oper3->data.array;
	novars	= array_count(vars);

	if (check_mvar_overflow(novars))
		abort_interp("Out of MPI variables. (3)");

	if (array_first(vars, &idx))
	{
		do
		{
			array_data*	val = array_getitem(vars, &idx);

			if (idx.type != PROG_STRING)
			{
				CLEAR(&idx);
				abort_interp("Only string keys supported. (3)");
			}

			if (idx.data.string == NULL)
			{
				CLEAR(&idx);
				abort_interp("Empty string keys not supported. (3)");
			}

			if (strlen(idx.data.string->data) > MAX_MFUN_NAME_LEN)
			{
				CLEAR(&idx);
				abort_interp("Key too long to be an MPI variable. (3)");
			}

			switch(val->type)
			{
				case PROG_INTEGER:
				case PROG_FLOAT:
				case PROG_OBJECT:
				case PROG_STRING:
				case PROG_LOCK:
				break;

				default:
					CLEAR(&idx);
					abort_interp("Only integer, float, dbref, string and lock values supported. (3)");
				break;
			}

			if (string_compare(idx.data.string->data, "how") == 0)
				hashow = 1;
		}
		while(array_next(vars, &idx));
	}

	if (mpi && *mpi)
	{
		if (novars > 0)
		{
			mvarcnt = varc;

			if ((buffers = (char*)malloc(novars * BUFFER_LEN)) == NULL)
				abort_interp("Out of memory.");

			if (array_first(vars, &idx))
			{
				i = 0;

				do
				{
					char*		var_buf = buffers + (i++ * BUFFER_LEN);
					array_data*	val;

					val = array_getitem(vars, &idx);

					switch(val->type)
					{
						case PROG_INTEGER:
							snprintf(var_buf, BUFFER_LEN, "%i", val->data.number);
						break;

						case PROG_FLOAT:
							snprintf(var_buf, BUFFER_LEN, "%g", val->data.fnumber);
						break;

						case PROG_OBJECT:
							snprintf(var_buf, BUFFER_LEN, "#%i", val->data.objref);
						break;

						case PROG_STRING:
							strncpy(var_buf, DoNullInd(val->data.string), BUFFER_LEN);
						break;

						case PROG_LOCK:
							strncpy(var_buf, unparse_boolexp(ProgUID, val->data.lock, 1), BUFFER_LEN);
						break;

						default:
							var_buf[0] = '\0';
						break;
					}

					var_buf[BUFFER_LEN - 1] = '\0';

					new_mvar(idx.data.string->data, var_buf);
				}
				while(array_next(vars, &idx));
			}
		}

		result = 0;

		if (oper4->data.number)
			result |= MPI_ISPRIVATE;

		if (Prop_Blessed(oper1->data.objref, oper2->data.string->data))
			result |= MPI_ISBLESSED;

		if (hashow)
			result |= MPI_NOHOW;

		str = do_parse_mesg(fr->descr, player, oper1->data.objref, mpi, "(parsepropex)", buf, sizeof(buf), result);

		if (novars > 0)
		{
			if (array_first(vars, &idx))
			{
				i = 0;

				do
				{
					char*		var_buf = buffers + (i++ * BUFFER_LEN);
					struct inst	temp;

					temp.type			= PROG_STRING;
					temp.data.string	= alloc_prog_string(var_buf);

					array_setitem(&vars, &idx, &temp);

					CLEAR(&temp);
				}
				while(array_next(vars, &idx));
			}

			free(buffers);

			varc = mvarcnt;
		}
	}

	oper3->data.array = NULL;

	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
	CLEAR(oper4);

	PushArrayRaw(vars);
	PushString(str);
}
示例#10
0
文件: mroute.c 项目: OpenVPN/openvpn
void
mroute_addr_init(struct mroute_addr *addr)
{
    CLEAR(*addr);
}
示例#11
0
void* RecieveClientThread(void* data) // recieve udp packets containing message/voice to the other client
{
	struct thread* new_data = data;	

	printf("you are recieving from %s IP address\n", new_data->IPaddr);
	PaStreamParameters outputParam;
	PaStream *stream = NULL;
	char *sampleBlock;
	int i, sockfd, numBytes;
	PaError error;
	struct sockaddr_in servaddr, cliaddr;

	sockfd = socket(AF_INET, SOCK_DGRAM, 0); // make udp socket
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = inet_addr(new_data->IPaddr);
	servaddr.sin_port = htons(new_data->Port);

	bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr));
	fflush(stdout); 
	numBytes = FRAMES_BUFFER * SAMPLE_SIZE * 2;
	sampleBlock = (char *) malloc(numBytes);
	if(sampleBlock == NULL){
		printf("Could not allocate record array.\n");
		exit(1);
	}
	CLEAR(sampleBlock);
 
	printf("Initializing the devices...\n"); 
	error = Pa_Initialize();
	if(error != paNoError) 
		goto errorState;
 
	outputParam.device = Pa_GetDefaultOutputDevice();
  	printf( "Output device # %d.\n", outputParam.device );
	outputParam.channelCount = 2;
	outputParam.sampleFormat = paFloat32;
	outputParam.suggestedLatency = Pa_GetDeviceInfo( outputParam.device )->defaultHighOutputLatency;
	outputParam.hostApiSpecificStreamInfo = NULL;	
 
	error = Pa_OpenStream(&stream, NULL, &outputParam, SAMPLE_RATE, FRAMES_BUFFER, paClipOff, NULL, NULL );
  
	if( error != paNoError ) 
		goto errorState;
 
	error = Pa_StartStream( stream );
	if( error != paNoError ) 
		goto errorState;

	printf("The client is talking to you\n"); 
	fflush(stdout);

	while(1){
		recvfrom(sockfd, sampleBlock, 4096, 0, NULL, NULL); // recieve packet containing voice data from the other client
		error = Pa_WriteStream(stream, sampleBlock, FRAMES_BUFFER);
 		if(error && UNDERFLOW) 
			goto exitState;
	}

	error = Pa_StopStream(stream);
	if(error != paNoError) 
		goto errorState;
 
	CLEAR(sampleBlock);
	free(sampleBlock);
	Pa_Terminate();
	return 0;
 
exitState:
	if(stream){
		Pa_AbortStream(stream);
		Pa_CloseStream(stream);
	}
	free(sampleBlock);
	Pa_Terminate();
	if(error & paOutputUnderflow)
		fprintf(stderr, "Output Underflow.\n");
	return (void*)-2;
 
errorState:
	if(stream) {
		Pa_AbortStream(stream);
		Pa_CloseStream(stream);
	}
	free(sampleBlock);
	Pa_Terminate();
	fprintf(stderr, "An error occured while using the portaudio stream\n");
	fprintf(stderr, "Error number: %d\n", error);
	fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(error));
	return (void*)-1;

}
示例#12
0
文件: win32.c 项目: angelol/iOpenVPN
void
semaphore_clear (struct semaphore *s)
{
  CLEAR (*s);
}
示例#13
0
文件: win32.c 项目: angelol/iOpenVPN
void
window_title_clear (struct window_title *wt)
{
  CLEAR (*wt);
}
示例#14
0
文件: win32.c 项目: angelol/iOpenVPN
void
win32_signal_open (struct win32_signal *ws,
		   int force,
		   const char *exit_event_name,
		   bool exit_event_initial_state)
{
  CLEAR (*ws);

  ws->mode = WSO_MODE_UNDEF;
  ws->in.read = INVALID_HANDLE_VALUE;
  ws->in.write = INVALID_HANDLE_VALUE;
  ws->console_mode_save = 0;
  ws->console_mode_save_defined = false;

  if (force == WSO_NOFORCE || force == WSO_FORCE_CONSOLE)
    {
      /*
       * Try to open console.
       */
      ws->in.read = GetStdHandle (STD_INPUT_HANDLE);
      if (ws->in.read != INVALID_HANDLE_VALUE)
	{
	  if (GetConsoleMode (ws->in.read, &ws->console_mode_save))
	    {
	      /* running on a console */
	      const DWORD new_console_mode = ws->console_mode_save
		& ~(ENABLE_WINDOW_INPUT
		    | ENABLE_PROCESSED_INPUT
		    | ENABLE_LINE_INPUT
		    | ENABLE_ECHO_INPUT 
		    | ENABLE_MOUSE_INPUT);

	      if (new_console_mode != ws->console_mode_save)
		{
		  if (!SetConsoleMode (ws->in.read, new_console_mode))
		    msg (M_ERR, "Error: win32_signal_open: SetConsoleMode failed");
		  ws->console_mode_save_defined = true;
		}
	      ws->mode = WSO_MODE_CONSOLE;
	    }
	  else
	    ws->in.read = INVALID_HANDLE_VALUE; /* probably running as a service */
	}
    }

  /*
   * If console open failed, assume we are running
   * as a service.
   */
  if ((force == WSO_NOFORCE || force == WSO_FORCE_SERVICE)
      && !HANDLE_DEFINED (ws->in.read) && exit_event_name)
    {
      struct security_attributes sa;

      if (!init_security_attributes_allow_all (&sa))
	msg (M_ERR, "Error: win32_signal_open: init SA failed");

      ws->in.read = CreateEvent (&sa.sa,
				 TRUE,
				 exit_event_initial_state ? TRUE : FALSE,
				 exit_event_name);
      if (ws->in.read == NULL)
	{
	  msg (M_WARN|M_ERRNO, "NOTE: CreateEvent '%s' failed", exit_event_name);
	}
      else
	{
	  if (WaitForSingleObject (ws->in.read, 0) != WAIT_TIMEOUT)
	    msg (M_FATAL, "ERROR: Exit Event ('%s') is signaled", exit_event_name);
	  else
	    ws->mode = WSO_MODE_SERVICE;
	}
    }
}
示例#15
0
int
muf_debugger(int descr, dbref player, dbref program, const char *text, struct frame *fr)
{
    char cmd[BUFFER_LEN];
    char buf[BUFFER_LEN];
    char buf2[BUFFER_LEN];
    char *ptr, *ptr2, *arg;
    struct inst *pinst;
    dbref ref;
    int i, j, cnt;

    while (isspace(*text)) text++;
    strcpy(cmd, text);
    ptr = cmd + strlen(cmd);
    if (ptr > cmd) ptr--;
    while (ptr >= cmd && isspace(*ptr)) *ptr-- = '\0';
    for (arg = cmd; *arg && !isspace(*arg); arg++);
    if (*arg) *arg++ = '\0';
    if (!*cmd && fr->brkpt.lastcmd) {
        strcpy(cmd, fr->brkpt.lastcmd);
    } else {
        if (fr->brkpt.lastcmd)
            free(fr->brkpt.lastcmd);
        if (*cmd)
            fr->brkpt.lastcmd = string_dup(cmd);
    }
    /* delete triggering breakpoint, if it's only temp. */
    j = fr->brkpt.breaknum;
    if (j >= 0 && fr->brkpt.temp[j]) {
        for (j++; j < fr->brkpt.count; j++) {
            fr->brkpt.temp[j-1]         = fr->brkpt.temp[j];
            fr->brkpt.level[j-1]        = fr->brkpt.level[j];
            fr->brkpt.line[j-1]         = fr->brkpt.line[j];
            fr->brkpt.linecount[j-1]    = fr->brkpt.linecount[j];
            fr->brkpt.pc[j-1]           = fr->brkpt.pc[j];
            fr->brkpt.pccount[j-1]      = fr->brkpt.pccount[j];
            fr->brkpt.prog[j-1]         = fr->brkpt.prog[j];
        }
	fr->brkpt.count--;
    }
    fr->brkpt.breaknum = -1;
    
    if (!string_compare(cmd, "cont")) {
    } else if (!string_compare(cmd, "finish")) {
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot finish because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = fr->system.top - 1;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = program;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "stepi")) {
        i = atoi(arg);
        if (!i) i = 1;
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot stepi because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = -1;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = i;
        fr->brkpt.prog[j] = NOTHING;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "step")) {
        i = atoi(arg);
        if (!i) i = 1;
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot step because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = -1;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = i;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = NOTHING;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "nexti")) {
        i = atoi(arg);
        if (!i) i = 1;
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot nexti because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = fr->system.top;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = i;
        fr->brkpt.prog[j] = program;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "next")) {
        i = atoi(arg);
        if (!i) i = 1;
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot next because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = fr->system.top;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = i;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = program;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "exec")) {
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot finish because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
	if (!(pinst = funcname_to_pc(program, arg))) {
	    anotify_nolisten(player, CINFO "I don't know a function by that name.", 1);
            add_muf_read_event(descr, player, program, fr);
	    return 0;
	}
	if (fr->system.top >= STACK_SIZE) {
	    anotify_nolisten(player, CFAIL "That would exceed the system stack size for this program.", 1);
            add_muf_read_event(descr, player, program, fr);
	    return 0;
	}
	fr->system.st[fr->system.top].progref = program;
	fr->system.st[fr->system.top++].offset = fr->pc;
	fr->pc = pinst;
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = fr->system.top - 1;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = program;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "prim")) {
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Cannot finish because there are too many breakpoints set.", 1);
            add_muf_read_event(descr, player, program, fr);
            return 0;
        }
	if (!(i = primitive(arg))) {
	    anotify_nolisten(player, CINFO "I don't recognize that primitive.", 1);
            add_muf_read_event(descr, player, program, fr);
	    return 0;
	}
	if (fr->system.top >= STACK_SIZE) {
	    anotify_nolisten(player, CFAIL "That would exceed the system stack size for this program.", 1);
            add_muf_read_event(descr, player, program, fr);
	    return 0;
	}

	shstr.data[0] = '\0';
	shstr.links = 1;
	shstr.length= strlen(shstr.data);
	primset[0].type = PROG_FUNCTION;
	primset[0].line = 0;
	primset[0].data.string = &shstr;
	primset[1].type = PROG_DECLVAR;
	primset[1].line = 0;
	primset[1].data.number = 0;
	primset[1].type = PROG_PRIMITIVE;
	primset[1].line = 0;
	primset[1].data.number = /* i */ get_primitive(arg);
	primset[2].type = PROG_PRIMITIVE;
	primset[2].line = 0;
	primset[2].data.number = primitive("EXIT");

	fr->system.st[fr->system.top].progref = program;
	fr->system.st[fr->system.top++].offset = fr->pc;
	fr->pc = primset;
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 1;
        fr->brkpt.level[j] = fr->system.top - 1;
        fr->brkpt.line[j] = -1;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = program;
        fr->brkpt.bypass = 1;
        return 0;
    } else if (!string_compare(cmd, "break")) {
	add_muf_read_event(descr, player, program, fr);
        if (fr->brkpt.count >= MAX_BREAKS) {
            anotify_nolisten(player, CFAIL "Too many breakpoints set.", 1);
            return 0;
        }
        if (number(arg)) {
            i = atoi(arg);
        } else {
            if (!(pinst = funcname_to_pc(program, arg))) {
                anotify_nolisten(player, CINFO "I don't know a function by that name.", 1);
                return 0;
            } else {
                i = pinst->line;
            }
        }
        if (!i) i = fr->pc->line;
        j = fr->brkpt.count++;
        fr->brkpt.temp[j] = 0;
        fr->brkpt.level[j] = -1;
        fr->brkpt.line[j] = i;
        fr->brkpt.linecount[j] = -2;
        fr->brkpt.pc[j] = NULL;
        fr->brkpt.pccount[j] = -2;
        fr->brkpt.prog[j] = program;
        anotify_nolisten(player, CSUCC "Breakpoint set.", 1);
        return 0;
    } else if (!string_compare(cmd, "delete")) {
	add_muf_read_event(descr, player, program, fr);
        i = atoi(arg);
        if (!i) {
            anotify_nolisten(player, CINFO "Which breakpoint did you want to delete?", 1);
            return 0;
        }
        if (i < 1 || i > fr->brkpt.count) {
            anotify_nolisten(player, CFAIL "No such breakpoint.", 1);
            return 0;
        }
        j = i - 1;
        for (j++; j < fr->brkpt.count; j++) {
            fr->brkpt.temp[j-1]      = fr->brkpt.temp[j];
            fr->brkpt.level[j-1]     = fr->brkpt.level[j];
            fr->brkpt.line[j-1]      = fr->brkpt.line[j];
            fr->brkpt.linecount[j-1] = fr->brkpt.linecount[j];
            fr->brkpt.pc[j-1]        = fr->brkpt.pc[j];
            fr->brkpt.pccount[j-1]   = fr->brkpt.pccount[j];
            fr->brkpt.prog[j-1]      = fr->brkpt.prog[j];
        }
        fr->brkpt.count--;
        anotify_nolisten(player, CSUCC "Breakpoint deleted.", 1);
        return 0;
    } else if (!string_compare(cmd, "breaks")) {
        anotify_nolisten(player, CINFO "Breakpoints:", 1);
        for (i = 0; i < fr->brkpt.count; i++) {
            ptr = unparse_breakpoint(fr, i);
            notify_nolisten(player, ptr, 1);
        }
        anotify_nolisten(player, CINFO "Done.", 1);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "where")) {
        i = atoi(arg);
        muf_backtrace(player, program, i, fr);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "stack")) {
        anotify_nolisten(player, CINFO "*Argument stack top*", 1);
        i = atoi(arg);
        if (!i) i = STACK_SIZE;
        ptr = "";
        ref = program;
        for (j = fr->argument.top; j>0 && i-->0;) {
            cnt = 0;
            do {
                strcpy(buf, ptr);
                ptr = insttotext(&fr->argument.st[--j], buf2, sizeof(buf2), 4000, program);
                cnt++;
            } while (!string_compare(ptr, buf) && j>0);
            if (cnt > 1)
                notify_fmt(player, "     [repeats %d times]", cnt);
            if (string_compare(ptr, buf))
                notify_fmt(player, "%3d) %s", j+1, ptr);
        }
        anotify_nolisten(player, CINFO "Done.", 1);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "list") ||
	       !string_compare(cmd, "listi")) {
        int startline, endline;
        startline = endline = 0;
	add_muf_read_event(descr, player, program, fr);
        if ((ptr2 = (char *)index(arg, ','))) {
            *ptr2++ = '\0';
        } else {
            ptr2 = "";
        }
        if (!*arg) {
            if (fr->brkpt.lastlisted) {
                startline = fr->brkpt.lastlisted + 1;
            } else {
                startline = fr->pc->line;
            }
            endline = startline + 15;
        } else {
            if (!number(arg)) {
                if (!(pinst = funcname_to_pc(program, arg))) {
                    anotify_nolisten(player, CINFO "I don't know a function by that name. (starting arg, 1)", 1);
                    return 0;
                } else {
                    startline = pinst->line;
                    endline = startline + 15;
                }
            } else {
                if (*ptr2) {
                    endline = startline = atoi(arg);
                } else {
                    startline = atoi(arg) - 7;
                    endline = startline + 15;
                }
            }
        }
        if (*ptr2) {
            if (!number(ptr2)) {
                if (!(pinst = funcname_to_pc(program, ptr2))) {
                    anotify_nolisten(player, CINFO "I don't know a function by that name. (ending arg, 1)", 1);
                    return 0;
                } else {
                    endline = pinst->line;
                }
            } else {
                endline = atoi(ptr2);
            }
        }
        i = (DBFETCH(program)->sp.program.code +
                DBFETCH(program)->sp.program.siz - 1)->line;
        if (startline > i) {
            anotify_nolisten(player, CFAIL "Starting line is beyond end of program.", 1);
            return 0;
        }
        if (startline < 1) startline = 1;
        if (endline > i) endline = i;
        if (endline < startline) endline = startline;
        anotify_nolisten(player, CINFO "Listing:", 1);
	if (!string_compare(cmd, "listi")) {
	    for (i = startline; i <= endline; i++) {
		pinst = linenum_to_pc(program, i);
		if (pinst) {
		    sprintf(buf, "line %d: %s", i, (i == fr->pc->line) ?
			    show_line_prims(program, fr->pc, STACK_SIZE, 1) :
			    show_line_prims(program, pinst, STACK_SIZE, 0));
		    notify_nolisten(player, buf, 1);
		}
	    }
	} else {
	    list_proglines(player, program, fr, startline, endline);
	}
        fr->brkpt.lastlisted = endline;
        anotify_nolisten(player, CINFO "Done.", 1);
        return 0;
    } else if (!string_compare(cmd, "quit")) {
        anotify_nolisten(player, CINFO "Halting execution.", 1);
        return 1;
    } else if (!string_compare(cmd, "trace")) {
	add_muf_read_event(descr, player, program, fr);
        if (!string_compare(arg, "on")) {
            fr->brkpt.showstack = 1;
            anotify_nolisten(player, CSUCC "Trace turned on.", 1);
        } else if (!string_compare(arg, "off")) {
            fr->brkpt.showstack = 0;
            anotify_nolisten(player, CSUCC "Trace turned off.", 1);
        } else {
            sprintf(buf, CINFO "Trace is currently %s.",
                    fr->brkpt.showstack? "on" : "off");
            anotify_nolisten(player, buf, 1);
        }
        return 0;
    } else if (!string_compare(cmd, "words")) {
	list_program_functions(player, program, arg);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "print")) {
	debug_printvar(player, fr, arg);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "push")) {
	push_arg(player, fr, arg);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "pop")) {
	fr->argument.top--;
	CLEAR(fr->argument.st + fr->argument.top);
	anotify_nolisten(player, CSUCC "Stack item popped.", 1);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    } else if (!string_compare(cmd, "help")) {
notify_nolisten(player, "cont            continues execution until a breakpoint is hit.", 1);
notify_nolisten(player, "finish          completes execution of current function.", 1);
notify_nolisten(player, "step [NUM]      executes one (or NUM, 1) lines of muf.", 1);
notify_nolisten(player, "stepi [NUM]     executes one (or NUM, 1) muf instructions.", 1);
notify_nolisten(player, "next [NUM]      like step, except skips CALL and EXECUTE.", 1);
notify_nolisten(player, "nexti [NUM]     like stepi, except skips CALL and EXECUTE.", 1);
notify_nolisten(player, "break LINE#     sets breakpoint at given LINE number.", 1);
notify_nolisten(player, "break FUNCNAME  sets breakpoint at start of given function.", 1);
notify_nolisten(player, "breaks          lists all currently set breakpoints.", 1);
notify_nolisten(player, "delete NUM      deletes breakpoint by NUM, as listed by 'breaks'", 1);
notify_nolisten(player, "where [LEVS]    displays function call backtrace of up to num levels deep.", 1);
notify_nolisten(player, "stack [NUM]     shows the top num items on the stack.", 1);
notify_nolisten(player, "print v#        displays the value of given global variable #.", 1);
notify_nolisten(player, "print lv#       displays the value of given local variable #.", 1);
notify_nolisten(player, "trace [on|off]  turns on/off debug stack tracing.", 1);
notify_nolisten(player, "list [L1,[L2]]  lists source code of given line range.", 1);
notify_nolisten(player, "list FUNCNAME   lists source code of given function.", 1);
notify_nolisten(player, "listi [L1,[L2]] lists instructions in given line range.", 1);
notify_nolisten(player, "listi FUNCNAME  lists instructions in given function.", 1);
notify_nolisten(player, "words           lists all function word names in program.", 1);
notify_nolisten(player, "words PATTERN   lists all function word names that match PATTERN.", 1);
notify_nolisten(player, "exec FUNCNAME   calls given function with the current stack data.", 1);
notify_nolisten(player, "prim PRIMITIVE  executes given primitive with current stack data.", 1);
notify_nolisten(player, "push DATA       pushes an int, dbref, var, or string onto the stack.", 1);
notify_nolisten(player, "pop             pops top data item off the stack.", 1);
notify_nolisten(player, "help            displays this help screen.", 1);
notify_nolisten(player, "quit            stop execution here.", 1);
	add_muf_read_event(descr, player, program, fr);
	return 0;
    } else {
        anotify_nolisten(player, CINFO "I don't understand that debugger command. Type 'help' for help.", 1);
	add_muf_read_event(descr, player, program, fr);
        return 0;
    }
    return 0;
}
示例#16
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_getprop(PRIM_PROTOTYPE)
{
	const char *temp;
	PropPtr prptr;
	dbref obj2;

	CHECKOP(2);
	oper1 = POP();
	oper2 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper2))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper2->data.objref);
	{
		char type[BUFFER_LEN];
		int len = oper1->data.string->length;

		if (!prop_read_perms(ProgUID, oper2->data.objref, oper1->data.string->data, mlev))
			abort_interp("Permission denied.");

		strcpyn(type, sizeof(type), oper1->data.string->data);
		while (len-- > 0 && type[len] == PROPDIR_DELIMITER) {
			type[len] = '\0';
		}

		obj2 = oper2->data.objref;
		prptr = get_property(obj2, type);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) GETPROP: o=%d n=\"%s\"",
				 program, pc->line, oper2->data.objref, type);
#endif

		CLEAR(oper1);
		CLEAR(oper2);
		if (prptr) {
#ifdef DISKBASE
			propfetch(obj2, prptr);
#endif
			switch (PropType(prptr)) {
			case PROP_STRTYP:
				temp = PropDataStr(prptr);
				PushString(temp);
				break;
			case PROP_LOKTYP:
				if (PropFlags(prptr) & PROP_ISUNLOADED) {
					PushLock(TRUE_BOOLEXP);
				} else {
					PushLock(PropDataLok(prptr));
				}
				break;
			case PROP_REFTYP:
				PushObject(PropDataRef(prptr));
				break;
			case PROP_INTTYP:
				PushInt(PropDataVal(prptr));
				break;
			case PROP_FLTTYP:
				PushFloat(PropDataFVal(prptr));
				break;
			default:
				result = 0;
				PushInt(result);
				break;
			}
		} else {
			result = 0;
			PushInt(result);
		}

		/* if (Typeof(oper2->data.objref) != TYPE_PLAYER)
		   ts_lastuseobject(oper2->data.objref); */
	}
}
示例#17
0
struct http_proxy_info *
http_proxy_new (const struct http_proxy_options *o,
		struct auto_proxy_info *auto_proxy_info)
{
  struct http_proxy_info *p;
  struct http_proxy_options opt;

  if (auto_proxy_info)
    {
      if (o && o->server)
	{
	  /* if --http-proxy explicitly given, disable auto-proxy */
	  auto_proxy_info = NULL;
	}
      else
	{
	  /* if no --http-proxy explicitly given and no auto settings, fail */
	  if (!auto_proxy_info->http.server)
	    return NULL;

	  if (o)
	    {
	      opt = *o;
	    }
	  else
	    {
	      CLEAR (opt);
	  
	      /* These settings are only used for --auto-proxy */
	      opt.timeout = 5;
	      opt.http_version = "1.0";
	    }

	  opt.server = auto_proxy_info->http.server;
	  opt.port = auto_proxy_info->http.port;
	  if (!opt.auth_retry)
	    opt.auth_retry = PAR_ALL;

	  o = &opt;
	}
    }

  if (!o || !o->server)
    msg (M_FATAL, "HTTP_PROXY: server not specified");

  ASSERT (legal_ipv4_port (o->port));

  ALLOC_OBJ_CLEAR (p, struct http_proxy_info);
  p->options = *o;

  /* parse authentication method */
  p->auth_method = HTTP_AUTH_NONE;
  if (o->auth_method_string)
    {
      if (!strcmp (o->auth_method_string, "none"))
	p->auth_method = HTTP_AUTH_NONE;
      else if (!strcmp (o->auth_method_string, "basic"))
	p->auth_method = HTTP_AUTH_BASIC;
#if NTLM
      else if (!strcmp (o->auth_method_string, "ntlm"))
	p->auth_method = HTTP_AUTH_NTLM;
      else if (!strcmp (o->auth_method_string, "ntlm2"))
	p->auth_method = HTTP_AUTH_NTLM2;
#endif
      else
	msg (M_FATAL, "ERROR: unknown HTTP authentication method: '%s'",
	     o->auth_method_string);
    }

  /* only basic and NTLM/NTLMv2 authentication supported so far */
  if (p->auth_method == HTTP_AUTH_BASIC || p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2)
    {
      get_user_pass_http (p, true);
    }

#if !NTLM
  if (p->auth_method == HTTP_AUTH_NTLM || p->auth_method == HTTP_AUTH_NTLM2)
    msg (M_FATAL, "Sorry, this version of " PACKAGE_NAME " was built without NTLM Proxy support.");
#endif

  p->defined = true;
  return p;
}
示例#18
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_envprop(PRIM_PROTOTYPE)
{
	double fresult;

	CHECKOP(2);
	oper1 = POP();
	oper2 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper2))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper2->data.objref);
	{
		char tname[BUFFER_LEN];
		dbref what;
		PropPtr ptr;
		int len = oper1->data.string->length;

		strcpyn(tname, sizeof(tname), oper1->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		what = oper2->data.objref;
		ptr = envprop(&what, tname, 0);
		if (what != NOTHING) {
			if (!prop_read_perms(ProgUID, what, oper1->data.string->data, mlev))
				abort_interp("Permission denied.");
		}
		CLEAR(oper1);
		CLEAR(oper2);
		PushObject(what);

		if (!ptr) {
			result = 0;
			PushInt(result);
		} else {
#ifdef DISKBASE
			propfetch(what, ptr);
#endif
			switch (PropType(ptr)) {
			case PROP_STRTYP:
				PushString(PropDataStr(ptr));
				break;
			case PROP_INTTYP:
				result = PropDataVal(ptr);
				PushInt(result);
				break;
			case PROP_FLTTYP:
				fresult = PropDataFVal(ptr);
				PushFloat(fresult);
				break;
			case PROP_REFTYP:
				ref = PropDataRef(ptr);
				PushObject(ref);
				break;
			case PROP_LOKTYP:
				if (PropFlags(ptr) & PROP_ISUNLOADED) {
					PushLock(TRUE_BOOLEXP);
				} else {
					PushLock(PropDataLok(ptr));
				}
				break;
			default:
				result = 0;
				PushInt(result);
				break;
			}
		}
	}
}
示例#19
0
/*
 - slow - step through the string more deliberately
 == static const char *slow(struct match *m, const char *start, \
 ==	const char *stop, sopno startst, sopno stopst);
 */
static const char *		/* where it ended */
slow(	struct match *m,
	const char *start,
	const char *stop,
	sopno startst,
	sopno stopst)
{
	states st = m->st;
	states empty = m->empty;
	states tmp = m->tmp;
	const char *p = start;
	wint_t c;
	wint_t lastc;		/* previous c */
	wint_t flagch;
	int i;
	const char *matchp;	/* last p at which a match ended */
	size_t clen;

	AT("slow", start, stop, startst, stopst);
	CLEAR(st);
	SET1(st, startst);
	SP("sstart", st, *p);
	st = step(m->g, startst, stopst, st, NOTHING, st);
	matchp = NULL;
	if (start == m->beginp)
		c = OUT;
	else {
		/*
		 * XXX Wrong if the previous character was multi-byte.
		 * Newline never is (in encodings supported by FreeBSD),
		 * so this only breaks the ISWORD tests below.
		 */
		c = (uch)*(start - 1);
	}
	for (;;) {
		/* next character */
		lastc = c;
		if (p == m->endp) {
			c = OUT;
			clen = 0;
		} else
			clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);

		/* is there an EOL and/or BOL between lastc and c? */
		flagch = '\0';
		i = 0;
		if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
				(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
			flagch = BOL;
			i = m->g->nbol;
		}
		if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
				(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
			flagch = (flagch == BOL) ? BOLEOL : EOL;
			i += m->g->neol;
		}
		if (i != 0) {
			for (; i > 0; i--)
				st = step(m->g, startst, stopst, st, flagch, st);
			SP("sboleol", st, c);
		}

		/* how about a word boundary? */
		if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
					(c != OUT && ISWORD(c)) ) {
			flagch = BOW;
		}
		if ( (lastc != OUT && ISWORD(lastc)) &&
				(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
			flagch = EOW;
		}
		if (flagch == BOW || flagch == EOW) {
			st = step(m->g, startst, stopst, st, flagch, st);
			SP("sboweow", st, c);
		}

		/* are we done? */
		if (ISSET(st, stopst))
			matchp = p;
		if (EQ(st, empty) || p == stop || clen > stop - p)
			break;		/* NOTE BREAK OUT */

		/* no, we must deal with this character */
		ASSIGN(tmp, st);
		ASSIGN(st, empty);
		assert(c != OUT);
		st = step(m->g, startst, stopst, tmp, c, st);
		SP("saft", st, c);
		assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
		p += clen;
	}

	return(matchp);
}
示例#20
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_envpropstr(PRIM_PROTOTYPE)
{
	CHECKOP(2);
	oper1 = POP();
	oper2 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper2))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper2->data.objref);
	{
		char tname[BUFFER_LEN];
		dbref what;
		PropPtr ptr;
		const char *temp;
		int len = oper1->data.string->length;

		strcpyn(tname, sizeof(tname), oper1->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		what = oper2->data.objref;
		ptr = envprop(&what, tname, 0);
		if (!ptr) {
			temp = "";
		} else {
#ifdef DISKBASE
			propfetch(what, ptr);
#endif
			switch (PropType(ptr)) {
			case PROP_STRTYP:
				temp = PropDataStr(ptr);
				break;
				/*
				 *case PROP_INTTYP:
				 *    snprintf(buf, sizeof(buf), "%d", PropDataVal(ptr));
				 *    temp = buf;
				 *    break;
				 */
			case PROP_REFTYP:
				snprintf(buf, sizeof(buf), "#%d", PropDataRef(ptr));
				temp = buf;
				break;
			case PROP_LOKTYP:
				if (PropFlags(ptr) & PROP_ISUNLOADED) {
					temp = "*UNLOCKED*";
				} else {
					temp = unparse_boolexp(ProgUID, PropDataLok(ptr), 1);
				}
				break;
			default:
				temp = "";
				break;
			}
		}

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) ENVPROPSTR: o=%d so=%d n=\"%s\" s=\"%s\"",
				 program, pc->line, what, oper2->data.objref, tname, temp);
#endif

		if (what != NOTHING) {
			if (!prop_read_perms(ProgUID, what, oper1->data.string->data, mlev))
				abort_interp("Permission denied.");
			/* if (Typeof(what) != TYPE_PLAYER)
			 *     ts_lastuseobject(what); */
		}
		CLEAR(oper1);
		CLEAR(oper2);
		PushObject(what);
		PushString(temp);
	}
}
示例#21
0
void init_words (WavpackStream *wps)
{
    CLEAR (wps->w);

    word_set_bitrate (wps);
}
示例#22
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_setprop(PRIM_PROTOTYPE)
{
	CHECKOP(3);
	oper1 = POP();
	oper2 = POP();
	oper3 = POP();
	if ((oper1->type != PROG_STRING) &&
		(oper1->type != PROG_INTEGER) &&
		(oper1->type != PROG_LOCK) &&
		(oper1->type != PROG_OBJECT) &&
		(oper1->type != PROG_FLOAT)) abort_interp("Invalid argument type (3)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper2->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper3))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper3->data.objref);

	if ((mlev < 2) && (!permissions(ProgUID, oper3->data.objref)))
		abort_interp("Permission denied.");

	if (!prop_write_perms(ProgUID, oper3->data.objref, oper2->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		char *tmpe;
		char tname[BUFFER_LEN];
		PData propdat;
		int len = oper2->data.string->length;

		tmpe = oper2->data.string->data;
		while (*tmpe && *tmpe != '\r' && *tmpe != ':')
			tmpe++;
		if (*tmpe)
			abort_interp("Illegal propname");

		strcpyn(tname, sizeof(tname), oper2->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		switch (oper1->type) {
		case PROG_STRING:
			propdat.flags = PROP_STRTYP;
			propdat.data.str = oper1->data.string ? oper1->data.string->data : 0;
			break;
		case PROG_INTEGER:
			propdat.flags = PROP_INTTYP;
			propdat.data.val = oper1->data.number;
			break;
		case PROG_FLOAT:
			propdat.flags = PROP_FLTTYP;
			propdat.data.fval = oper1->data.fnumber;
			break;
		case PROG_OBJECT:
			propdat.flags = PROP_REFTYP;
			propdat.data.ref = oper1->data.objref;
			break;
		case PROG_LOCK:
			propdat.flags = PROP_LOKTYP;
			propdat.data.lok = copy_bool(oper1->data.lock);
			break;
		}
		set_property(oper3->data.objref, tname, &propdat);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) SETPROP: o=%d n=\"%s\"",
				 program, pc->line, oper3->data.objref, tname);
#endif

		ts_modifyobject(oper3->data.objref);
	}
	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
}
示例#23
0
TVerdict CCompactAndRecoverStep::doTestStepPostambleL()
	{
	CLEAR( iContactOpenOperation );	
	return CPerformanceFunctionalityBase::doTestStepPostambleL();
	}
示例#24
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_addprop(PRIM_PROTOTYPE)
{
	CHECKOP(4);
	oper1 = POP();
	oper2 = POP();
	oper3 = POP();
	oper4 = POP();
	if (oper1->type != PROG_INTEGER)
		abort_interp("Non-integer argument (4)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (3)");
	if (oper3->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper3->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper4))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper4->data.objref);

	if ((mlev < 2) && (!permissions(ProgUID, oper4->data.objref)))
		abort_interp("Permission denied.");

	if (!prop_write_perms(ProgUID, oper4->data.objref, oper3->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		const char *temp;
		char *tmpe;
		char tname[BUFFER_LEN];
		int len = oper3->data.string->length;

		temp = (oper2->data.string ? oper2->data.string->data : 0);
		tmpe = oper3->data.string->data;
		while (*tmpe && *tmpe != '\r')
			tmpe++;
		if (*tmpe)
			abort_interp("CRs not allowed in propname");

		strcpyn(tname, sizeof(tname), oper3->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		/* if ((temp) || (oper1->data.number)) */
		{
			add_property(oper4->data.objref, tname, temp, oper1->data.number);

#ifdef LOG_PROPS
			log2file("props.log", "#%d (%d) ADDPROP: o=%d n=\"%s\" s=\"%s\" v=%d",
					 program, pc->line, oper4->data.objref, tname, temp, oper1->data.number);
#endif

			ts_modifyobject(oper4->data.objref);
		}
	}
	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
	CLEAR(oper4);
}
示例#25
0
static bool
recv_line (socket_descriptor_t sd,
	   char *buf,
	   int len,
	   const int timeout_sec,
	   const bool verbose,
	   struct buffer *lookahead,
	   volatile int *signal_received)
{
  struct buffer la;
  int lastc = 0;

  CLEAR (la);
  if (lookahead)
    la = *lookahead;

  while (true)
    {
      int status;
      ssize_t size;
      fd_set reads;
      struct timeval tv;
      uint8_t c;

      if (buf_defined (&la))
	{
	  ASSERT (buf_init (&la, 0));
	}

      FD_ZERO (&reads);
      FD_SET (sd, &reads);
      tv.tv_sec = timeout_sec;
      tv.tv_usec = 0;

      status = select (sd + 1, &reads, NULL, NULL, &tv);

      get_signal (signal_received);
      if (*signal_received)
	goto error;

      /* timeout? */
      if (status == 0)
	{
	  if (verbose)
	    msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read timeout expired");
	  goto error;
	}

      /* error */
      if (status < 0)
	{
	  if (verbose)
	    msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read failed on select()");
	  goto error;
	}

      /* read single char */
      size = recv (sd, &c, 1, MSG_NOSIGNAL);

      /* error? */
      if (size != 1)
	{
	  if (verbose)
	    msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read failed on recv()");
	  goto error;
	}

#if 0
      if (isprint(c))
	msg (M_INFO, "PROXY: read '%c' (%d)", c, (int)c);
      else
	msg (M_INFO, "PROXY: read (%d)", (int)c);
#endif

      /* store char in buffer */
      if (len > 1)
	{
	  *buf++ = c;
	  --len;
	}

      /* also store char in lookahead buffer */
      if (buf_defined (&la))
	{
	  buf_write_u8 (&la, c);
	  if (!isprint(c) && !isspace(c)) /* not ascii? */
	    {
	      if (verbose)
		msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: Non-ASCII character (%d) read on recv()", (int)c);
	      *lookahead = la;
	      return false;
	    }
	}

      /* end of line? */
      if (lastc == '\r' && c == '\n')
	break;

      lastc = c;
    }

  /* append trailing null */
  if (len > 0)
    *buf++ = '\0';

  return true;

 error:
  return false;
}
示例#26
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_parseprop(PRIM_PROTOTYPE)
{
	const char *temp;
	char *ptr;
	struct inst *oper1 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper2 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper3 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper4 = NULL; /* prevents re-entrancy issues! */

	char buf[BUFFER_LEN];
	char type[BUFFER_LEN];

	CHECKOP(4);
	oper4 = POP();				/* int */
	oper2 = POP();				/* arg str */
	oper1 = POP();				/* propname str */
	oper3 = POP();				/* object dbref */
	if (mlev < 3)
		abort_interp("Mucker level 3 or greater required.");
	if (oper3->type != PROG_OBJECT)
		abort_interp("Non-object argument. (1)");
	if (!valid_object(oper3))
		abort_interp("Invalid object. (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("String expected. (3)");
	if (oper1->type != PROG_STRING)
		abort_interp("String expected. (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (oper4->type != PROG_INTEGER)
		abort_interp("Integer expected. (4)");
	if (oper4->data.number < 0 || oper4->data.number > 1)
		abort_interp("Integer of 0 or 1 expected. (4)");
	CHECKREMOTE(oper3->data.objref);
	{
		int len = oper1->data.string->length;

		if (!prop_read_perms(ProgUID, oper3->data.objref, oper1->data.string->data, mlev))
			abort_interp("Permission denied.");

		if (mlev < 3 && !permissions(player, oper3->data.objref) &&
			prop_write_perms(ProgUID, oper3->data.objref, oper1->data.string->data, mlev))
			abort_interp("Permission denied.");

		strcpyn(type, sizeof(type), oper1->data.string->data);
		while (len-- > 0 && type[len] == PROPDIR_DELIMITER) {
			type[len] = '\0';
		}

		temp = get_property_class(oper3->data.objref, type);
#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) GETPROPSTR: o=%d n=\"%s\" s=\"%s\"",
				 program, pc->line, oper3->data.objref, type, temp);
#endif

	}
	ptr = (oper2->data.string) ? oper2->data.string->data : "";
	if (temp) {
		result = 0;
		if (oper4->data.number)
			result |= MPI_ISPRIVATE;
		if (Prop_Blessed(oper3->data.objref, type))
			result |= MPI_ISBLESSED;
		ptr = do_parse_mesg(fr->descr, player, oper3->data.objref, temp, ptr, buf, sizeof(buf), result);
		CLEAR(oper1);
		CLEAR(oper2);
		CLEAR(oper3);
		CLEAR(oper4);
		PushString(ptr);
	} else {
		CLEAR(oper1);
		CLEAR(oper2);
		CLEAR(oper3);
		CLEAR(oper4);
		PushNullStr;
	}
}
示例#27
0
static int
plugin_call_item (const struct plugin *p,
		  void *per_client_context,
		  const int type,
		  const struct argv *av,
		  struct openvpn_plugin_string_list **retlist,
		  const char **envp
#ifdef ENABLE_SSL
		  , int certdepth,
		  openvpn_x509_cert_t *current_cert
#endif
		 )
{
  int status = OPENVPN_PLUGIN_FUNC_SUCCESS;

  /* clear return list */
  if (retlist)
    *retlist = NULL;

  if (p->plugin_handle && (p->plugin_type_mask & OPENVPN_PLUGIN_MASK (type)))
    {
      struct gc_arena gc = gc_new ();
      struct argv a = argv_insert_head (av, p->so_pathname);

      dmsg (D_PLUGIN_DEBUG, "PLUGIN_CALL: PRE type=%s", plugin_type_name (type));
      plugin_show_args_env (D_PLUGIN_DEBUG, (const char **)a.argv, envp);

      /*
       * Call the plugin work function
       */
      if (p->func3) {
        struct openvpn_plugin_args_func_in args = { type,
                                                    (const char ** const) a.argv,
                                                    (const char ** const) envp,
                                                    p->plugin_handle,
                                                    per_client_context,
#ifdef ENABLE_SSL
						    (current_cert ? certdepth : -1),
						    current_cert
#else
						    -1,
						    NULL
#endif
	  };

        struct openvpn_plugin_args_func_return retargs;

        CLEAR(retargs);
        retargs.return_list = retlist;
        status = (*p->func3)(OPENVPN_PLUGINv3_STRUCTVER, &args, &retargs);
      } else if (p->func2)
	status = (*p->func2)(p->plugin_handle, type, (const char **)a.argv, envp, per_client_context, retlist);
      else if (p->func1)
	status = (*p->func1)(p->plugin_handle, type, (const char **)a.argv, envp);
      else
	ASSERT (0);

      msg (D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=%d",
	   p->so_pathname,
	   plugin_type_name (type),
	   status);

      if (status == OPENVPN_PLUGIN_FUNC_ERROR)
	msg (M_WARN, "PLUGIN_CALL: plugin function %s failed with status %d: %s",
	     plugin_type_name (type),
	     status,
	     p->so_pathname);

      argv_reset (&a);
      gc_free (&gc);
    }
  return status;
}
示例#28
0
文件: p_props.c 项目: hyena/fuzzball
void
prim_array_filter_prop(PRIM_PROTOTYPE)
{
	char pattern[BUFFER_LEN];
	char tname[BUFFER_LEN];
	struct inst *in;
	struct inst temp1;
	stk_array *arr;
	stk_array *nu;
	char* prop;
	int len;

	CHECKOP(3);
	oper3 = POP();				/* str     pattern */
	oper2 = POP();				/* str     propname */
	oper1 = POP();				/* refarr  Array */
	if (oper1->type != PROG_ARRAY)
		abort_interp("Argument not an array. (1)");
	if (!array_is_homogenous(oper1->data.array, PROG_OBJECT))
		abort_interp("Argument not an array of dbrefs. (1)");
	if (oper2->type != PROG_STRING || !oper2->data.string)
		abort_interp("Argument not a non-null string. (2)");
	if (oper3->type != PROG_STRING)
		abort_interp("Argument not a string pattern. (3)");

	len = oper2->data.string ? oper2->data.string->length : 0;
	strcpyn(tname, sizeof(tname), DoNullInd(oper2->data.string));
	while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
		tname[len] = '\0';
	}

	nu = new_array_packed(0);
	arr = oper1->data.array;
	prop = tname;
	strcpyn(pattern, sizeof(pattern), DoNullInd(oper3->data.string));
	if (array_first(arr, &temp1)) {
		do {
			in = array_getitem(arr, &temp1);
			if (valid_object(in)) {
				ref = in->data.objref;
				CHECKREMOTE(ref);
				if (prop_read_perms(ProgUID, ref, prop, mlev)) {
					PropPtr pptr = get_property(ref, prop);

					if (pptr)
					{
						switch(PropType(pptr))
						{
							case PROP_STRTYP:
								strncpy(buf, PropDataStr(pptr), BUFFER_LEN);
							break;

							case PROP_LOKTYP:
								if (PropFlags(pptr) & PROP_ISUNLOADED) {
									strncpy(buf, "*UNLOCKED*", BUFFER_LEN);
								} else {
									strncpy(buf, unparse_boolexp(ProgUID, PropDataLok(pptr), 0), BUFFER_LEN);
								}
							break;

							case PROP_REFTYP:
								snprintf(buf, BUFFER_LEN, "#%i", PropDataRef(pptr));
							break;

							case PROP_INTTYP:
								snprintf(buf, BUFFER_LEN, "%i", PropDataVal(pptr));
							break;

							case PROP_FLTTYP:
								snprintf(buf, BUFFER_LEN, "%g", PropDataFVal(pptr));
							break;

							default:
								strncpy(buf, "", BUFFER_LEN);
							break;
						}
					}
					else
						strncpy(buf, "", BUFFER_LEN);

					if (equalstr(pattern, buf)) {
						array_appenditem(&nu, in);
					}
				}
			}
		} while (array_next(arr, &temp1));
	}

	CLEAR(oper3);
	CLEAR(oper2);
	CLEAR(oper1);

	PushArrayRaw(nu);
}
示例#29
0
// Server Operation - captureImage_server
//# Start captureImage_operation Marker
bool image_sensor::captureImage_operation(agse_package::captureImage::Request  &req,
  agse_package::captureImage::Response &res)
{
#ifdef USE_ROSMOD
  comp_queue.ROSMOD_LOGGER->log("DEBUG", "Entering image_sensor::captureImage_operation");
#endif
  // Business Logic for captureImage_server_operation
    if (!paused)
    {
      // Business Logic for captureImage_server Server providing captureImage Service
      fd_set                          fds;
      struct timeval                  tv;
      enum v4l2_buf_type              type;
      int                             r;

      for (int i = 0; i < n_buffers; ++i) {
	CLEAR(buf);
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;
	buf.index = i;
	xioctl(videoFD, VIDIOC_QBUF, &buf);
      }
      type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

      xioctl(videoFD, VIDIOC_STREAMON, &type);
      do {
	FD_ZERO(&fds);
	FD_SET(videoFD, &fds);

	/* Timeout. */
	tv.tv_sec = 2;
	tv.tv_usec = 0;

	r = select(videoFD + 1, &fds, NULL, NULL, &tv);
      } while ((r == -1 && (errno = EINTR)));
      if (r == -1) {
	perror("select");
	return false;
      }

      CLEAR(buf);
      buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
      buf.memory = V4L2_MEMORY_MMAP;
      xioctl(videoFD, VIDIOC_DQBUF, &buf);

      //fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);

      type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
      xioctl(videoFD, VIDIOC_STREAMOFF, &type);

      res.imgVector.reserve(buf.bytesused);
      std::copy(&((unsigned char *)buffers[buf.index].start)[0],
		&((unsigned char *)buffers[buf.index].start)[0] + buf.bytesused,
		back_inserter(res.imgVector));
      res.width = width;
      res.height = height;
		
      return true;
    }
  return false;
#ifdef USE_ROSMOD
  comp_queue.ROSMOD_LOGGER->log("DEBUG", "Exiting image_sensor::captureImage_operation");
#endif
  return true;
}
示例#30
0
文件: win32.c 项目: angelol/iOpenVPN
void
net_event_win32_init (struct net_event_win32 *ne)
{
  CLEAR (*ne);
  ne->sd = SOCKET_UNDEFINED;
}