Ejemplo n.º 1
0
void cgc_send_message(message_t *m)
{
    char buf[100];
    cgc_sprintf(buf, "%08d - %s\n", m->id, m->topic);
    send_string(buf);
    send_string(m->body);
}
Ejemplo n.º 2
0
void set_event(uint8_t event_number)
{
	uint8_t which_pin = events[event_number].pin;
	
	actual_events[which_pin] = event_number;
	
	switch(which_pin)
	{
		case EXP0_PC2:
		case EXP1_PD4:
		case EXP2_PD7:
		case EXP3_PB0:
		set_pin(which_pin, events[event_number].pin_state);
		break;
		
		case PWM0_PD6:
		case PWM1_PD5:
		// not implemented yet case PWM2_PB1:
		// not implemented yet case PWM3_PD3:
		run_pwm(which_pin, &events[event_number]);
		break;
		
		default:break;
	}
	
	int32_t time = current_time();
	
	// event_time
	char formatted_date[30];
	timeToString(time, formatted_date);
	send_string(formatted_date);
	send_string(" ");
	
	print_event(event_number);
}
OPENVPN_EXPORT int
openvpn_plugin_func_v1 (openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[])
{
  struct auth_pam_context *context = (struct auth_pam_context *) handle;

  if (type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY && context->foreground_fd >= 0)
    {
      /* get username/password from envp string array */
      const char *username = get_env ("username", envp);
      const char *password = get_env ("password", envp);

      if (username && strlen (username) > 0 && password)
	{
	  if (send_control (context->foreground_fd, COMMAND_VERIFY) == -1
	      || send_string (context->foreground_fd, username) == -1
	      || send_string (context->foreground_fd, password) == -1)
	    {
	      fprintf (stderr, "AUTH-PAM: Error sending auth info to background process\n");
	    }
	  else
	    {
	      const int status = recv_control (context->foreground_fd);
	      if (status == RESPONSE_VERIFY_SUCCEEDED)
		return OPENVPN_PLUGIN_FUNC_SUCCESS;
	      if (status == -1)
		fprintf (stderr, "AUTH-PAM: Error receiving auth confirmation from background process\n");
	    }
	}
    }
  return OPENVPN_PLUGIN_FUNC_ERROR;
}
Ejemplo n.º 4
0
atlsci_led_ret_t atlsci_led(int sensor_type, int action)
{
    char * led_on =    "L,1";	//Turn on LEDs
    char * led_off =   "L,0"; 	//Turn off LEDs
    char * led_query = "L,?"; 	//Query LEDs
    uint8_t rx_buffer[STRING_SIZE] = {0};

    int ret = set_sensor_address(i2c_context, sensor_type);

    switch (action)
    {
        case ATLSCI_LED_ON:    ret = send_string(i2c_context, led_on); break;
        case ATLSCI_LED_OFF:   ret = send_string(i2c_context, led_off); break;
        case ATLSCI_LED_QUERY: ret = send_string(i2c_context, led_query); break;
        default:               ret = -1; break;
    }

    if (ret == MRAA_SUCCESS)
    {
        ret = mraa_i2c_read(i2c_context, rx_buffer, sizeof(rx_buffer));
        if(action == ATLSCI_LED_QUERY)
			printf("%s\n", rx_buffer);
        return parse_atlsci_led(rx_buffer, action);
    }

    log_mraa_response("atlsci_led()", ret);

    return parse_atlsci_led(rx_buffer, action);

}
int main(void)
{
  /* Setup IO */
  DDRD   = (1 << DDD5) | (1 << DDD6) | (1 << DDD7);
  DDRB   = (1 << DDB0);
  PORTC  = (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5);
  PCMSK1 = (1 << PCINT10) | (1 << PCINT11) | (1 << PCINT12) | (1 << PCINT13);
  UBRR0H = 0;
  UBRR0L = 103;
  UCSR0B = (1 << TXEN0);

  send_string("Hello\n");

  /* Duplicate */
  for (;;)
  {
    send_string("Cloning\n");
    clone(C, 2, B, 0);
    clone(C, 3, D, 7);
    clone(C, 4, D, 6);
    clone(C, 5, D, 5);

    send_string("Sleeping\n");
    PCICR |= (1 << PCIE1);
    intsleep(PWR_DOWN);
    PCICR &= ~(1 << PCIE1);
    send_string("Woke up\n");
  }
}
Ejemplo n.º 6
0
int main(void)
{
   int i;

/* Init the Display */
   lcd_init(2);
/* Clear the screen */
   lcd_putc('\f');
/* Send the message */
   send_string(5, INITMESSAGE);

   while (1)
   {
   /* Display on the first line after button press */
      while(lcd.button == 1)
      { }
      lcd_putc('\f');
      send_string(1000, MESSAGE1);

      while(lcd.button == 1)
      { }
      lcd_putc('\f');
   /* New line */
      lcd_putc('\n');
      send_string(5, MESSAGE2);
   /* Add delay for button debouncing */
      delay_ms(500);
   }

   return 0;
}
Ejemplo n.º 7
0
/*
 * Temperature compensation is only enable for pH, DO, and Conductivity sensor.
 * ORP does not have this feature. The value that it takes is expressed in float value nn.n
 */
