Пример #1
0
/* can't really use xsubpp here... */
extern
XS(blizkost_callable_trampoline)
{
#ifdef dVAR
    dVAR;
#endif
    dXSARGS;
    PMC *callable;
    blizkost_nexus *nexus;
    int i;
    PMC *args, *posret, *namret;

    blizkost_get_bound_pmc(my_perl, &nexus, (SV *)cv, &callable);

    if (nexus->dying)
        exit_fatal(1, "Attempted reentry of Parrot code during global destruction");

    PERL_UNUSED_VAR(ax);
    SP -= items;
    PUTBACK;

    args = Parrot_pmc_new_init_int(nexus->parrot_interp, enum_class_ResizablePMCArray, items);
    for (i = 0; i < items; i++) {
        SV *svarg = ST(i);
        PMC *pmcarg = blizkost_wrap_sv(nexus, svarg);
        VTABLE_set_pmc_keyed_int(nexus->parrot_interp, args, i, pmcarg);
    }

    Parrot_pcc_invoke_sub_from_c_args(nexus->parrot_interp, callable,
            "Pf->PsPsn", args, &posret, &namret);

    blizkost_slurpy_to_stack(nexus, posret, namret);

    SPAGAIN;
}
Пример #2
0
int open_clientsock(char * address, int port)
{
  struct sockaddr_in servadr;
  int client_handle;
 
  /* Create a new socket */
  if ((client_handle = socket (AF_INET, SOCK_STREAM, 0)) == -1)
    exit_fatal ("Error opening socket Abort !");
  
/* Now set the server address struct and connect client socket to the port*/
  initaddr (&servadr,address,port);

  if (connect(client_handle,(struct sockaddr *) &servadr,
       sizeof (struct sockaddr)) == -1)
	  exit_fatal ("connect failed Abort !");
  return client_handle;
}
Пример #3
0
void *_mem_calloc (size_t nmemb, size_t size, int line, const char* fname) {
  void *p;

  if (!nmemb || !size)
    return NULL;

  if (((size_t) - 1) / nmemb <= size) {
    exit_fatal ("mem_calloc", _("Integer overflow -- can't allocate memory!"),
                line, fname, 1);
    return (NULL);
  }

  if (!(p = calloc (nmemb, size))) {
    exit_fatal ("mem_calloc", _("Out of memory!"), line, fname, 1);
    return (NULL);
  }
  return p;
}
Пример #4
0
void *_mem_malloc (size_t siz, int line, const char* fname) {
  void *p;

  if (siz == 0)
    return 0;
  if ((p = (void *) malloc (siz)) == 0) {       /* __MEM_CHECKED__ */
    exit_fatal ("mem_malloc", _("Out of memory!"), line, fname, 1);
    return (NULL);
  }
  return (p);
}
Пример #5
0
static int
SetVideoPict (struct vdIn *vd)
{
  if (ioctl (vd->fd, VIDIOCSPICT, &vd->videopict) < 0)
    exit_fatal ("Couldnt set videopict params with VIDIOCSPICT");

  printf ("VIDIOCSPICT brightnes=%d hue=%d color=%d contrast=%d whiteness=%d"
	  "depth=%d palette=%d\n", vd->videopict.brightness,
	  vd->videopict.hue, vd->videopict.colour, vd->videopict.contrast,
	  vd->videopict.whiteness, vd->videopict.depth,
	  vd->videopict.palette);

  return 0;
}
Пример #6
0
int
open_sock (int port)
{

  struct sockaddr_in servadr;
  int server_handle;
  int O_on = 1;
/* Create a new socket */
  if ((server_handle = socket (AF_INET, SOCK_STREAM, 0)) == -1)
    exit_fatal ("Error opening socket Abort !");
  if (setsockopt (server_handle, SOL_SOCKET, SO_REUSEADDR, &O_on, sizeof (int)) == -1)
    exit_fatal ("Setting reused address fail Abort !");
/* Now set the server address struct and bind socket to the port*/
  initaddr (&servadr,NULL, port);
  if (bind 
      (server_handle, (struct sockaddr *) &servadr,
       sizeof (struct sockaddr)) == -1)
    exit_fatal ("error bind socket");
/* Listen on the socket */
  if (listen (server_handle, MAXCONNECT) == -1)
    exit_fatal ("Damned errors when listen Abort !");
  return server_handle;
}
Пример #7
0
static void
initaddr (struct sockaddr_in *servadrr,char *address,int port)
{  
	//printf("Init addr %s:%d\n",address,port );
int adrsize = 0;
	if(address){
		adrsize = strlen(address);
		if(adrsize < 7 || adrsize > 15)
			exit_fatal("setting wrong address Abort !!");
		servadrr->sin_addr.s_addr = inet_addr(address);
	} else {
		servadrr->sin_addr.s_addr = INADDR_ANY;
	}
		
	servadrr->sin_family = PF_INET;
  	servadrr->sin_port = htons (port);
   	memset (&(servadrr->sin_zero), '\0', 8);
	
}
Пример #8
0
void
Parrot_setenv(PARROT_INTERP, STRING *str_name, STRING *str_value)
{
    char * const name  = Parrot_str_to_cstring(interp, str_name);
    char * const value = Parrot_str_to_cstring(interp, str_value);
    assert(name  != NULL);
    assert(value != NULL);

    {
        const int name_len  = strlen(name);
        const int value_len = strlen(value);

        {
            char * const envstring = (char * const)mem_internal_allocate(
                                         name_len     /* name  */
                                         + 1          /* '='   */
                                         + value_len  /* value */
                                         + 1);        /* string terminator */

            /* Save a bit of time, by using the fact we already have the
            lengths, avoiding strcat */
            strcpy(envstring, name);
            strcpy(envstring + name_len, "=");
            strcpy(envstring + name_len + 1, value);

            Parrot_str_free_cstring(name);
            Parrot_str_free_cstring(value);

            if (_putenv(envstring) == 0) {
                /* success */
                mem_sys_free(envstring);
            }
            else {
                mem_sys_free(envstring);
                exit_fatal(1, "Unable to set environment variable %s=%s",
                           name, value);
            }
        }
    }
}
Пример #9
0
void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
  void *r;
  void **p = (void **) ptr;

  if (siz == 0) {
    if (*p) {
      free (*p);                /* __MEM_CHECKED__ */
      *p = NULL;
    }
    return;
  }

  if (*p)
    r = (void *) realloc (*p, siz);     /* __MEM_CHECKED__ */
  else {
    /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x  --- __MEM_CHECKED__ */
    r = (void *) malloc (siz);  /* __MEM_CHECKED__ */
  }

  if (!r)
    exit_fatal ("mem_realloc", _("Out of memory!"), line, fname, 1);

  *p = r;
}
Пример #10
0
static int
init_v4l (struct vdIn *vd)
{
  int f;
  int erreur = 0;
  int err;
  if ((vd->fd = open (vd->videodevice, O_RDWR)) == -1)
    exit_fatal ("ERROR opening V4L interface");

  if (ioctl (vd->fd, VIDIOCGCAP, &(vd->videocap)) == -1)
    exit_fatal ("Couldn't get videodevice capability");

  printf ("Camera found: %s \n", vd->videocap.name);
  snprintf (vd->cameraname, 32, "%s", vd->videocap.name);

  erreur = GetVideoPict (vd);
   if (ioctl (vd->fd, VIDIOCGCHAN, &vd->videochan) == -1)
    {
      printf ("Hmm did not support Video_channel\n");
      vd->cameratype = UNOW;
    }
  else
    {
    if (vd->videochan.name){
      printf ("Bridge found: %s \n", vd->videochan.name);
      snprintf (vd->bridge, 9, "%s", vd->videochan.name);
      vd->cameratype = GetStreamId (vd->videochan.name);
      spcaPrintParam (vd->fd,&vd->videoparam);
      }
      else
      {
       printf ("Bridge not found not a spca5xx Webcam Probing the hardware !!\n");
      vd->cameratype = UNOW;
      }
    }
   printf ("StreamId: %d  Camera\n", vd->cameratype);
/* probe all available palette and size */
   if (probePalette(vd ) < 0) {
	  exit_fatal ("could't probe video palette Abort !");
	  }
   if (probeSize(vd ) < 0) {
	  exit_fatal ("could't probe video size Abort !");
	  }

/* now check if the needed setting match the available
	if not find a new set and populate the change */
	 err = check_palettesize(vd);
	 printf (" Format asked %d check %d\n",vd->formatIn, err);	
  vd->videopict.palette = vd->formatIn;
  vd->videopict.depth = GetDepth (vd->formatIn);
  vd->bppIn = GetDepth (vd->formatIn);
  
   vd->framesizeIn = (vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3;
   
  erreur = SetVideoPict (vd);
  erreur = GetVideoPict (vd);
  if (vd->formatIn != vd->videopict.palette ||
      vd->bppIn != vd->videopict.depth)
    exit_fatal ("could't set video palette Abort !");
  if (erreur < 0)
    exit_fatal ("could't set video palette Abort !");

  if (vd->grabMethod)
    {
      printf (" grabbing method default MMAP asked \n");
      // MMAP VIDEO acquisition
      memset (&(vd->videombuf), 0, sizeof (vd->videombuf));
      if (ioctl (vd->fd, VIDIOCGMBUF, &(vd->videombuf)) < 0)
	{
	  perror (" init VIDIOCGMBUF FAILED\n");
	}
      printf ("VIDIOCGMBUF size %d  frames %d  offets[0]=%d offsets[1]=%d\n",
	      vd->videombuf.size, vd->videombuf.frames,
	      vd->videombuf.offsets[0], vd->videombuf.offsets[1]);
      vd->pFramebuffer =
	(unsigned char *) mmap (0, vd->videombuf.size, PROT_READ | PROT_WRITE,
				MAP_SHARED, vd->fd, 0);
      vd->mmapsize = vd->videombuf.size;
      vd->vmmap.height = vd->hdrheight;
      vd->vmmap.width = vd->hdrwidth;
      vd->vmmap.format = vd->formatIn;
      for (f = 0; f < vd->videombuf.frames; f++)
	{
	  vd->vmmap.frame = f;
	  if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap)))
	    {
	      perror ("cmcapture");
	    }
	}
      vd->vmmap.frame = 0;
    }
  else
    {
      /* read method */
      /* allocate the read buffer */
      vd->pFramebuffer =
	(unsigned char *) realloc (vd->pFramebuffer, (size_t) vd->framesizeIn);
      printf (" grabbing method READ asked \n");
      if (ioctl (vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0)
	perror ("VIDIOCGWIN failed \n");
      vd->videowin.height = vd->hdrheight;
      vd->videowin.width = vd->hdrwidth;
      if (ioctl (vd->fd, VIDIOCSWIN, &(vd->videowin)) < 0)
	perror ("VIDIOCSWIN failed \n");
      printf ("VIDIOCSWIN height %d  width %d \n",
	      vd->videowin.height, vd->videowin.width);
    }
  vd->frame_cour = 0;
  return erreur;
}
Пример #11
0
int main(int argc, char **argv) {
    int conf_err = 0;
    int option;
    int dflag = 0;
    conf_ruleset_s rset;

    // Set the default logger to syslog
    log_syslog(&logger);

    // Initialize the config and its rulesets
    conf_init(&conf);
    conf_rset_init(&rset);

    // Set the real path
    conf_set_realpath(&conf, argv[0]);

    conf_rset_add(&rset, conf_rule_create("root = %s", &conf.document_root));
    conf_rset_add(&rset, conf_rule_create("handler = %s", &conf.method));
    conf_rset_add(&rset, conf_rule_create("port = %hu", &conf.port));
    conf_rset_add(&rset, conf_rule_create("backlog = %d", &conf.backlog));
    conf_rset_add(&rset, conf_rule_create("mime = %s", &conf.mime));
    conf_rset_add(&rset, conf_rule_create("logfile = %s", &conf.logfile));

    if (conf_read(conf.real_path, ".lab3-config", rset) == -1)
        exit_fatal("The configuration file could not be read");

    while((option = getopt(argc, argv, "hp:dl:s:")) != -1) {
        switch(option) {
            case 'p': conf_set_port(&conf, optarg); break;
            case 'd': dflag = 1; break;
            case 'l':
                conf_set_logfile(&conf, optarg);

                if (strncmp(optarg, "stdout", 6) == 0)
                    log_stdout(&logger);
                else
                    log_file(&logger);
                break;
            case 's': conf_set_method(&conf, optarg); break;
            case 'h': default: usage(argv[0]); exit(EXIT_SUCCESS);
        }
    }

    // Register signal handler for SIGINT
    signal(SIGINT, sigint_handler);

    if ((conf_err = conf_validate(conf)) < 0)
        conf_print_err(conf_err);

    // Daemonize the process if the dflag is set
    if (dflag) {
        log_syslog(&logger);
        daemonize();
    } else {
        jail_proc(dflag);
    }

    server_create();

    return 0;
}