コード例 #1
0
ファイル: session_impl.cpp プロジェクト: Corvusoft/restbed
 void SessionImpl::transmit( const Response& response, const function< void ( const error_code&, size_t ) >& callback ) const
 {
     auto hdrs = m_settings->get_default_headers( );
     
     if ( m_resource not_eq nullptr )
     {
         const auto m_resource_headers = m_resource->m_pimpl->m_default_headers;
         hdrs.insert( m_resource_headers.begin( ), m_resource_headers.end( ) );
     }
     
     hdrs.insert( m_headers.begin( ), m_headers.end( ) );
     
     auto response_headers = response.get_headers( );
     hdrs.insert( response_headers.begin( ), response_headers.end( ) );
     
     auto payload = make_shared< Response >( );
     payload->set_headers( hdrs );
     payload->set_body( response.get_body( ) );
     payload->set_version( response.get_version( ) );
     payload->set_protocol( response.get_protocol( ) );
     payload->set_status_code( response.get_status_code( ) );
     payload->set_status_message( response.get_status_message( ) );
     
     if ( payload->get_status_message( ).empty( ) )
     {
         payload->set_status_message( m_settings->get_status_message( payload->get_status_code( ) ) );
     }
     
     m_request->m_pimpl->m_socket->start_write( Http::to_bytes( payload ), callback );
 }
コード例 #2
0
  void ICMPv4::ping_reply(full_header* full_hdr, uint16_t size) {
    auto packet_ptr = inet_.create_packet(size);
    auto buf = packet_ptr->buffer();

    icmp_header* hdr = &reinterpret_cast<full_header*>(buf)->icmp_hdr;
    hdr->type = ICMP_ECHO_REPLY;
    hdr->code = 0;
    hdr->identifier = full_hdr->icmp_hdr.identifier;
    hdr->sequence   = full_hdr->icmp_hdr.sequence;

    debug("<ICMP> Rest of header IN: 0x%lx OUT: 0x%lx\n",
          full_hdr->icmp_hdr.rest, hdr->rest);

    debug("<ICMP> Transmitting answer\n");

    // Populate response IP header
    auto ip4_pckt = static_unique_ptr_cast<PacketIP4>(std::move(packet_ptr));
    ip4_pckt->init();
    ip4_pckt->set_src(full_hdr->ip_hdr.daddr);
    ip4_pckt->set_dst(full_hdr->ip_hdr.saddr);
    ip4_pckt->set_protocol(IP4::IP4_ICMP);
    ip4_pckt->set_ip_data_length(sizeof(icmp_header) + size - sizeof(full_header));

    // Copy payload from old to new packet
    uint8_t* payload = reinterpret_cast<uint8_t*>(hdr) + sizeof(icmp_header);
    uint8_t* source  = reinterpret_cast<uint8_t*>(&full_hdr->icmp_hdr) + sizeof(icmp_header);
    memcpy(payload, source, size - sizeof(full_header));

    hdr->checksum = 0;
    hdr->checksum = net::checksum(reinterpret_cast<uint16_t*>(hdr),
                                  size - sizeof(full_header) + sizeof(icmp_header));

    network_layer_out_(std::move(ip4_pckt));
  }
コード例 #3
0
ファイル: usb-hid.c プロジェクト: KevinOConnor/seabios
static int
usb_mouse_setup(struct usbdevice_s *usbdev
                , struct usb_endpoint_descriptor *epdesc)
{
    if (! CONFIG_USB_MOUSE)
        return -1;
    if (mouse_pipe)
        // XXX - this enables the first found mouse (could be random)
        return -1;

    if (epdesc->wMaxPacketSize < 3 || epdesc->wMaxPacketSize > 8)
        return -1;

    // Enable "boot" protocol.
    int ret = set_protocol(usbdev->defpipe, 0);
    if (ret)
        return -1;

    mouse_pipe = usb_alloc_pipe(usbdev, epdesc);
    if (!mouse_pipe)
        return -1;

    dprintf(1, "USB mouse initialized\n");
    return 0;
}
コード例 #4
0
ファイル: usb-hid.c プロジェクト: KevinOConnor/seabios
static int
usb_kbd_setup(struct usbdevice_s *usbdev
              , struct usb_endpoint_descriptor *epdesc)
{
    if (! CONFIG_USB_KEYBOARD)
        return -1;
    if (keyboard_pipe)
        // XXX - this enables the first found keyboard (could be random)
        return -1;

    if (epdesc->wMaxPacketSize != 8)
        return -1;

    // Enable "boot" protocol.
    int ret = set_protocol(usbdev->defpipe, 0);
    if (ret)
        return -1;
    // Periodically send reports to enable key repeat.
    ret = set_idle(usbdev->defpipe, KEYREPEATMS);
    if (ret)
        return -1;

    keyboard_pipe = usb_alloc_pipe(usbdev, epdesc);
    if (!keyboard_pipe)
        return -1;

    dprintf(1, "USB keyboard initialized\n");
    return 0;
}
コード例 #5
0
void RedClient::set_target(const std::string& host, int port, int sport, int protocol)
{
    if (protocol != get_protocol()) {
        LOG_INFO("old protocol %d, new protocol %d", get_protocol(), protocol);
    }

    _port = port;
    _sport = sport;
    _host.assign(host);
    set_protocol(protocol);
}
コード例 #6
0
ファイル: ip_header.c プロジェクト: Clanne/Projet_RP
void forge_ipv4_header( void* buf , struct sockaddr* destination , uint8_t protonum ) {
    ipv4_header_t* iph = (ipv4_header_t*) buf;
    memset( buf , 0 , sizeof( ipv4_header_t ) );
    iph->version = 4;
    iph->IHL= 5;
    set_destination( iph ,(struct sockaddr_in *) destination );
    set_source( iph , inet_addr(SOURCEIP) );
    set_TTL(iph, 80);
    set_protocol( iph, protonum );
    set_packet_length( iph , 28 );//taille d'un echo request
    set_ipv4_checksum( iph );
}
コード例 #7
0
ファイル: packet_udp.hpp プロジェクト: jdiego/IncludeOS
 //! initializes to a default, empty UDP packet, given
 //! a valid MTU-sized buffer
 void init()
 {            
   PacketIP4::init();
   // source and destination ports
   header().sport = 0;
   header().dport = 0;
   // set zero length
   set_length(0);
   // zero the optional checksum
   header().checksum = 0;
   // set UDP payload location (!?)
   payload_ = buffer() + sizeof(UDP::full_header);
   set_protocol(IP4::IP4_UDP);
 }