atlsci_temp_comp_ret_t atlsci_temp_comp(int sensor_type, atlsci_temp_comp_param param, float value)
{
	atlsci_temp_comp_ret_t ret;
	uint8_t rx_buffer[STRING_SIZE] = {0};
	char cal_temp[TEMP_COMP_SIZE] = "T,";
	int success = set_sensor_address(i2c_context, sensor_type);
	char *pt_cal = cal_temp;

	switch(param)
	{
		case SET_TEMPERATURE:		sprintf(pt_cal + TEMP_COMP_INDEX, "%.1f", value);
						success = send_string(i2c_context, cal_temp); break;
						
		case QUERY_TEMPERATURE:		success = send_string (i2c_context, cal_query); break;
		
		default:			return atlsci_temp_comp_fail(param);
	}
    if (success == MRAA_SUCCESS)
    {
        success = mraa_i2c_read(i2c_context, rx_buffer, sizeof(rx_buffer));
    	if(param == QUERY_TEMPERATURE)
    		printf("%s\n", rx_buffer);
        //First bit of rx_buffer will be '1' if write is successful
    	ret.success = (int)rx_buffer[0];
    }
    else
    {
    	log_mraa_response("atlsci_temp_comp()", success);
    	ret.success = -1;
    }
	return ret;
}
Ejemplo n.º 8
0
int main(void)
{
	struct DataPackage* pkg;
	uint8_t i;
	uint8_t buffer[20];
	
	rfm_init(RX_MODE);
	init_uart();
	
	DDRD &= ~(1<<PD2);
	PORTD |= 1<<PD2;
	
    while(1)
    {
		pkg = receivePackageBlocking();
		
		if(pkg->pkgSize > 0)
		{
			send_string("RICHTIG\r\n");
/*			for(i=0; i<pkg->pkgSize-DATA_PKG_HEAD_SIZE; i++)
			{
				itoa(pkg->pkgData[i], (char*)buffer, 16);
				send_string(buffer);
				send_string("\r\n");
			}*/
		}
		else
		{
			send_string("FALSCH\r\n");
		}
		
		deleteDataPackage(pkg);
    }
}
Ejemplo n.º 9
0
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
lcd_init();
send_string("Manpreet Singh");
send_command(0xC0);
send_string("Minhas");
while(1){}
}
Ejemplo n.º 10
0
int main (int argc, char *argv[])
{
    optarg = (char *)malloc(100*sizeof(char));

    //fill optarg with the path to the serial transmitter
    find_serial_transmitter();

    FILE *log_file;
    char buf[1000];
    char *str_array[140]={"\0"};
    int i=0;

    //Open the FM stations log file that will become the device database
    log_file = fopen("log.txt","r");
    if (!log_file){
        printf("ERROR: Could not open FM Stations log file for reading.\n");
        return -1;
    }

    //create a connection over the virtual serial port
    open_port();

    //send the start sequence
    perror("START SEQUENCE:\n");
    send_string("$$$");
    printf("\n\n");

    //wait a while to make sure the device has detected the start sequence and is ready for data
    usleep(5000000);

    //parse the log file line by line
    while (fgets(buf,1000, log_file)!=NULL) 
    {
        //keep track of each line
        str_array[i] = buf;
        strip_newline( str_array[i], 210);

        //prepare, parse, and transmit the data within each line
        parse_line(line_prep(str_array[i]));
        i++;
    }

    //close the log file
    fclose(log_file);

    //make sure the device has had enough time to write all the data before sending end sequence
    usleep(4000000);

    //send the end sequence
    printf("END SEQUENCE:\n");
    send_string("^^^");
    printf("\n\n");

    //terminate the virtual serial port connection
    serialport_close(fd);
    return 0;
}
Ejemplo n.º 11
0
int parse_line(char * in_line){
    int i = 0;
    int initial_length = strlen(in_line);
    printf("chars parsed: %d\n", initial_length);
    char * token = strtok_single(in_line, " ");
    /* walk through other tokens */
    //The first call you use a char array which has the elements you want parsed.
    //The second time you call it you pass it NULL as the first parameter to tell function 
    //to resume from the last spot in the string. Once the first call is made your char 
    //array receives the parsed string. If you don't put NULL you would lose your place 
    //and effectivly the last part of your string.
    if (initial_length > 10){
        if (initial_length >= 200){
            //grid population
            send_byte((uint8_t)*(token));
            printf("%s ", token);
            while(token){

                i++;
                token = strtok_single(NULL, " ");
                if (i < 100) {
                    send_byte((uint8_t)*(token));
                    printf("%s ",token);
                }

                usleep(200000);
            }
            printf("\n");
        }
        else{
            //Station line
            //printf("callsign:%s\n", token);
            send_string(token);
            if (strlen(token) < 8)
            {
                int k=0;
                for (k=0; k< 8-strlen(token); k++)
                {
                    send_string(" ");
                }
            }
            while(token){
                i++;
                token = strtok_single(NULL, " ");
                if (i < 6) send_float(token); 
                //if (i < 6) printf("float:%s ",token); 
                usleep(200000);
            }       
        }  
    }
    else{
        send_float(token);
        //printf("num_stations: %s\n",token);
    }
    printf("\n");
    return 0;
}
Ejemplo n.º 12
0
/*
  handle_response -- accept a response from stdin (the gnu process) and pass the
                     information on to the relevant client.
*/
static void
handle_response (void)
{
  char buf[GSERV_BUFSZ+1];
  int offset=0;
  int s;
  int len = 0;
  int result_len;

  /* read in "n/m:" (n=client fd, m=message length) */
  while (offset < GSERV_BUFSZ &&
	 ((len = read(0,buf+offset,1)) > 0) &&
	 buf[offset] != ':') {
    offset += len;
  }

  if (len < 0) {
    perror(progname);
    fprintf(stderr,"%s: unable to read\n",progname);
    exit(1);
  }

  /* parse the response from emacs, getting client fd & result length */
  buf[offset] = '\0';
  sscanf(buf,"%d/%d", &s, &result_len);

  while (result_len > 0) {
    if ((len = read(0,buf,min2(result_len,GSERV_BUFSZ))) < 0) {
      perror(progname);
      fprintf(stderr,"%s: unable to read\n",progname);
      exit(1);
    }
    buf[len] = '\0';
    send_string(s,buf);
    result_len -= len;
  }

  /* eat the newline */
  while ((len = read(0,buf,1)) == 0)
    ;
  if (len < 0)
    {
      perror(progname);
      fprintf(stderr,"%s: unable to read\n",progname);
      exit(1);
    }
  if (buf[0] != '\n')
    {
      fprintf(stderr,"%s: garbage after result\n",progname);
      exit(1);
    }
  /* send the newline */
  buf[1] = '\0';
  send_string(s,buf);
  close(s);

} /* handle_response */
Ejemplo n.º 13
0
static void docmd(char **cmd)
{
    int i;

    if (cmd[0] == NULL) {
	help();
	return;
    }
    if (cmd[1] && cmd[2]) {
	printf("%s\n", lang_toolong);
	help();
	return;
    }

    if (strcmp(cmd[0], lang_look[0]) == 0
	    || strcmp(cmd[0], lang_look[1]) == 0) {
	send_string("descr\r\n");
	return;
    }
    if (strcmp(cmd[0], lang_inv[0]) == 0
	    || strcmp(cmd[0], lang_inv[1]) == 0) {
	send_string("inv\r\n");
	return;
    }
    if (strcmp(cmd[0], lang_get) == 0) {
	call_with_arg(get, cmd[1], lang_getdrop_explain, lang_get);
	return;
    }
    if (strcmp(cmd[0], lang_drop) == 0) {
	call_with_arg(drop, cmd[1], lang_getdrop_explain, lang_drop);
	return;
    }
    if (strcmp(cmd[0], lang_poke) == 0) {
	if (cmd[1] && cmd[1][0] == '-')
	    cmd[1]++;
	call_with_arg(poke, cmd[1], lang_poke_explain, lang_poke);
	return;
    }

    for (i = 0; i < 6; i++) {
	if (strcmp(cmd[0], lang_directions[i][0]) == 0
		|| strcmp(cmd[0], lang_directions[i][1]) == 0) {
	    go(i);
	    return;
	}
    }

    /* accept standard command "l" in any language, unless it is assigned
     * another meaning */
    if (strcmp(cmd[0], "l") == 0) {
	send_string("descr\r\n");
	return;
    }

    printf("%s\n", lang_huh);
    help();
}
Ejemplo n.º 14
0
void run_task(uint8_t *Task)
{
	switch(Task[2])
	{
		case '0':
		send_string("boot");
		break;
		case '1':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		readFlashPage(page_address, 128);
		send_buff(gBuffer, 128);
		Task[2] = 0;
		break;
		case '2':
		Task[2] = 0;
		break;
		case '3':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		for (uint16_t i = 0; i < SPM_PAGESIZE; i++)
		gBuffer[i] = data_buffer[i + 16];
		writeFlashPage(page_address,SPM_PAGESIZE);
		send_string("page done");
		Task[2] = 0;
		break;
		case '4':
		eraseFlash();
		send_string("erase ok");
		Task[2] = 0;
		break;
		case '5':
		Task[2] = 0;
		break;
		case '6':
		fill_page();
		send_buff(gBuffer, 256);
		Task[2] = 0;
		break;
		case '7':
		blink_led();
		Task[2] = 0;
		break;
		case '8':
		MCUCR |= 1<<IVCE;
		MCUCR = 0<<IVSEL;
		send_string("jump ok");
		jump_to_app();		// Jump to application sector
		Task[2] = 0;
		break;
		default:
		Task[2] = 0;
	}
}
	Service* service_request (string service_name) {
		int socket;
		Service_description* s_description = NULL;
		if (service_name == "" ||
			!socket_initialization_client (&socket, SR_address, SR_port)) return NULL;
		
		if (send_string (socket, "get_service") &&
			receive_int (socket) != -1 &&
			send_string (socket, service_name)) s_description = receive_service_description (socket);
		
		close(socket);
		return (s_description == NULL) ? NULL : new Service (s_description);
	}
