示例#1
0
  void setStringMapAttribute_(const nstr& key, const nvar& value){
    nvec values;

    if(value.isString()){
      values.push_back(value); 
    }
    else{
      if(!value.hasVector()){
        error_(key, value);
      }

      for(size_t i = 0; i < value.size(); ++i){
        if(!value[i].isString()){
          error_(key, value);
        }

        values.push_back(value[i]);
      }
    }

    nvar& r = attrs_(key);
    for(const nstr& k : values){
      r(k) = true;
    }
  }
示例#2
0
void init(){
	int i;
	for(i=0;i<CLI_FD;i++){
		if ((g_sfd[i] = socket (AF_INET, SOCK_STREAM, 0)) < 0){
			error ("Socket error");
		}

		bzero ((char *) &g_addr[i], sizeof(g_addr[i]));
		g_addr[i].sin_family = AF_INET;
		g_addr[i].sin_addr.s_addr = htonl(INADDR_ANY);
		g_addr[i].sin_port = htons(PORTS[i]);
		if (bind (g_sfd[i],(struct sockaddr *)&g_addr[i], sizeof(g_addr[i])) < 0)
			error_("Bind Error at ",i);

		printf("Client Ports have been initialized\n");
	}

	for(i=0;i<2;i++){
		if((service_sfd[i] = socket(AF_INET,SOCK_STREAM,0)) < 0){
			error("Socket error at service");
		}

		bzero((char *) &service[i], sizeof(service[i]));
		service[i].sin_family = AF_INET;
		service[i].sin_addr.s_addr = htonl(INADDR_ANY);
		service[i].sin_port = htons(SERV_PORTS[i]);

		if(bind(service_sfd[i], (struct sockaddr *) &service[i], sizeof(service[i])) < 0){
			error_("Bind Error at Service",i);
		}

		printf("Service ports have been initialized\n");
	}
}
示例#3
0
  bool controller::JacobianProduct(std::string type, Eigen::VectorXd& update)
  {
    Eigen::MatrixXd jacobian;
    Eigen::VectorXd ke = Eigen::VectorXd::Zero(6), dqbis;

    kine_model_->getJacobian(joints_[0], joints_names_, jacobian);
    if(type == "force")
      {
        for(unsigned int i=0; i<3; i++)
          ke(i) = gF_(i)*error_(i);
      }
    else if(type == "moment")
      {
        for(unsigned int i=0; i<3; i++)
          ke(i+3) = gM_(i)*error_(i+3);
      }
    else
      {
        ROS_ERROR("Could not recognize type of controller");
        return false;
      }

    dqbis = jacobian.transpose() * ke;
    update = dqbis;
    ROS_INFO_STREAM("update qs: " << update);
    return true;
  }