コード例 #8
0
ファイル: packet_udp.hpp プロジェクト: AnnikaH/IncludeOS
    void init(uint16_t l_port, uint16_t d_port)
    {
      Expects(data_end() == layer_begin() + ip_header_length());

      // Initialize UDP packet header
      // source and destination ports
      set_src_port(l_port);
      set_dst_port(d_port);
      // set zero length
      set_length(sizeof(UDP::header));
      // zero the optional checksum
      header().checksum = 0;
      set_protocol(Protocol::UDP);
    }
コード例 #9
0
ファイル: display.cpp プロジェクト: barry-scott/BarrysEmacs
void SystemExpressionRepresentationScreenWidth::assign_value( ExpressionRepresentation *new_value )
{
    int width = new_value->asInt();
    if( width < 32 || width > MSCREENWIDTH )
        error( FormatString("terminal-width must be > 32 and <= %d") << MSCREENWIDTH );
    else
    {
        term_width = width;
        theActiveView->t_width = width;
        theActiveView->t_change_width( width );
        set_protocol( protocol_mode );
        theActiveView->fit_windows_to_screen();
        screen_garbaged = 1;
    }
}
コード例 #10
0
ファイル: display.cpp プロジェクト: barry-scott/BarrysEmacs
void SystemExpressionRepresentationScreenLength::assign_value( ExpressionRepresentation *new_value )
{
    int length = new_value->asInt();

    if( length < 3 || length > MSCREENLENGTH )
        error( FormatString("terminal-length must be > 3 and <= %d") << MSCREENLENGTH );
    else
    {
        term_length = length;
        theActiveView->t_length = length;
        set_protocol( protocol_mode );
        theActiveView->fit_windows_to_screen();
        screen_garbaged = 1;
    }
}
コード例 #11
0
ファイル: connection.cpp プロジェクト: xfun68/test
Connection::Connection(void) :
    init_ok_(0),
    last_recv_time_(time(NULL)),
    last_send_time_(time(NULL)),
    last_error_(0),
    auto_release_(0),
    state_(CLOSED),
    default_event_handler_("ConnDefHandler"),
    connection_manager_(NULL),
    event_handler_(&default_event_handler_)
{
    set_ip(0U);
    set_port(0U);
    set_protocol("tcp");
}
コード例 #12
0
ファイル: Url.cpp プロジェクト: asionius/fibjs
void Url::parseProtocol(const char*& url)
{
    const char* p = url;
    char ch;

    while ((ch = *p)
        && (qisascii(ch) || qisdigit(ch) || ch == '.' || ch == '+'
               || ch == '-'))
        p++;

    if (ch == ':') {
        p++;

        exlib::string str(url, p - url);
        set_protocol(str);
        url = p;
    }
}
コード例 #13
0
ファイル: Url.cpp プロジェクト: asionius/fibjs
result_t Url::format(v8::Local<v8::Object> args)
{
    clear();

    Isolate* isolate = holder();

    exlib::string str;
    v8::Local<v8::Value> v;

    if (getString(isolate, args, "protocol", str))
        set_protocol(str);

    if (getString(isolate, args, "username", str))
        set_username(str);
    if (getString(isolate, args, "password", str))
        set_password(str);

    if (getString(isolate, args, "host", str))
        set_host(str);
    if (getString(isolate, args, "port", str))
        set_port(str);

    if (getString(isolate, args, "hostname", str))
        set_hostname(str);

    if (getString(isolate, args, "pathname", str))
        set_pathname(str);

    v = args->Get(holder()->NewString("query"));
    if (!IsEmpty(v))
        set_query(v);

    if (getString(isolate, args, "hash", str))
        set_hash(str);

    if (m_slashes && m_protocol.compare("file:") && m_hostname.length() == 0)
        m_slashes = false;

    v = args->Get(holder()->NewString("slashes"));
    if (!IsEmpty(v))
        set_slashes(v->BooleanValue());

    return 0;
}
コード例 #14
0
ファイル: device_ds3.c プロジェクト: DSkywalk/RetroArch
static void *ds3_init(void *handle)
{
   ds3_instance_t *instance;
   int errors = 0;
   RARCH_LOG("[ds3]: init\n");
   instance = (ds3_instance_t *)calloc(1, sizeof(ds3_instance_t));
   if(!instance)
     goto error;

   memset(instance, 0, sizeof(ds3_instance_t));
   instance->handle = handle;

   RARCH_LOG("[ds3]: setting protocol\n");

   /* this might fail, but we don't care. */
   set_protocol(instance, 1);

   RARCH_LOG("[ds3]: sending control packet\n");
   if(send_control_packet(instance) < 0)
      errors++;

   RARCH_LOG("[ds3]: sending activation packet\n");
   if(send_activation_packet(instance) < 0)
      errors++;

   if(errors)
      goto error;

   instance->pad = hid_pad_register(instance, &ds3_pad_connection);
   if(!instance->pad)
      goto error;

   RARCH_LOG("[ds3]: init complete.\n");
   return instance;

   error:
      RARCH_ERR("[ds3]: init failed.\n");
      if(instance)
         free(instance);
      return NULL;
}
コード例 #15
0
ファイル: connection.cpp プロジェクト: xfun68/test
Connection::Connection(
    const char* string_ip,
    uint16_t port,
    EventHandler* event_handler) :
    init_ok_(0),
    last_recv_time_(time(NULL)),
    last_send_time_(time(NULL)),
    last_error_(0),
    auto_release_(0),
    state_(CLOSED),
    default_event_handler_("ConnDefHandler"),
    connection_manager_(NULL)
{
    set_ip(string_ip);
    set_port(port);
    set_protocol("tcp");

    if (NULL == event_handler) {
        event_handler_ = &default_event_handler_;
    } else {
        event_handler_ = event_handler;
    }
}
コード例 #16
0
ファイル: config_file.c プロジェクト: Bruno17/Irdroid
static struct ir_remote * read_config_recursive(FILE *f, const char *name, int depth)
{
	char buf[LINE_LEN+1], *key, *val, *val2;
        int len,argc;
	struct ir_remote *top_rem=NULL,*rem=NULL;
        struct void_array codes_list,raw_codes,signals;
	struct ir_ncode raw_code={NULL,0,0,NULL};
	struct ir_ncode name_code={NULL,0,0,NULL};
	struct ir_ncode *code;
	int mode=ID_none;