Ejemplo n.º 16
0
int main()
{
    type2_vals t2v;
    unsigned char* ScreenBuf[MAX_LINES];
    unsigned LineCnt;

#ifndef DEBUG
    type2_negotiate(&t2v);
#else
    (void)t2v;
#endif

    transmit_all(STDOUT, "l23k", 4);

    send_string(STDERR, "GOING\n");
    LineCnt = ReadScreen(ScreenBuf);
    for (unsigned Index = 0; Index < 64; ++Index)
    {
        send_string(STDERR, "LOOP\n");
        send_string(STDOUT, "0\n");
        LineCnt = ReadScreen(ScreenBuf);
    }

    send_string(STDOUT, "shuf\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "4986\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "4\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "dupr\n");
    LineCnt = ReadScreen(ScreenBuf);


    char* s = (char *)ScreenBuf[LineCnt - 2];
    s = strchr(s, ':');
    s += 2;

    int m = strtol(s, NULL, 10);
    unsigned char secret[4];
    cgc_memcpy(secret, (void *)&m, 4);

    secret[0] ^= 0x14;
    secret[1] ^= 0x15;
    secret[2] ^= 0x16;
    secret[3] ^= 0x17;

    send_string(STDERR, (char *)s);
    send_string(STDERR, "----->\n");
    type2_submit((unsigned char *)secret, 4);
    send_string(STDOUT, "quit\n");
}
Ejemplo n.º 17
0
static atlsci_cal_ret_t atlsci_cal_ph(atlsci_cal_param_t param, float value)
{
    atlsci_cal_ret_t ret;
	int success = set_sensor_address(i2c_context, ATLSCI_PH);
    uint8_t rx_buffer[STRING_SIZE] = {0};
    char cal_low[PH_CAL_LOW_SIZE] = "Cal,low,";
    char cal_mid[PH_CAL_MID_SIZE] = "Cal,mid,";
    char cal_high[PH_CAL_HIGH_SIZE] = "Cal,high";
    char *pt_cal = NULL;

    switch(param.cal_ph)
    {
    	case PH_CALIBRATION_CLEAR:		success = send_string(i2c_context, cal_clear); break;

    	case PH_CALIBRATION_QUERY:		success = send_string(i2c_context, cal_query); break;

    	case PH_LOW_CALIBRATION_POINT:  	pt_cal = cal_low;
    						sprintf(pt_cal + PH_INDEX_LOW, "%.2f", value);
    						success = send_string(i2c_context, cal_low); break;

    	case PH_MID_CALIBRATION_POINT:		pt_cal = cal_mid;
    						sprintf((pt_cal + PH_INDEX_MID), "%.2f", value);
    						success = send_string(i2c_context, cal_mid); break;

    	case PH_HIGH_CALIBRATION_POINT: 	pt_cal = cal_high;
    						sprintf((pt_cal + PH_INDEX_HIGH), "%.2f", value);
    						success = send_string(i2c_context, cal_high); break;
        
        default:         			return atlsci_cal_fail(param);
    }

    if (success == MRAA_SUCCESS)
    {
        success = mraa_i2c_read(i2c_context, rx_buffer, sizeof(rx_buffer));
    	if(param.cal_ph == PH_CALIBRATION_QUERY)
        {
            ret.query = malloc(QUERY_SIZE);
            //ret.query = rx_buffer;
            uint8_t * rx_ptr = rx_buffer; rx_ptr++;
            sprintf(ret.query, "%s", rx_ptr);
        }
        //First bit of rx_buffer will be '1' if write is successful
    	ret.success = (int)rx_buffer[0];
    }
    else
    {
    	log_mraa_response("atlsci_cal_ph()", success);
    	ret.success = -1;
    }
	return ret;
}
Ejemplo n.º 18
0
/**
 * Checks each of the cliff sensors and returns 1 if the sensor is tripped and prints to putty which sensor was tripped.
 * @param sensor_status - the robot 
 **/
int check_cliff(oi_t *sensor_status)
{
	
	int stop = 0;
		
    oi_update(sensor_status);

	if(old_cl != sensor_status->cliff_left)
	{
		old_cl = sensor_status->cliff_left;
		if(old_cl == 1)
		{
			oi_set_wheels(0, 0);
			stop = 1;
			send_string("Cliff Left Detected!");
		}
	}
	else if(old_cfl != sensor_status->cliff_frontleft)
	{
		old_cfl = sensor_status->cliff_frontleft;
		if(old_cfl == 1)
		{
			oi_set_wheels(0, 0);
			stop = 1;
			send_string("Cliff Front Left Detected!");
		}
	}
	else if(old_cfr != sensor_status->cliff_frontright)
	{
		old_cfr = sensor_status->cliff_frontright;
		if(old_cfr == 1)
		{
			oi_set_wheels(0, 0);
			stop = 1;
			send_string("Cliff Front Right Detected!");
		}
	}
	else if(old_cr != sensor_status->cliff_right)
	{
		old_cr = sensor_status->cliff_right;
		if(old_cr == 1)
		{
			oi_set_wheels(0, 0);
			stop = 1;
			send_string("Cliff Right Detected!");
		}
	}
	return stop;
}
	bool unregister_service (Service_description* s_description) {
		int socket;
		bool result = false;
		if (s_description == NULL ||
			!socket_initialization_client (&socket, SR_address, SR_port)) return false;
				
		if (send_string (socket, "remove_service") &&
			receive_int (socket) != -1 &&
			send_string (socket, s_description->name) &&
			send_string (socket, s_description->address) &&
			send_string (socket, s_description->port)) result = true;
		
		close(socket);
		return result;
	}
Ejemplo n.º 20
0
void print_events()
{
	char ts[30];
	
	send_string("Number of events: ");
	sprintf(ts, "%d", events_count);
	send_string(ts);
	send_enter();
	
	for (uint8_t i = 0; i < events_count; i++)
	{
		print_event(i);
	}
	
}
	bool register_service_provider (string address, string port) {
		int socket;
		bool result = false;
		if (!check_address (address) ||
			atoi(port.c_str()) < 1023 ||  atoi(port.c_str()) > 65535 ||
			!socket_initialization_client (&socket, SR_address, SR_port)) return false;
		
		if (send_string (socket, "add_service_provider") &&
			receive_int (socket) != -1 &&
			send_string (socket, address) &&
			send_string (socket, port)) result = true;
		
		close(socket);
		return result;
	}
Ejemplo n.º 22
0
void cgc_do_read(const char *str)
{
    if (str[1] != ' ')
    {
        send_string("Missing required argument.\n");
        return;
    }

    int id = cgc_strtol(&str[2], NULL, 10);
    message_t *m = cgc_find_message(id);
    if (m)
        cgc_send_message(m);
    else
        send_string("Message ID not found.\n");
}
Ejemplo n.º 23
0
static int
do_ftp_auth (const char *username, const char *password)
{
    struct sockaddr_in local_address;
    unsigned long inaddr;
    int my_socket;
    char answer[4];

    memset ((char *) &local_address, 0, sizeof (local_address));

    local_address.sin_family = AF_INET;
    /* FIXME: extract the ftp port with the proper function */
    local_address.sin_port = htons (21);

    /*  Convert localhost to usable format */
    if ((inaddr = inet_addr ("127.0.0.1")) != INADDR_NONE)
	memcpy ((char *) &local_address.sin_addr, (char *) &inaddr,
		sizeof (inaddr));

    if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
	if (!isDaemon)
	    fprintf (stderr, "do_auth: can't create socket\n");
	return 0;
    }
    if (connect
	(my_socket, (struct sockaddr *) &local_address,
	 sizeof (local_address)) < 0) {
	fprintf (stderr,
		 "do_auth: can't connect to ftp daemon for authentication\n");
	close (my_socket);
	return 0;
    }
    send_string (my_socket, "user ");
    send_string (my_socket, username);
    send_string (my_socket, "\r\n");
    if (!ftp_answer (my_socket, "331")) {
	send_string (my_socket, "quit\r\n");
	close (my_socket);
	return 0;
    }
    next_line (my_socket);	/* Eat all the line */
    send_string (my_socket, "pass ");
    send_string (my_socket, password);
    send_string (my_socket, "\r\n");
    socket_read_block (my_socket, answer, 3);
    answer[3] = 0;
    send_string (my_socket, "\r\n");
    send_string (my_socket, "quit\r\n");
    close (my_socket);
    if (strcmp (answer, "230") == 0)
	return 1;
    return 0;
}
Ejemplo n.º 24
0
void send_int(char *name, int integer) /* includefile */
{
  send_string(name);
  if (swapout) swap_int(&integer);
  fwrite(&integer,sizeof(int),1,output);
  /*fprintf(stderr,"%d\n",integer);*/
}
Ejemplo n.º 25
0
/* adds bouquet at the end of the bouquetlist  */
void CZapitClient::addBouquet(const char * const name)
{
	if (send(CZapitMessages::CMD_BQ_ADD_BOUQUET))
		send_string(name);

	close_connection();
}
Ejemplo n.º 26
0
void send_user(connection_t *connection) {
    char cmdstr[DEFBUFFSIZE];
    memset(cmdstr, '\0', sizeof cmdstr);
    snprintf(cmdstr, DEFBUFFSIZE, "USER %s %s %s :%s\r\n", connection->config->name, 
                                  "hostname", "servername", connection->config->realname);
    send_string(connection, cmdstr);
}
Ejemplo n.º 27
0
void send_long(char *name, long integer) /* includefile */
{
  send_string(name);
  if (swapout) swap_long(&integer);
  fwrite(&integer,sizeof(long),1,output);
  /*fprintf(stderr,"%ld\n",integer);*/
}
Ejemplo n.º 28
0
int			cmd_get(int sockfd, char *line, uint32_t cmd, t_param *param)
{
	t_command		command;
	char			*src;
	char			*dst;

	command.magic = MAGIC_CMD;
	command.command = cmd;
	if (!get_2_params(line, &src, &dst))
	{
		printf(INVALID_ARG_GET "\n");
		return (0);
	}
	if (!send_data(sockfd, &command, sizeof(t_command)))
	{
		param->to_deco = 1;
		printf(SEND_CMD_FAIL "\n");
		return (0);
	}
	if  (!send_string(sockfd, src, ft_strlen(src)))
	{
		printf(SEND_STRING_FAIL "\n");
		return (0);
	}
	if (!(get_response(sockfd, dst, param)))
		return (0);
	return (1);
}
Ejemplo n.º 29
0
void PJON::update() {
    for(uint8_t i = 0; i < MAX_PACKETS; i++) {
        if(packets[i].state != NULL)
            if(micros() - packets[i].registration > packets[i].timing + pow(packets[i].attempts, 2))
                packets[i].state = send_string(packets[i].device_id, packets[i].content, packets[i].length);

        if(packets[i].state == ACK) {
            if(!packets[i].timing)
                this->remove(i);
            else {
                packets[i].attempts = 0;
                packets[i].registration = micros();
                packets[i].state = TO_BE_SENT;
            }
        }
        if(packets[i].state == FAIL) {
            packets[i].attempts++;

            if(packets[i].attempts > MAX_ATTEMPTS) {
                this->_error(CONNECTION_LOST, packets[i].device_id);
                if(!packets[i].timing)
                    this->remove(i);
                else {
                    packets[i].attempts = 0;
                    packets[i].registration = micros();
                    packets[i].state = TO_BE_SENT;
                }
            }
        }
    }
}
Ejemplo n.º 30
0
/* Send a 407 Proxy Authenticate Required response. */
static int send_proxy_authenticate(struct fdinfo *fdn, int stale)
{
    char *buf = NULL;
    size_t size = 0, offset = 0;
    int n;

    strbuf_append_str(&buf, &size, &offset, "HTTP/1.0 407 Proxy Authentication Required\r\n");
    strbuf_append_str(&buf, &size, &offset, "Proxy-Authenticate: Basic realm=\"Ncat\"\r\n");
#if HAVE_HTTP_DIGEST
    {
        char *hdr;

        hdr = http_digest_proxy_authenticate("Ncat", stale);
        strbuf_sprintf(&buf, &size, &offset, "Proxy-Authenticate: %s\r\n", hdr);
        free(hdr);
    }
#endif
    strbuf_append_str(&buf, &size, &offset, "\r\n");

    if (o.debug > 1)
        logdebug("RESPONSE:\n%s", buf);

    n = send_string(fdn, buf);
    free(buf);

    return n;
}