示例#4
0
void copyseq (float a[], float t[], int i, int j, int k) {
  if (i>j) { return; }
  else {
    if (k<0 || k>=dim) { error_(); };
    if (i<0 || i>=dim) { error_(); };
    t[k] = a[i];
    copyseq (a, t, i+1,j, k+1);
  }
}
示例#5
0
int eSocket::connectToHost(eString hostname, int port)
{
	sockaddr_in  serv_addr;
	struct hostent *server;
	int res;

	if (mystate == Invalid)
	{
		/* the socket has been closed, create a new socket descriptor */
		int s=socket(AF_INET, SOCK_STREAM, 0);
		mystate=Idle;
		setSocket(s, 1, mainloop);
	}
	
	if(socketdesc < 0){
		error_(errno);
		return(-1);
	}
	server=gethostbyname(hostname.c_str());
	if(server==NULL)
	{
		eDebug("can't resolve %s", hostname.c_str());
		error_(errno);
		return(-2);
	}
	memset(&serv_addr, 0, sizeof(serv_addr));
	serv_addr.sin_family=AF_INET;
	memmove(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
	serv_addr.sin_port=htons(port);
	res=::connect(socketdesc, (const sockaddr*)&serv_addr, sizeof(serv_addr));
	if ((res < 0) && (errno != EINPROGRESS) && (errno != EINTR))
	{
		eDebug("can't connect to host: %s", hostname.c_str());
		close();
		error_(errno);
		return(-3);
	}
	if (res < 0)	// EINPROGRESS or EINTR
	{
		rsn->setRequested(rsn->getRequested()|eSocketNotifier::Write);
		mystate=Connecting;
	} else
	{
		mystate=Connection;
		connected_();
	}
	return(0);
}
示例#6
0
void ParDiSO::solve(CSRcomplex& Z, complex<double>* x, complex<double>* rhs)
{
  // --------------------------------------------------------------------
  // ..  Back substitution and iterative refinement.                     
  // --------------------------------------------------------------------
  phase = 33;

  shiftIndices_(Z, 1);


  PARDISOCALL_Z(pt,
                &maxfct,
                &mnum,
                &mtype,
                &phase,
                &Z.nrows,
                Z.pData,
                Z.pRows,
                Z.pCols,
                perm,
                &nrhs,
                &iparm[1],
                &msglvl,
                rhs,
                x,
                &error,
                &dparm[1]);


  shiftIndices_(Z, -1);


  error_();
}
示例#7
0
void ParDiSO::factorize(CSRcomplex& Z)
{
  complex<double> zdum;

  // for factorization phase should be equal to 12
  phase = 22;

  shiftIndices_(Z, 1);

  PARDISOCALL_Z(pt,
                &maxfct,
                &mnum,
                &mtype,
                &phase,
                &Z.nrows,
                Z.pData,
                Z.pRows,
                Z.pCols,
                perm,
                &nrhs,
                &iparm[1],
                &msglvl,
                &zdum,
                &zdum,
                &error,
                &dparm[1]);

  shiftIndices_(Z, -1);

  error_();
}
void OnkyoRemoteItem::connect_(bool conn)
{
    bool linked_ = getConnected();
    if( linked_ != conn ){

        if(conn){
            onkyo_.reset( new OnkyoClient() );
            connect(onkyo_.data(), SIGNAL( newStatus(QString) ), this, SLOT(status_(QString)) );
            connect(onkyo_.data(), SIGNAL( error(QString)), this, SLOT(error_(QString)) );
            if(addr_.isEmpty())
                onkyo_->init();
            else {
                DeviceInfo d;
                d.addr = QHostAddress(addr_);
                d.port = port_;
                onkyo_->init(d);
            }
            onkyo_->setConnected(true);
        }
        else {//make diskonnect
            if(! onkyo_.isNull() ){
                this->disconnect(onkyo_.data());
                onkyo_.reset();
            }
        }
        emit connectChanged();
    }

}
void *space_runner(void  *arg){
  Runner_Arg *rarg  = (Runner_Arg *) arg;
  int read;
  int fd_is_close; 
  while(1){
    // lock ; read file;
    int locked = pthread_mutex_lock(rarg->read_fd_lock);
      if (locked!=0) return error_lock("Could not lock on file : ", rarg->read_fd_lock);
      char *line = read_line_from_input(rarg->fd, &fd_is_close);
      if (!line){
	if (fd_is_close){
	  pthread_mutex_unlock(rarg->read_fd_lock); 
	  //TODO - next step. 
	  return NULL; 
	}
	return error_lock("Strange... could not allocate memory? : " , rarg->read_fd_lock);
      }
      if (pthread_mutex_unlock(rarg->read_fd_lock) != 0){
	perror("Unlock :");
      }

     char **arguments = split(line, &read);
    // Check arguments is clean:
    if (arguments == NULL )  return error_("Could not allocate in split of input line: ");
    
    if (read != 7 ){
      fprintf(stderr, "Ignoring input line (!= %d): %s - ",  read, line);
      freeArray(arguments);
      continue;
    }

    //    return "add Education course C2 MI";
    if (strcasecmp(arguments[2], "room")== 0){
      if (read_room(rarg, arguments, read) != 0){
	return error_(""); 
      }
      else{
	freeArray(arguments); 
	continue; 
      }
    }
    freeArray(arguments); 
    //We got here. So we do not recognize this shit
    fprintf(stderr, "EntityType  %s is not valid\n", arguments[2]);
  }

}
示例#10
0
void Serial::handleError(QSerialPort::SerialPortError error)
{
    if ( (SerialPort->isOpen()) && (error == QSerialPort::ResourceError))
    {
        error_(SerialPort->errorString().toLocal8Bit());
        disconnectSerial();
    }
}
示例#11
0
void merge (float a[], int i, int iu, int ju) {
  int j = iu+1;
  int m = ju-i+1;
  if (m<=0) { error_(); };
  float t[m];
  mergeF2 (a,t,i,iu,j,ju,0);
  copyseq (t,a,0,m-1,i);
}
示例#12
0
void EventBase::ErrSocket(int aSockid) {
    eventLoop_->DeleteFileEvent(aSockid,
        AE_WRITABLE | AE_READABLE | AE_RWERROR);
    close(aSockid);
    if (error_) {
        error_(aSockid);
    }
}
示例#13
0
void ParDiSO::init(CSRcomplex& Z, int number_of_rhs)
{
  // --------------------------------------------------------------------
  // ..  Convert matrix from 0-based C-notation to Fortran 1-based       
  //     notation.                                                       
  // --------------------------------------------------------------------
  shiftIndices_(Z, 1);


  // --------------------------------------------------------------------
  //  .. pardiso_chk_matrix(...)                                         
  //     Checks the consistency of the given matrix.                     
  //     Use this functionality only for debugging purposes              
  // --------------------------------------------------------------------
    
  PARDISOCHECK_Z(&mtype, &Z.nrows, Z.pData, Z.pRows, Z.pCols, &error);

  if (error != 0) 
  {
    printf("\nERROR in consistency of matrix: %d", error);
    exit(1);
  }

  // --------------------------------------------------------------------
  // ..  Reordering and Symbolic Factorization.  This step also allocates
  //     all memory that is necessary for the factorization.             
  // --------------------------------------------------------------------

  complex<double> zdum;
  nrhs = number_of_rhs;
  
  phase = 11;
 
  PARDISOCALL_Z(pt,
                &maxfct,
                &mnum,
                &mtype,
                &phase,
                &Z.nrows,
                Z.pData,
                Z.pRows,
                Z.pCols,
                perm,
                &nrhs,
                &iparm[1],
                &msglvl,
                &zdum,
                &zdum,
                &error,
                &dparm[1]);

  // --------------------------------------------------------------------
  // ..  Convert matrix from 1-based Fortran-notation to C 0-based       
  //     notation.                                                       
  // --------------------------------------------------------------------
  shiftIndices_(Z, -1);
  error_();
}
示例#14
0
/*---------------------------------------------------------------------------*                                            
 * NAME: fetch_instruction
 * DESC: fetch each instructions and fill block and fuzz structures
 *---------------------------------------------------------------------------*/
unsigned int fetch_instruction(config *conf) {

  unsigned char opcode;

  /* debug */
  debug(1, "<-----------------------[enter]\n");

  /* read the byte pointed by the offset in adc->buffer */
  opcode = read_buffer_char(conf);

  debug(3, "INSTRUCTION: %d\n", opcode);


  /* big switch for each instructions */
  switch(opcode) {
  case HF_HEX            : opcode_hf_hex(conf);             break;
  case HF_FUZZ_HEX       : opcode_hf_fuzz_hex(conf);        break;
  case HF_STRING         : opcode_hf_string(conf, -1);      break;
  case HF_FUZZ_STRING    : opcode_hf_fuzz_string(conf);     break;
  case HF_BLOCK_BEGIN    : opcode_hf_block_begin(conf);     break;
  case HF_BLOCK_END      : opcode_hf_block_end(conf);       break;
  case HF_BLOCK_SIZE_L_32: opcode_hf_block_size_l_32(conf); break;
  case HF_BLOCK_SIZE_L_16: opcode_hf_block_size_l_16(conf); break;
  case HF_BLOCK_SIZE_B_32: opcode_hf_block_size_b_32(conf); break;
  case HF_BLOCK_SIZE_B_16: opcode_hf_block_size_b_16(conf); break;
  case HF_BLOCK_SIZE_8   : opcode_hf_block_size_8(conf);    break;
  case HF_BLOCK_SIZE_S_16: opcode_hf_block_size_s_16(conf); break;
  case HF_BLOCK_SIZE_S_10: opcode_hf_block_size_s_10(conf); break;
  case HF_BLOCK_CRC32_B  : opcode_hf_block_crc32_b(conf);   break;
  case HF_BLOCK_CRC32_L  : opcode_hf_block_crc32_l(conf);   break;
  case HF_SEND           : opcode_hf_send(conf);            break;
  case HF_RECV           : opcode_hf_recv(conf);            break;


  default:
    error_("NOT SUPPORTED instruction detected!\n");
    error_("QUITTING!\n");
    return -1;
  }

  /* debug */
  debug(1, "<-----------------------[quit]\n");

  return 0;
}
示例#15
0
void  Serial::disconnectSerial()
{
    if(SerialPort->isOpen())
    {
        SerialPort->close();
        error_(SettingsSerial.name.toLocal8Bit() + " >> Закрыт!\r");
        qDebug("CLOSE");
    }
}
示例#16
0
static DBusMessage *ConnectionBlockingSendReply(struct DriverConnection *conn,
                                                DBusMessage *req, DBusError *err) {
  DBusMessage *rsp = NULL;
  if (!(rsp = dbus_connection_send_with_reply_and_block(conn->dbus, req, -1, err))) {
    error_("!!! send_with_reply_and_block failed: %s: %s", err->name, err->message);
    return NULL;
  }
  dbus_message_unref(req);
  return rsp;
}
示例#17
0
/*---------------------------------------------------------------------------*
 * NAME: main
 * DESC: Main Entry Point
 *---------------------------------------------------------------------------*/
int main(int argc, char **argv) {

  config *conf;
  unsigned int first_arg;

  /* create the configuration structure */
  conf = malloc_(sizeof(config));

  /* init the configuration structure */
  init_configuration(conf);

  /* parse the arguments */
  first_arg = parsing_args(argc, argv, conf);
  conf->xml_filename = argv[first_arg];

  /* copy the name of the .ad file */
  conf->output_name = argv[first_arg+1];

  /* basic check */
  if ((conf->output_name == NULL) || (conf->xml_filename == NULL)) {
    usage(argv, conf);
  }

  /* open the output_name file */
  output_desc = fopen(conf->output_name, "w");
  if (!output_desc) {
    error_("cannot write the file: \"%s\": ", conf->output_name);
    perror("");
    error_("QUITTING!\n");
    free(conf);
    exit(-1);
  }
  

  /* xml parsing of the file */
  xml_parsing(conf);

  /* free the configuration structure */
  free(conf);
  
  return 0;
}
void * init_space(void *arg){
  struct tuple *tuple = (struct tuple *) arg; 
  //init  hteachers
  Runner_Arg *args = malloc(sizeof(Runner_Arg)); 
  if (!args){
    perror("MEM :"); 
    exit(-1); 
  }
  pthread_mutex_t *read_fd = malloc(sizeof(pthread_mutex_t ));
  if (!read_fd){
    perror("MEM:");
    exit(-1);
  }

  args->fd =fdopen(tuple->fd, "r");
  if (args->fd == NULL) return error_("Could not create file from  pipe reading end");
  args->read_fd_lock = read_fd;
  if (pthread_mutex_init(read_fd, NULL)!=0) return error_("Initializing mutex failed: ");
 init_threads(args, tuple->users -1, space_runner); 
  //this thread runs staff_runner . new Staffs runners are launched by that method.
  return space_runner(args);
}
示例#19
0
  void setStringAttribute_(const nstr& key, const nvar& value){
    nstr str;

    if(value.isString()){
      str = value; 
    }
    else{
      if(!value.hasVector()){
        error_(key, value);
      }

      for(size_t i = 0; i < value.size(); ++i){
        if(!value[i].isString()){
          error_(key, value);
        }
      }
      
      str = nstr::join(value.vec(), "; ");
    }

    attrs_(key) = str;
  }
示例#20
0
int eUnixDomainSocket::connectToPath(eString path)
{
	sockaddr_un serv_addr_un;
	int res;

	if (mystate == Invalid)
	{
		/* the socket has been closed, create a new socket descriptor */
		int s=socket(AF_LOCAL, SOCK_STREAM, 0);
		mystate=Idle;
		setSocket(s, 1, mainloop);
	}
	
	if(socketdesc < 0){
		error_(errno);
		return(-1);
	}
	memset(&serv_addr_un, 0, sizeof(serv_addr_un));
	serv_addr_un.sun_family = AF_LOCAL;
	strcpy(serv_addr_un.sun_path, path.c_str());
	res=::connect(socketdesc, (const sockaddr*)&serv_addr_un, sizeof(serv_addr_un));
	if ((res < 0) && (errno != EINPROGRESS) && (errno != EINTR))
	{
		close();
		error_(errno);
		return(-3);
	}
	if (res < 0)	// EINPROGRESS or EINTR
	{
		rsn->setRequested(rsn->getRequested()|eSocketNotifier::Write);
		mystate=Connecting;
	} else
	{
		mystate=Connection;
		connected_();
	}
	return(0);
}
void * init_staff(void *arg){
  struct tuple *tuple = (struct tuple *) arg; 
  //init  hteachers
  Runner_Arg *args = malloc(sizeof(Runner_Arg)); 
  if (!args){
    perror("MEM :"); 
    exit(-1); 
  }
  pthread_mutex_t *read_fd = malloc(sizeof(pthread_mutex_t));
  if (!read_fd){
    perror("MEM :"); 
    exit(-1); 
  }

  args->fd =fdopen(tuple->fd, "r");
  if (args->fd == NULL) return error_("Could not create file from  pipe reading end\n");
  args->read_fd_lock = read_fd;
  if (pthread_mutex_init(read_fd, NULL)!=0) return error_("Initializing mutex failed: \n");
  // init n- 1 threads...
  init_threads(args, tuple->users -1, staff_runner); 
  //because we run a thread already:
  return staff_runner(args);
}
示例#22
0
文件: xml.c 项目: wuyihao14/autodafe
/*---------------------------------------------------------------------------*
 * NAME: xml_parse_ip
 * DESC: Parse the content of a PDML ip
 *---------------------------------------------------------------------------*/
void xml_parse_ip(config *conf, xmlNodePtr cur_orig) {

  xmlChar *value;
  unsigned long result1;
  unsigned long result2;

  /* look for the value of "ip.src" 1 down to the tree */
  value = xml_parse_field(cur_orig, 1, "ip.src", "value");
  if (!value) exit(-1);

  /* convert the value in unsigned long */
  result1 = strtoul((char *)value, NULL, 16);

  /* free the value */
  xmlFree(value);

  /* look for the value of "ip.dst" 1 down to the tree */
  value = xml_parse_field(cur_orig, 1, "ip.dst", "value");
  if (!value) exit(-1);

  /* convert the value in unsigned long */
  result2 = strtoul((char *)value, NULL, 16);
  debug(2, "value: %s\n", value);
  debug(2, "result2: %d\n", result2);

  /* free the value */
  xmlFree(value);

  if (conf->ip_client == 0) conf->ip_client = result1;
  if (conf->ip_server == 0) conf->ip_server = result2;
  debug(2, "ip of the client: %p\n", conf->ip_client);
  debug(2, "ip of the server: %p\n", conf->ip_server);
  debug(2, "result1: %p\n", result1);
  debug(2, "result2: %p\n", result2);

  /* now we write the ip of the packet */
  conf->ip_pkt = result1;

  /* check to be sure */
  if (conf->ip_pkt != conf->ip_client) {
    if (conf->ip_pkt != conf->ip_server) {
      error_("more than two IP address! Check your Ethereal logs!\n");
      exit(-1);
    }
  }



}
void *staff_runner(void *arg){
  Runner_Arg *rarg  = (Runner_Arg *) arg;
  int read;
  int fd_is_close; 

  while(1){
    // lock ; read file;
    int locked = pthread_mutex_lock(rarg->read_fd_lock);
      if (locked!=0) return error_lock("Could not lock on file : ", rarg->read_fd_lock);
      char *line = read_line_from_input(rarg->fd, &fd_is_close);
      if (!line){
	if (fd_is_close){
	  pthread_mutex_unlock(rarg->read_fd_lock); 
	  //TODO - next step. 
	  return NULL; 
	}
	return error_lock("Strange... could not allocate memory? : " , rarg->read_fd_lock);
      }
      if (pthread_mutex_unlock(rarg->read_fd_lock) != 0){
	perror("Unlock :");
      }
     char **arguments = split(line, &read);
    // Check arguments is clean:
    if (arguments == NULL )  return error_("Could not allocate in split of input line: ");
    if (read != 6 ){
      fprintf(stderr, "Ignoring input line: %s | %d.", line, read);
      freeArray(arguments);
      continue;
    }
    //Create new Staff entity.
    if (strcasecmp(arguments[2], "teacher") == 0){
      if (read_teacher(arg, arguments, read) != 0){
	return NULL; 
      }
    }
    else{
      fprintf(stderr, "EntityType  %s is not valid\n", arguments[2]);
    }
    freeArray(arguments); 
  }
}
示例#24
0
ParDiSO::ParDiSO(int pardiso_mtype, int pardiso_msglvl)
{
  // --------------------------------------------------------------------
  // ..  Setup ParDiSO control parameters und initialize the solvers     
  //     internal adress pointers. This is only necessary for the FIRST  
  //     call of the ParDiSO solver.                                     
  // --------------------------------------------------------------------
  mtype  = pardiso_mtype;
  msglvl = pardiso_msglvl;
  msglvl = 0;   // fabio hard-coded
  if(iam == 0)
    msglvl = 1; // fabio hard-coded
  solver = 0;

  maxfct = 1;
  mnum   = 1;
  nrhs   = 1; 
  perm   = 0;

  PARDISOINIT_D(pt,  &mtype, &solver, &iparm[1], &dparm[1], &error);

  error_();
}
示例#25
0
void ParDiSO::factorize(CSRdouble& A)
{
  double ddum;

  // for factorization phase should be equal to 12
  phase = 22;

  shiftIndices_(A, 1);

  PARDISOCALL_D(pt,
                &maxfct,
                &mnum,
                &mtype,
                &phase,
                &A.nrows,
                A.pData,
                A.pRows,
                A.pCols,
                perm,
                &nrhs,
                &iparm[1],
                &msglvl,
                &ddum,
                &ddum,
                &error,
                &dparm[1]);

  shiftIndices_(A, -1);
  
  if (error != 0) 
  {
    printf("\nERROR in factorization of matrix: %d", error);
    exit(1);
  }

  error_();
}
示例#26
0
void ParDiSO::solve(CSRdouble& A, double* x, double* rhs)
{
  // --------------------------------------------------------------------
  // ..  Back substitution and iterative refinement.                     
  // --------------------------------------------------------------------
  phase = 33;

  shiftIndices_(A, 1);


  PARDISOCALL_D(pt,
                &maxfct,
                &mnum,
                &mtype,
                &phase,
                &A.nrows,
                A.pData,
                A.pRows,
                A.pCols,
                perm,
                &nrhs,
                &iparm[1],
                &msglvl,
                rhs,
                x,
                &error,
                &dparm[1]);


  shiftIndices_(A, -1);
  if (error != 0) 
  {
    printf("\nERROR in back-substitution of matrix: %d", error);
    exit(1);
  }
  error_();
}
示例#27
0
文件: chan.c 项目: marayl/aug
static aug_chan*
pchan_process_BI_(aug_chan* ob, aug_chandler* handler, aug_bool* fork)
{
    struct pimpl_* impl = AUG_PODIMPL(struct pimpl_, chan_, ob);
    unsigned short events;

    /* Channel closed. */

    if (AUG_BADMD == impl->sticky_.md_)
        return NULL;

    events = aug_getsticky(&impl->sticky_);

    /* Close socket on error. */

    if (error_(handler, &impl->chan_, impl->sticky_.md_, events))
        return NULL;

    if (events && !aug_readychan(handler, &impl->chan_, events))
        return NULL;

    pretain_(impl);
    return ob;
}
示例#28
0
int eSocket::connect(struct addrinfo *addr)
{
	int res;
	struct addrinfo *ptr = addr;
	close();
	for (ptr = addr; ptr != NULL; ptr = ptr->ai_next)
	{
		if (setSocket(socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol), 1) < 0)
		{
			/* No need to close, setSocket only fails when socket() already failed */
			continue;
		}
		mystate = Idle;

		res = ::connect(socketdesc, ptr->ai_addr, ptr->ai_addrlen);
		if ((res < 0) && (errno != EINPROGRESS) && (errno != EINTR))
		{
			error_(errno);
			close(); /* Release and disconnect the notifier */
			continue;
		}
		if (res < 0)	// EINPROGRESS or EINTR
		{
			rsn->setRequested(rsn->getRequested() | eSocketNotifier::Write);
			mystate = Connecting;
			return 0;
		}
		else
		{
			mystate = Connection;
			connected_();
			return 1;
		}
	}
	return -1;
}
示例#29
0
void mergeF2 (float a[], float t[], int i, int iu, int j, int ju, int k) {
  if (i>iu)  { copyseq (a,t,j,ju,k); }
  else {
    if (j>ju) { copyseq (a,t,i,iu,k); }
    else {
      if (i<0 || i>=dim) { error_(); };
      if (j<0 || j>=dim) { error_(); };
      if (a[i] <= a[j]) {
        if (k<0 || k>=dim) { error_(); };
        if (i<0 || i>=dim) { error_(); };
        t[k]=a[i];
        mergeF2 (a,t,i+1,iu,j,ju,k+1);
      } else {
        if (k<0 || k>=dim) { error_(); };
        if (j<0 || j>=dim) { error_(); };
        t[k]=a[j];
        mergeF2 (a,t,i,iu,j+1,ju,k+1);
      }
    }
  }
}
示例#30
0
文件: xml.c 项目: wuyihao14/autodafe
/*---------------------------------------------------------------------------*
 * NAME: xml_parsing
 * DESC: Main xml parsing function
 *---------------------------------------------------------------------------*/