	line=0;
	parse_error=0;
	LOGPRINTF(2, "parsing '%s'", name);

	while(fgets(buf,LINE_LEN,f)!=NULL)
	{
		line++;
		len=strlen(buf);
		if(len==LINE_LEN && buf[len-1]!='\n')
		{
			logprintf(LOG_ERR,"line %d too long in config file",
				  line);
			parse_error=1;
			break;
		}

		if(len>0)
		{
			len--;
			if(buf[len]=='\n') buf[len]=0;
		}
		if(len>0)
		{
			len--;
			if(buf[len]=='\r') buf[len]=0;
		}
                /* ignore comments */
                if(buf[0]=='#'){
			continue;
                }
		key=strtok(buf, whitespace);
		/* ignore empty lines */
		if(key==NULL) continue;
		val=strtok(NULL, whitespace);
		if(val!=NULL){
			val2=strtok(NULL, whitespace);
			LOGPRINTF(3,"\"%s\" \"%s\"",key,val);
			if (strcasecmp("include",key)==0){
                                FILE* childFile;
				const char *childName;
				const char *fullPath;
				char result[FILENAME_MAX+1];


				if (depth > MAX_INCLUDES) {
					logprintf(LOG_ERR,"error opening child file defined at %s:%d",name,line);
					logprintf(LOG_ERR,"too many files included");
					parse_error=-1;
					break;
				}

				childName = lirc_parse_include(val);
				if (!childName){
					logprintf(LOG_ERR,"error parsing child file value defined at line %d:",line);
					logprintf(LOG_ERR,"invalid quoting");
					parse_error=-1;
					break;
				}

				fullPath = lirc_parse_relative(result, sizeof(result), childName, name);
				if (!fullPath) {
					logprintf(LOG_ERR,"error composing relative file path defined at line %d:",line);
					logprintf(LOG_ERR,"resulting path too long");
					parse_error=-1;
					break;
				}

				childFile = fopen(fullPath, "r");
				if (childFile == NULL){
					logprintf(LOG_ERR,"error opening child file '%s' defined at line %d:",fullPath, line);
					logprintf(LOG_ERR,"ignoring this child file for now.");
				}
				else{
					int save_line = line;

					if (!top_rem){
						/* create first remote */
						LOGPRINTF(2,"creating first remote");
						rem = read_config_recursive(childFile, fullPath, depth + 1);
						if(rem != (void *) -1 && rem != NULL) {
							top_rem = rem;
						} else {
							rem = NULL;
						}
					}else{
						/* create new remote */
						LOGPRINTF(2,"creating next remote");
						rem->next=read_config_recursive(childFile, fullPath, depth + 1);
						if(rem->next != (void *) -1 && rem->next != NULL) {
							rem=rem->next;
						} else {
							rem->next = NULL;
						}
					}
					fclose(childFile);
					line = save_line;
				}
			}else if (strcasecmp("begin",key)==0){
				if (strcasecmp("codes", val)==0){
                                        /* init codes mode */
					LOGPRINTF(2,"    begin codes");
					if (!checkMode(mode, ID_remote,
						       "begin codes")) break;
					if (rem->codes){
						logprintf(LOG_ERR,"error in configfile line %d:",line);
						logprintf(LOG_ERR,"codes are already defined");
						parse_error=1;
						break;
					}

                                        init_void_array(&codes_list,30, sizeof(struct ir_ncode));
                                        mode=ID_codes;
                                }else if(strcasecmp("raw_codes",val)==0){
                                        /* init raw_codes mode */
					LOGPRINTF(2,"    begin raw_codes");
					if(!checkMode(mode, ID_remote,
						  "begin raw_codes")) break;
					if (rem->codes){
						logprintf(LOG_ERR,"error in configfile line %d:",line);
						logprintf(LOG_ERR,"codes are already defined");
						parse_error=1;
						break;
					}
					set_protocol(rem, RAW_CODES);
					raw_code.code=0;
                                        init_void_array(&raw_codes,30, sizeof(struct ir_ncode));
                                        mode=ID_raw_codes;
                                }else if(strcasecmp("remote",val)==0){
					/* create new remote */
					LOGPRINTF(1,"parsing remote");
					if(!checkMode(mode, ID_none,
						  "begin remote")) break;
                                        mode=ID_remote;
                                        if (!top_rem){
                                                /* create first remote */
						LOGPRINTF(2,"creating first remote");
                                                rem=top_rem=s_malloc(sizeof(struct ir_remote));
                                        }else{
                                                /* create new remote */
						LOGPRINTF(2,"creating next remote");
                                                rem->next=s_malloc(sizeof(struct ir_remote));;
                                                rem=rem->next;
                                        }
				}else if(mode==ID_codes){
					code=defineCode(key, val, &name_code);
					while(!parse_error && val2!=NULL)
					{
						struct ir_code_node *node;

						if(val2[0]=='#') break; /* comment */
						node=defineNode(code, val2);
						val2=strtok(NULL, whitespace);
					}
					code->current=NULL;
					add_void_array(&codes_list, code);
                                }else{
                                        logprintf(LOG_ERR,"error in configfile line %d:",line);
					logprintf(LOG_ERR,"unknown section \"%s\"",val);
                                        parse_error=1;
                                }
				if(!parse_error && val2!=NULL)
				{
					logprintf(LOG_WARNING,"garbage after "
						  "'%s' token in line %d ignored",
						  val,line);
				}
                        }else if (strcasecmp("end",key)==0){

				if (strcasecmp("codes", val)==0){
					/* end Codes mode */
					LOGPRINTF(2,"    end codes");
                                        if (!checkMode(mode, ID_codes,
						       "end codes")) break;
                                        rem->codes=get_void_array(&codes_list);
                                        mode=ID_remote;     /* switch back */

                                }else if(strcasecmp("raw_codes",val)==0){
                                        /* end raw codes mode */
					LOGPRINTF(2,"    end raw_codes");

					if(mode==ID_raw_name){
						raw_code.signals=get_void_array(&signals);
						raw_code.length=signals.nr_items;
						if(raw_code.length%2==0)
						{
							logprintf(LOG_ERR,"error in configfile line %d:",line);
							logprintf(LOG_ERR,"bad signal length");
							parse_error=1;
						}
						if(!add_void_array(&raw_codes, &raw_code))
							break;
						mode=ID_raw_codes;
					}
                                        if(!checkMode(mode,ID_raw_codes,
						      "end raw_codes")) break;
					rem->codes=get_void_array(&raw_codes);
					mode=ID_remote;     /* switch back */
                                }else if(strcasecmp("remote",val)==0){
                                        /* end remote mode */
					LOGPRINTF(2,"end remote");
					/* print_remote(rem); */
                                        if (!checkMode(mode,ID_remote,
                                                  "end remote")) break;
					if(!sanityChecks(rem)) {
                                                parse_error=1;
                                                break;
					}

#                                       ifdef DYNCODES
					if(rem->dyncodes_name==NULL)
					{
						rem->dyncodes_name=s_strdup("unknown");
					}
					rem->dyncodes[0].name=rem->dyncodes_name;
					rem->dyncodes[1].name=rem->dyncodes_name;
#                                       endif
					/* not really necessary because we
					   clear the alloced memory */
                                        rem->next=NULL;
					rem->last_code=NULL;
                                        mode=ID_none;     /* switch back */
				}else if(mode==ID_codes){
					code=defineCode(key, val, &name_code);
					while(!parse_error && val2!=NULL)
					{
						struct ir_code_node *node;

						if(val2[0]=='#') break; /* comment */
						node=defineNode(code, val2);
						val2=strtok(NULL, whitespace);
					}
					code->current=NULL;
					add_void_array(&codes_list, code);
                                }else{
                                        logprintf(LOG_ERR,"error in configfile line %d:",line);
					logprintf(LOG_ERR,"unknown section %s",val);
                                        parse_error=1;
                                }
				if(!parse_error && val2!=NULL)
				{
					logprintf(LOG_WARNING,"garbage after '%s'"
						  " token in line %d ignored",
						  val,line);
				}
                        } else {
				switch (mode){
				case ID_remote:
					argc=defineRemote(key, val, val2, rem);
					if(!parse_error && ((argc==1 && val2!=NULL) || 
					   (argc==2 && val2!=NULL && strtok(NULL, whitespace)!=NULL)))
					{
						logprintf(LOG_WARNING,"garbage after '%s'"
							  " token in line %d ignored",
							  key,line);
					}
					break;
				case ID_codes:
					code=defineCode(key, val, &name_code);
					while(!parse_error && val2!=NULL)
					{
						struct ir_code_node *node;

						if(val2[0]=='#') break; /* comment */
						node=defineNode(code, val2);
						val2=strtok(NULL, whitespace);
					}
					code->current=NULL;
					add_void_array(&codes_list, code);
					break;
				case ID_raw_codes:
				case ID_raw_name:
					if(strcasecmp("name",key)==0){
						LOGPRINTF(3,"Button: \"%s\"",val);
						if(mode==ID_raw_name)
						{
                                                        raw_code.signals=get_void_array(&signals);
							raw_code.length=signals.nr_items;
							if(raw_code.length%2==0)
							{
								logprintf(LOG_ERR,"error in configfile line %d:",line);
								logprintf(LOG_ERR,"bad signal length");
								parse_error=1;
							}
							if(!add_void_array(&raw_codes, &raw_code))
								break;
						}
						if(!(raw_code.name=s_strdup(val))){
							break;
						}
						raw_code.code++;
						init_void_array(&signals,50,sizeof(lirc_t));
						mode=ID_raw_name;
						if(!parse_error && val2!=NULL)
						{
							logprintf(LOG_WARNING,"garbage after '%s'"
								  " token in line %d ignored",
								  key,line);
						}
					}else{
						if(mode==ID_raw_codes)
						{
							logprintf(LOG_ERR,"no name for signal defined at line %d",line);
							parse_error=1;
							break;
						}
						if(!addSignal(&signals, key)) break;
						if(!addSignal(&signals, val)) break;
						if (val2){
							if (!addSignal(&signals, val2)){
								break;
							}
						}
						while ((val=strtok(NULL, whitespace))){
							if (!addSignal(&signals, val)) break;
						}
					}
					break;
				}
			}
		}else if(mode==ID_raw_name){
                        if(!addSignal(&signals, key)){
				break;
			}
		}else{
                        logprintf(LOG_ERR,"error in configfile line %d", line);
			parse_error=1;
			break;
                }
                if (parse_error){
                        break;
                }
        }
	if(mode!=ID_none)
	{
		switch(mode)
		{
		case ID_raw_name:
			if(raw_code.name!=NULL)
			{
				free(raw_code.name);
				if(get_void_array(&signals)!=NULL)
					free(get_void_array(&signals));
			}
		case ID_raw_codes:
			rem->codes=get_void_array(&raw_codes);
			break;
		case ID_codes:
			rem->codes=get_void_array(&codes_list);
			break;
		}
		if(!parse_error)
		{
			logprintf(LOG_ERR,"unexpected end of file");
			parse_error=1;
		}
	}
        if (parse_error){
		static int print_error = 1;

		if(print_error) {
			logprintf(LOG_ERR, "reading of file '%s' failed",
				  name);
			print_error = 0;
		}
		free_config(top_rem);
		if(depth == 0) print_error = 1;
                return((void *) -1);
        }
	/* kick reverse flag */
	/* handle RC6 flag to be backwards compatible: previous RC-6
	   config files did not set rc6_mask */
	rem=top_rem;
	while(rem!=NULL)
	{
		if((!is_raw(rem)) && rem->flags&REVERSE)
		{
			struct ir_ncode *codes;

			if(has_pre(rem))
			{
				rem->pre_data=reverse(rem->pre_data,
						      rem->pre_data_bits);
			}
			if(has_post(rem))
			{
				rem->post_data=reverse(rem->post_data,
						       rem->post_data_bits);
			}
			codes=rem->codes;
			while(codes->name!=NULL)
			{
				codes->code=reverse(codes->code,rem->bits);
				codes++;
			}
			 rem->flags=rem->flags&(~REVERSE);
			 rem->flags=rem->flags|COMPAT_REVERSE;
			/* don't delete the flag because we still need
			   it to remain compatible with older versions
			*/
		}
		if(rem->flags&RC6 && rem->rc6_mask==0 && rem->toggle_bit>0)
		{
			int all_bits=bit_count(rem);

			rem->rc6_mask=((ir_code) 1)<<(all_bits-rem->toggle_bit);
		}
		if(rem->toggle_bit > 0)
		{
			int all_bits=bit_count(rem);

			if(has_toggle_bit_mask(rem))
			{
				logprintf(LOG_WARNING,
					  "%s uses both toggle_bit and "
					  "toggle_bit_mask", rem->name);
			}
			else
			{
				rem->toggle_bit_mask=((ir_code) 1)<<(all_bits-rem->toggle_bit);
			}
			rem->toggle_bit = 0;
		}
		if(has_toggle_bit_mask(rem))
		{
			if(!is_raw(rem) && rem->codes)
			{
				rem->toggle_bit_mask_state = (rem->codes->code & rem->toggle_bit_mask);
				if(rem->toggle_bit_mask_state)
				{
					/* start with state set to 0 for backwards compatibility */
					rem->toggle_bit_mask_state ^= rem->toggle_bit_mask;
				}
			}
		}
		if(is_serial(rem))
		{
			lirc_t base;

			if(rem->baud>0)
			{
				base=1000000/rem->baud;
				if(rem->pzero==0 && rem->szero==0)
				{
					rem->pzero=base;
				}
				if(rem->pone==0 && rem->sone==0)
				{
					rem->sone=base;
				}
			}
			if(rem->bits_in_byte==0)
			{
				rem->bits_in_byte=8;
			}
		}
		if(rem->min_code_repeat>0)
		{
			if(!has_repeat(rem) ||
			   rem->min_code_repeat>rem->min_repeat)
			{
				logprintf(LOG_WARNING,
					  "invalid min_code_repeat value");
				rem->min_code_repeat = 0;
			}
		}
		calculate_signal_lengths(rem);
		rem=rem->next;
	}

	top_rem = sort_by_bit_count(top_rem);
#       if defined(DEBUG) && !defined(DAEMONIZE)
        /*fprint_remotes(stderr, top_rem);*/
#       endif
        return (top_rem);
}
コード例 #17
0
static int set_general(struct sc_stream* stream, char* stream_str)
{
  int rc = 0;
  uint8_t mac[6];
  char* key;
  char* next_field = stream_str;

  /* General format is series of key=value pairs, separated by ",". */
  while( next_field && (rc == 0) ) {
    char* value;
    char* field;

    field = strsep(&next_field, ",");

    /* Split key and value */
    value = field;
    key = strsep(&value, "=");

    if( !value ) {
      /* Handle some key-only magic values */
      if( !strcmp(key, "all") )
        rc = sc_stream_all(stream);
      /* The following needs a strncmp because we pass the stream as
       * 'sniff [0,1]' */
      else if( !strncmp(key, "sniff", strlen("sniff")) )
        rc = sc_stream_sniff(stream, key);
      else if( !strcmp(key, "ip") )
        rc = set_eth_type(stream, key);
      else if( !strcmp(key, "udp") || !strcmp(key, "tcp") )
        rc = set_protocol(stream, key);
      else {
        fprintf(stderr, "%s: ERROR: No value for key %s\n", __func__, key);
        return -EINVAL;
      }
    }
    else {
      if( !strcmp(key, "dmac") ) {
        if( parse_mac(value, mac) < 0 ) {
          fprintf(stderr, "%s: ERROR: Failed to parse mac \"%s\"\n",
                  __func__, key);
          return -EINVAL;
        }
        rc = sc_stream_eth_dhost(stream, mac);
      }
      else if( !strcmp(key, "smac") ) {
        if( parse_mac(value, mac) < 0 )
          fprintf(stderr, "%s: ERROR: Failed to parse mac \"%s\"\n",
                  __func__, key);
        return -EINVAL;
        rc = sc_stream_eth_shost(stream, mac);
      }
      else if( !strcmp(key, "vid") ) {
        rc = set_vlan_id(stream, value);
      }
      else if( !strcmp(key, "eth_type") ) {
        rc = set_eth_type(stream, value);
      }
      else if( !strcmp(key, "shost") ) {
        rc = sc_stream_ip_source_host(stream, value);
      }
      else if( !strcmp(key, "dhost") ) {
        rc = sc_stream_ip_dest_host(stream, value);
      }
      else if( !strcmp(key, "ip_protocol") ) {
        rc = set_protocol(stream, value);
      }
      else if( !strcmp(key, "sport") ) {
        rc = sc_stream_ip_source_port(stream, value);
      }
      else if( !strcmp(key, "dport") ) {
        rc = sc_stream_ip_dest_port(stream, value);
      }
      else {
        fprintf(stderr, "%s: ERROR: Unrecognised key \"%s\"\n", __func__, key);
        return -EINVAL;
      }
    }
  }

  return rc;
}
コード例 #18
0
ファイル: extra_comms.c プロジェクト: vanElden/burp
int extra_comms(struct async *as,
	char **incexc, int *srestore, struct conf **confs, struct conf **cconfs)
{
	struct vers vers;
	struct asfd *asfd;
	asfd=as->asfd;
	//char *restorepath=NULL;
	const char *peer_version=NULL;

	if(vers_init(&vers, cconfs)) goto error;

	if(vers.cli<vers.directory_tree)
	{
		set_int(confs[OPT_DIRECTORY_TREE], 0);
		set_int(cconfs[OPT_DIRECTORY_TREE], 0);
	}

	// Clients before 1.2.7 did not know how to do extra comms, so skip
	// this section for them.
	if(vers.cli<vers.min) return 0;

	if(asfd_read_expect(asfd, CMD_GEN, "extra_comms_begin"))
	{
		logp("problem reading in extra_comms\n");
		goto error;
	}
	// Want to tell the clients the extra comms features that are
	// supported, so that new clients are more likely to work with old
	// servers.
	if(vers.cli==vers.feat_list)
	{
		// 1.3.0 did not support the feature list.
		if(asfd->write_str(asfd, CMD_GEN, "extra_comms_begin ok"))
		{
			logp("problem writing in extra_comms\n");
			goto error;
		}
	}
	else
	{
		if(send_features(asfd, cconfs)) goto error;
	}

	if(extra_comms_read(as, &vers, srestore, incexc, confs, cconfs))
		goto error;

	peer_version=get_string(cconfs[OPT_PEER_VERSION]);

	// This needs to come after extra_comms_read, as the client might
	// have set PROTO_1 or PROTO_2.
	switch(get_protocol(cconfs))
	{
		case PROTO_AUTO:
			// The protocol has not been specified. Make a choice.
			if(vers.cli<vers.burp2)
			{
				// Client is burp-1.x.x, use protocol1.
				set_protocol(confs, PROTO_1);
				set_protocol(cconfs, PROTO_1);
				logp("Client is burp-%s - using protocol=%d\n",
					peer_version, PROTO_1);
			}
			else
			{
				// Client is burp-2.x.x, use protocol2.
				// This will probably never be reached because
				// the negotiation will take care of it.
				set_protocol(confs, PROTO_2);
				set_protocol(cconfs, PROTO_2);
				logp("Client is burp-%s - using protocol=%d\n",
					peer_version, PROTO_2);
			}
			break;
		case PROTO_1:
			// It is OK for the client to be burp1 and for the
			// server to be forced to protocol1.
			break;
		case PROTO_2:
			if(vers.cli>=vers.burp2) break;
			logp("protocol=%d is set server side, "
			  "but client is burp version %s\n",
			  peer_version);
			goto error;
	}

	if(get_protocol(cconfs)==PROTO_1)
	{
		if(get_e_rshash(cconfs[OPT_RSHASH])==RSHASH_UNSET)
		{
			set_e_rshash(confs[OPT_RSHASH], RSHASH_MD4);
			set_e_rshash(cconfs[OPT_RSHASH], RSHASH_MD4);
		}
	}

	return 0;
error:
	return -1;
}
コード例 #19
0
ファイル: extra_comms.c プロジェクト: vanElden/burp
static int extra_comms_read(struct async *as,
	struct vers *vers, int *srestore,
	char **incexc, struct conf **globalcs, struct conf **cconfs)
{
	int ret=-1;
	struct asfd *asfd;
	struct iobuf *rbuf;
	asfd=as->asfd;
	rbuf=asfd->rbuf;

	while(1)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd)) goto end;

		if(rbuf->cmd!=CMD_GEN)
		{
			iobuf_log_unexpected(rbuf, __func__);
			goto end;
		}

		if(!strcmp(rbuf->buf, "extra_comms_end"))
		{
			if(asfd->write_str(asfd, CMD_GEN, "extra_comms_end ok"))
				goto end;
			break;
		}
		else if(!strncmp_w(rbuf->buf, "autoupgrade:"))
		{
			char *os=NULL;
			const char *autoupgrade_dir=
				get_string(globalcs[OPT_AUTOUPGRADE_DIR]);
			os=rbuf->buf+strlen("autoupgrade:");
			iobuf_free_content(rbuf);
			if(os && *os && autoupgrade_server(as, vers->ser,
				vers->cli, os, get_cntr(globalcs),
				autoupgrade_dir))
					goto end;
		}
		else if(!strcmp(rbuf->buf, "srestore ok"))
		{
			iobuf_free_content(rbuf);
			// Client can accept the restore.
			// Load the restore config, then send it.
			*srestore=1;
			if(conf_parse_incexcs_path(cconfs,
				get_string(cconfs[OPT_RESTORE_PATH]))
			  || incexc_send_server_restore(asfd, cconfs))
				goto end;
			// Do not unlink it here - wait until
			// the client says that it wants to do the
			// restore.
			// Also need to leave it around if the
			// restore is to an alternative client, so
			// that the code below that reloads the config
			// can read it again.
			//unlink(get_string(cconfs[OPT_RESTORE_PATH]));
		}
		else if(!strcmp(rbuf->buf, "srestore not ok"))
		{
			const char *restore_path=get_string(
				cconfs[OPT_RESTORE_PATH]);
			// Client will not accept the restore.
			unlink(restore_path);
			if(set_string(cconfs[OPT_RESTORE_PATH], NULL))
				goto end;
			logp("Client not accepting server initiated restore.\n");
		}
		else if(!strcmp(rbuf->buf, "sincexc ok"))
		{
			// Client can accept incexc conf from the
			// server.
			iobuf_free_content(rbuf);
			if(incexc_send_server(asfd, cconfs)) goto end;
		}
		else if(!strcmp(rbuf->buf, "incexc"))
		{
			// Client is telling server its incexc
			// configuration so that it can better decide
			// what to do on resume.
			iobuf_free_content(rbuf);
			if(incexc_recv_server(asfd, incexc, globalcs)) goto end;
			if(*incexc)
			{
				char *tmp=NULL;
				char comp[32]="";
				snprintf(comp, sizeof(comp),
					"compression = %d\n",
					get_int(cconfs[OPT_COMPRESSION]));
				if(!(tmp=prepend(*incexc, comp)))
					goto end;
				free_w(incexc);
				*incexc=tmp;
			}
		}
		else if(!strcmp(rbuf->buf, "countersok"))
		{
			// Client can accept counters on
			// resume/verify/restore.
			logp("Client supports being sent counters.\n");
			set_int(cconfs[OPT_SEND_CLIENT_CNTR], 1);
		}
		else if(!strncmp_w(rbuf->buf, "uname=")
		  && strlen(rbuf->buf)>strlen("uname="))
		{
			char *uname=rbuf->buf+strlen("uname=");
			if(!strncasecmp("Windows", uname, strlen("Windows")))
				set_int(cconfs[OPT_CLIENT_IS_WINDOWS], 1);
		}
		else if(!strncmp_w(rbuf->buf, "orig_client=")
		  && strlen(rbuf->buf)>strlen("orig_client="))
		{
			if(conf_switch_to_orig_client(globalcs, cconfs,
				rbuf->buf+strlen("orig_client=")))
					goto end;
			// If this started out as a server-initiated
			// restore, need to load the restore file
			// again.
			if(*srestore)
			{
				if(conf_parse_incexcs_path(cconfs,
					get_string(cconfs[OPT_RESTORE_PATH])))
						goto end;
			}
			if(asfd->write_str(asfd, CMD_GEN, "orig_client ok"))
				goto end;
		}
		else if(!strncmp_w(rbuf->buf, "restore_spool="))
		{
			// Client supports temporary spool directory
			// for restores.
			if(set_string(cconfs[OPT_RESTORE_SPOOL],
				rbuf->buf+strlen("restore_spool=")))
					goto end;
		}
		else if(!strncmp_w(rbuf->buf, "protocol="))
		{
			char msg[128]="";
			// Client wants to set protocol.
			enum protocol protocol=get_protocol(cconfs);
			if(protocol!=PROTO_AUTO)
			{
				snprintf(msg, sizeof(msg), "Client is trying to use protocol=%s but server is set to protocol=%d\n", rbuf->buf, protocol);
				log_and_send_oom(asfd, __func__);
				goto end;
			}
			else if(!strcmp(rbuf->buf+strlen("protocol="), "1"))
			{
				set_protocol(cconfs, PROTO_1);
				set_protocol(globalcs, PROTO_1);
			}
			else if(!strcmp(rbuf->buf+strlen("protocol="), "2"))
			{
				set_protocol(cconfs, PROTO_2);
				set_protocol(globalcs, PROTO_2);
			}
			else
			{
				snprintf(msg, sizeof(msg), "Client is trying to use protocol=%s, which is unknown\n", rbuf->buf);
				log_and_send_oom(asfd, __func__);
				goto end;
			}
			logp("Client has set protocol=%d\n",
				(int)get_protocol(cconfs));
		}
		else if(!strncmp_w(rbuf->buf, "rshash=blake2"))
		{
#ifdef RS_DEFAULT_STRONG_LEN
			logp("Client is trying to use librsync hash blake2, but server does not support it.\n");
			goto end;
#else
			set_e_rshash(cconfs[OPT_RSHASH], RSHASH_BLAKE2);
			set_e_rshash(globalcs[OPT_RSHASH], RSHASH_BLAKE2);
#endif
		}
		else if(!strncmp_w(rbuf->buf, "msg"))
		{
			set_int(cconfs[OPT_MESSAGE], 1);
			set_int(globalcs[OPT_MESSAGE], 1);
		}
		else
		{
			iobuf_log_unexpected(rbuf, __func__);
			goto end;
		}
	}

	ret=0;