void xml_parsing(config *conf) {

  /* open the file using the libxml2 library */
  debug(3, "xml parsing of the file: %s\n", conf->xml_filename);
  conf->doc = xmlParseFile(conf->xml_filename);
  if (conf->doc == NULL) {
    error_("Document not parsed successfully!\n");
    return;
  }
  verbose_("[*] parsing the file: %s\n", conf->xml_filename);

  /* point on the root element of the tree */
  conf->cur = xmlDocGetRootElement(conf->doc);
  if (conf->cur == NULL) {
    error_("Empty Document!\n");
    xmlFreeDoc(conf->doc);
    return;
  }

  /* check if the format seems to be PDML: ie root = pdml */
  debug(3,"name of the root: %s\n", conf->cur->name);
  if (xmlStrcmp(conf->cur->name, (const xmlChar *) "pdml")) {
    error_("Document NOT a PDML file!\n");
    xmlFreeDoc(conf->doc);
    return;
  }

  /* start the autodafe's script language */
  output_("/*--------------------------------------------------------------------------*\n");
  output_(" * xml autodafe's parser v.%d.%d (c) Martin Vuagnoux - 2004-2006            *\n", MAJOR_VERSION, MINOR_VERSION);
  output_(" * auto-generated script using PDML (Packet Details Markup Language) source *\n");
  output_(" *--------------------------------------------------------------------------*/\n\n");

  /* the file is good, check for the packet entry (child) */
  conf->cur = conf->cur->xmlChildrenNode;
  while (conf->cur != NULL) {
    if (!xmlStrcmp(conf->cur->name, (const xmlChar *) "packet")) {
      debug(3, "packet field found\n");
      /* open the block */
      output_(AD_F_BLOCK_BEGIN"(\"packet_%d\");\n", conf->packet_counter);

      /* parse the internal data of the packet block */
      xml_parse_packet(conf);

      /* close the block */
      output_(AD_F_BLOCK_END"(\"packet_%d\");\n", conf->packet_counter);

      /* client send/recv */
      if ((conf->ip_pkt == conf->ip_client) && (conf->port_pkt == conf->port_client)) {
	debug(3, "check client\n");
	if (conf->transport_type == 1) {
	  if (conf->invert == 0)
	    output_(AD_F_SEND"(\"packet_%d\");  /* tcp */\n\n", conf->packet_counter);
	  else
	    output_(AD_F_RECV"(\"packet_%d\");  /* tcp */\n\n", conf->packet_counter);
	}
	else if (conf->transport_type == 2) {
	  if (conf->invert == 0)
	    output_(AD_F_SEND"(\"packet_%d\");  /* udp */\n\n", conf->packet_counter);
	  else
	    output_(AD_F_RECV"(\"packet_%d\");  /* udp */\n\n", conf->packet_counter);
	}
      }

      /* server send/recv */
      else if ((conf->ip_pkt == conf->ip_server) && (conf->port_pkt == conf->port_server)) {
	debug(3, "check server\n");
	if (conf->transport_type == 1) {
	  if (conf->invert == 1)
	    output_(AD_F_SEND"(\"packet_%d\");  /* tcp */\n\n", conf->packet_counter);
	  else
	    output_(AD_F_RECV"(\"packet_%d\");  /* tcp */\n\n", conf->packet_counter);
	}
	else if (conf->transport_type == 2) {
	  if (conf->invert == 1)
	    output_(AD_F_SEND"(\"packet_%d\");  /* udp */\n\n", conf->packet_counter);
	  else
	    output_(AD_F_RECV"(\"packet_%d\");  /* udp */\n\n", conf->packet_counter);
	}
      }

      else {
	error_("too much different packets?! Check your Ethereal logs!\n");
	error_("client: ip->%d, port->%d\n", conf->ip_client, conf->port_client);
	error_("server: ip->%d, port->%d\n", conf->ip_server, conf->port_server);
	error_("packet: ip->%d, port->%d\n", conf->ip_pkt, conf->port_pkt);
	exit(-1);
      }

      conf->packet_counter++;
    }
    conf->cur = conf->cur->next;
  }

  /* free */
  xmlFreeDoc(conf->doc);
}