end:
	iobuf_free_content(rbuf);
	return ret;
}
コード例 #20
0
ファイル: display.cpp プロジェクト: barry-scott/BarrysEmacs
void SystemExpressionRepresentationTermProtocolMode::assign_value( ExpressionRepresentation *new_value )
{
    SystemExpressionRepresentationIntBoolean::assign_value( new_value );

    set_protocol( exp_int );
}
コード例 #21
0
ファイル: test_restore.c プロジェクト: rubenk/burp
static void run_test(int expected_ret,
	enum protocol protocol,
	int manio_entries,
	int blocks_per_file,
	void setup_asfds_callback(struct asfd *asfd, struct slist *slist))
{
        struct async *as;
        struct asfd *asfd;
        struct sdirs *sdirs;
        struct conf **confs;
        struct slist *slist=NULL;
	char *dir_for_notify=NULL;
        prng_init(0);
        base64_init();
        hexmap_init();
        setup(protocol, &as, &sdirs, &confs);
	set_string(confs[OPT_BACKUP], "1");
	set_protocol(confs, protocol);
        asfd=asfd_mock_setup(&reads, &writes);
	as->asfd_add(as, asfd);
	as->read_write=async_rw_simple;
	as->read_quick=async_rw_simple;
	asfd->as=as;

	build_storage_dirs(sdirs, sd1, ARR_LEN(sd1));
	if(manio_entries)
	{
		struct sbuf *s;
		if(protocol==PROTO_2)
			slist=build_manifest_with_data_files(sdirs->cmanifest,
				sdirs->data, manio_entries, blocks_per_file);
		else
		{
			slist=build_manifest(sdirs->cmanifest,
				protocol, manio_entries, 0 /*phase*/);
			for(s=slist->head; s; s=s->next)
			{
				char path[256];
				if(!sbuf_is_filedata(s))
					continue;
				snprintf(path, sizeof(path), "%s/%s%s",
					sdirs->currentdata,
					TREE_DIR, s->path.buf);
				build_file(path, "data");
			}
		}
	}
	setup_asfds_callback(asfd, slist);

	fail_unless(do_restore_server(
		asfd,
		sdirs,
		ACTION_RESTORE,
		0, // srestore
		&dir_for_notify,
		confs
	)==expected_ret);

	if(!expected_ret)
	{
		// FIX THIS: Should check for the presence and correctness of
		// changed and unchanged manios.
	}
	slist_free(&slist);
	free_w(&dir_for_notify);
	tear_down(&as, &asfd, &sdirs, &confs);
}