Beispiel #1
0
int send_octets( struct rmt_socket_t *client, int msg_type, int msg_extra, char *fmt, uint64_t value)
{
	char *Buffer = (char *)octets2str(value);
	int ret = send_line( client, msg_type, msg_extra, fmt, Buffer);
	free(Buffer);
	return ret;
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_udpsend_process, ev, data)
{
  const char *next, *nextptr;
  struct shell_input *input;
  uint16_t port, local_port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&udpsend_command,
		     "udpsend <server> <port> [localport]: server as address", "");
    PROCESS_EXIT();
  }
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &nextptr);

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  udpconn = udp_new(&serveraddr, htons(port), NULL);
  
  if(next != nextptr) {
    local_port = shell_strtolong(nextptr, &nextptr);
    udp_bind(udpconn, htons(local_port));
  }
  running = 1;


  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      if(uip_newdata()) {
	newdata(uip_appdata, uip_datalen());
      }
#if 0
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&udpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Beispiel #3
0
static void RunMacro(Widget w, StdForm *sf, XmAnyCallbackStruct *cb)
{
    int n, m;
    string tmp;
    
    int MyLoop();
    void send_line();
    
    RunningMacro = 1;
    
    for (n=0; n<nMacros; n++) {
        m = Macros[n];
        sprintf(tmp, "Doing cmd: %s", MacroCmds[m].cmd);
        send_line(tmp);
        while (MyLoop(1));
        CallCmdFunction(&(MacroCmds[m].funcInfo));
        if (MacroError) {
            sprintf(tmp, "Error %d during macro cmd '%s'. Aborting...",
                    MacroError, MacroCmds[n].cmd);
            PostErrorDialog(w, tmp);
            MacroError = 0;
            break;
        }
        if (strlen(MacroWarning)) {
            sprintf(tmp, "Warning %s during macro cmd '%s'.",
                    MacroWarning, MacroCmds[n].cmd);
            PostWarningDialog(w, tmp);
            strcpy(MacroWarning, "");
        }
    }
    
    RunningMacro = 0;
}
Beispiel #4
0
int send_mac( struct rmt_socket_t *client, int msg_type, int msg_extra, char *fmt, uint8_t *value)
{
	char *Buffer = (char*)mac2str(value);
	int ret = send_line( client, msg_type, msg_extra, fmt, Buffer);
	free(Buffer);
	return ret;
}
Beispiel #5
0
void LCD_print(UArg food)
{

//Clear Screen
//clear_screen();

//set DDRAM address (line 1 0x00)
LCD_send(0,0x80);
//send line
send_line(buff1);

//set DDRAM address (line 2= 0x40)
LCD_send(0, 0xC0);
//send line
send_line(buff2);

}
Beispiel #6
0
int send_file (int sock, char *filename) {
    FILE         *fp;
    byte          current_byte;
    int           read_len;
    unsigned int  file_length;
    unsigned int  i;

    if (send_line(sock, filename, strlen(filename)) < 0) return -1;

    // Open the file to determine the number of bytes that
    // need to be sent
    fp = fopen(filename, "rb");
    if (!fp) {
        if (send_uint32(sock, 0) < 0) return -1;
        return -1;
    }

    fseek(fp, 0L, SEEK_END);
    file_length = ftell(fp);

#if DEBUG
    printf("Sending %s | %d bytes | ... ", filename, file_length);
    fflush(stdout);
#endif

    // Send the file size to the client
    if (send_uint32(sock, file_length) < 0) return -1;

    // Send each byte to the client starting from the start
    rewind(fp);
    for (i = 0; i < file_length; ++i) {
        read_len = fread(&current_byte, 1, 1, fp);
        if (read_len <= 0) {

            // send 0 to keep the client in sync
            if (send_byte(sock, 0) < 0) return -1;
            continue;
        }

#if DEBUG
        printf("\rSending %s | %d bytes | %d%%... ", filename, file_length,
                (int) (100 * floor((i + 1) / file_length)));
        fflush(stdout);
#endif

        if (send_byte(sock, current_byte) < 0) return -1;
    }

    // Close the file
    fclose(fp);

#if DEBUG
    printf("Done.\n");
#endif
    return 0;
}
Beispiel #7
0
static void search_done(position_t* pos, move_t move)
{
    //FIXME: enter critical section
    if (!ModeAnalyze && InGame && move != MOVE_NONE)
    {
        position_move(pos, move);
        position_print(pos, C_WHITE);
        send_line("move %s", move_format(move));
    }
}
Beispiel #8
0
/**
* Main - Run through the steps of configuring, greeting, getting a name, thanking,
* and then quitting
*/
int main(void) {
	char buff[BUFF_LENGTH];

	// Setup the hardware
	init_hardware();

	// Wait until the USB port is configured and ready to go
	draw_centred(17, "Waiting for");
	draw_centred(24, "computer...");
	show_screen();
	while (!usb_configured() || !usb_serial_get_control());

	// Prompt the user for their name, and wait until they enter it
	clear_screen();
	draw_centred(17, "Waiting for");
	draw_centred(24, "username...");
	show_screen();
	send_line("Hello!");
	send_line("Could you please tell me your name:");
	recv_line(buff, BUFF_LENGTH);
	usb_serial_putchar('\n');

	// Display their name on the Teensy and prompt them to exit
	char buff2[BUFF_LENGTH + 8];
	sprintf(buff2, "Thanks %s!", buff);
	clear_screen();
	draw_centred(21, buff2);
	show_screen();
	send_line("Press 'q' to exit...");
	while (usb_serial_getchar() != 'q');

	// Display the finished information
	clear_screen();
	draw_centred(21, "Goodbye!");
	show_screen();
	send_line("\r");
	send_line("Done! Goodbye!");
	while (1);

	// We'll never get here...
	return 0;
}
Beispiel #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_tcpsend_process, ev, data)
{
  char *next;
  const char *dummy; 
  struct shell_input *input;
  uint16_t port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&tcpsend_command,
		     "tcpsend <server> <port>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &dummy);
  
  running = 1;

  uiplib_ipaddrconv(server, &serveraddr);
  telnet_connect(&s, &serveraddr, port);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(&s, input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      telnet_app(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&tcpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Beispiel #10
0
		bool send_response( icap::Response * response, psocksxx::iosockstream * socket ) throw() {

			bool r_success = true;

			icap::ResponseHeader * header;

			// grab the response header
			header = response->header();

			// response status
			std::string line = header->protocol();
			line.append( " " );
			line.append( itoa( header->status() ) );
			line.append( " " );
			line.append( response_status( header->status() ) );

			r_success = send_line( line, socket );

			// response headers
			if ( r_success ) {
				r_success = send_headers( header, socket );
			}

			// response content (if there are any)
			if ( r_success ) {

				// req-hdr
				if ( response->payload().req_header.size() > 0 ) {
					send_data( response->payload().req_header, socket );
				}

				// red-body
				if ( response->payload().req_body.size() > 0 ) {
					send_chunked( response->payload().req_body, socket );
				}

				// res-hdr
				if ( response->payload().res_header.size() > 0 ) {
					send_data( response->payload().res_header, socket );
				}

				// res-body
				if ( response->payload().res_body.size() > 0 ) {
					send_chunked( response->payload().res_body, socket );
				}

			}

			// flush-out socket stream buffer
			socket->flush();

			return r_success;

		}
Beispiel #11
0
		bool send_chunked( const std::string &data, psocksxx::iosockstream * socket ) throw() {

			std::string chunked_data = "";
			unsigned int offset      = 0;
			int chunks               = 0;

			// calculate the number of chunks we need
			if ( data.size() > ICAP_BUFFER_SIZE ) {
				chunks = ( data.size() / ICAP_BUFFER_SIZE );
			}

			try {

				do {

					// prepare data for this chunk
					chunked_data = data.substr( offset, ICAP_BUFFER_SIZE );

					// sanity check
					if ( chunked_data.size() <= 0 ) {
						// we shouldn't get here
						break;
					}

					// update offset
					offset += chunked_data.size();

					// send chunk size
					if (! send_line( dectohex( chunked_data.size() ), socket ) ) {
						return false;
					}

					// send chunk
					if (! send_data( chunked_data, socket ) ) {
						return false;
					}

					chunks--;

				} while ( chunks > 0 );

				// end of chunk
				if (! send_data( "\r\n0\r\n\r\n", socket ) ) {
					return false;
				}

			} catch ( psocksxx::sockexception &e ) {
				// TODO: log errors ??
				return false;
			}

			return true;

		}
Beispiel #12
0
static void
send_header(FILE *fout, const char *line, size_t len)
{
	int	i;

	if (strncasecmp("To:", line, 3) != 0 &&
	    strncasecmp("Cc:", line, 3) != 0 &&
	    strncasecmp("Bcc:", line, 4) != 0 &&
	    strncasecmp("From:", line, 5) != 0) {
		send_line(fout, 0, "%.*s", (int)len, line);
		return;
	}
	if (len >= sizeof pstate.buf) {
		send_line(fout, 0, "%.*s", (int)len, line);
		return;
	}

	/* XXX
	 * To, Cc and Bcc may need rewrite, we can reuse the
	 * msg recipients field since former content has already
	 * been used at this point.
	 */
	memset(&pstate, 0, sizeof(pstate));
	memcpy(pstate.buf, line, len);
	pstate.buf[len] = 0;
	pstate.wpos = len - 1;
	msg.rcpts = NULL;
	msg.rcpt_cnt = 0;

	if (strncasecmp("From:", line, 5) == 0) {
		parse_addr_terminal(1);
		send_line(fout, 0, "%s\n", msg.from);
	}
	else {
		parse_addr_terminal(0);
		for (i = 0; i < msg.rcpt_cnt; ++i)
			if (*msg.rcpts[i] != '\0')
				send_line(fout, 0, "%s%s%s\n", i > 0 ? "\t" : "",
				    msg.rcpts[i], i < msg.rcpt_cnt - 1 ? "," : "");
	}
}
Beispiel #13
0
int helo_syntax(int fd, license_data_type *ld, char *buff)
{
	char *ptr;

	ptr = strstr(buff, message(MSG_HELO_CMD));

	if (ptr != buff || strlen(buff) == 7) {

		if (send_line(fd, message(MSG_BAD_SYNTAX), strlen(message(MSG_BAD_SYNTAX))) < 0) {
			return (-1);
		}

		return (1);

	} else {
        char *helo_ans = calloc(MAX_MSG_SIZE, sizeof(char));
		memset(ld -> ip, '\0', MAX_MSG_SIZE);

		memset(ld -> host, '\0', MAX_MSG_SIZE);

		strcat(ld -> ip, client_ip);

		ptr = strstr(buff, " ");

		strncat(ld -> host, ptr + 1, strlen(ptr + 1) - 2);

        strcat(helo_ans, message(MSG_CMD_OK));
		strcat(helo_ans, ld -> host);
		strcat(helo_ans, "\r\n");


		if (send_line(fd, helo_ans,  strlen(helo_ans)) < 0) {
            free(helo_ans);
			return (-1);
		}

		free(helo_ans);
	}

	return (NO_ERROR);
}
Beispiel #14
0
int get_ants(FDATA *fd)
{
    string buf;
    
    void send_line(), DRP2FD();
    
    DRP2FD(&OnScan, &XScan, fd);
    
    sprintf(buf, "POPS scan read successfully.");
    send_line(buf);
    
    return 0;
}
Beispiel #15
0
bool stratum_send_line(struct stratum_ctx *sctx, char *s)
{
	bool ret = false;

	if (opt_protocol)
		applog(LOG_DEBUG, "> %s", s);

	pthread_mutex_lock(&sctx->sock_lock);
	ret = send_line(sctx->sock, s);
	pthread_mutex_unlock(&sctx->sock_lock);

	return ret;
}
Beispiel #16
0
void WindowsOutpost::disconnect()
{
  if (sock) {
    // Send 'exit' command. This closes the socket and quits the program.
    send_line("exit");
#ifdef WIN32
    closesocket(sock);
#else
    close(sock);
#endif
  }
  sock = 0;
}
Beispiel #17
0
static bool
send_line_crlf (socket_descriptor_t sd,
		const char *src)
{
  bool ret;

  struct buffer buf = alloc_buf (strlen (src) + 3);
  ASSERT (buf_write (&buf, src, strlen (src)));
  ASSERT (buf_write (&buf, "\r\n", 3));
  ret = send_line (sd, BSTR (&buf));
  free_buf (&buf);
  return ret;
}
Beispiel #18
0
AVS_UNIT_TEST(http_close, chunked_request_error_in_first_chunk) {
    avs_http_t *client = avs_http_new(&AVS_HTTP_DEFAULT_BUFFER_SIZES);
    AVS_UNIT_ASSERT_NOT_NULL(client);
    avs_net_abstract_socket_t *socket = NULL;
    avs_stream_abstract_t *stream = NULL;
    successful_request(client, &socket, &stream);

    // second request
    const char *tmp_data =
            "POST / HTTP/1.1\r\n"
            "Host: example.com\r\n"
#ifdef WITH_AVS_HTTP_ZLIB
            "Accept-Encoding: gzip, deflate\r\n"
#endif
            "Expect: 100-continue\r\n"
            "Transfer-Encoding: chunked\r\n"
            "\r\n";
    avs_unit_mocksock_expect_output(socket, tmp_data, strlen(tmp_data));
    avs_unit_mocksock_input_fail(socket, -1);
    avs_unit_mocksock_expect_errno(socket, ETIMEDOUT);
    avs_unit_mocksock_output_fail(socket, -1);
    avs_unit_mocksock_expect_errno(socket, EPIPE);
    avs_unit_mocksock_expect_mid_close(socket);
    avs_unit_mocksock_expect_connect(socket, "example.com", "80");
    // second request retry
    avs_unit_mocksock_expect_output(socket, tmp_data, strlen(tmp_data));
    tmp_data =
            "HTTP/1.1 100 Continue\r\n"
            "\r\n";
    avs_unit_mocksock_input(socket, tmp_data, strlen(tmp_data));
    /* The text used in this test is 5119 bytes long.
     * This is to test writing more than buffer size, which is 4096. */
    tmp_data = MONTY_PYTHON_PER_LINE_REQUEST;
    avs_unit_mocksock_expect_output(socket, tmp_data, strlen(tmp_data));
    tmp_data =
            "HTTP/1.1 200 OK\r\n"
            "Transfer-Encoding: identity\r\n"
            "\r\n";
    avs_unit_mocksock_input(socket, tmp_data, strlen(tmp_data));
    tmp_data = MONTY_PYTHON_RAW;
    while (*tmp_data) {
        send_line(stream, &tmp_data);
    }
    AVS_UNIT_ASSERT_SUCCESS(avs_stream_finish_message(stream));
    avs_unit_mocksock_assert_io_clean(socket);
    avs_unit_mocksock_expect_shutdown(socket);
    AVS_UNIT_ASSERT_SUCCESS(avs_stream_cleanup(&stream));
    avs_http_free(client);
}
Beispiel #19
0
		bool send_headers( icap::Header * header, psocksxx::iosockstream * socket ) throw() {

			std::string line;
			icap::Header::headers_index_t i;
			icap::ResponseHeader::headers_t headers;

			// headers
			headers = header->headers();

			for ( i = headers.begin(); i != headers.end(); i++ ) {

				line = i->first;
				line.append( ": " );
				line.append( i->second );

				if (! send_line( line, socket ) ) {
					return false;
				}

			}

			// send encapsulated header
			line = "Encapsulated: ";
			line.append( header->encapsulated_header_str() );
			if (! send_line( line, socket ) ) {
				return false;
			}

			// end of header
			if (! send_data( "\r\n", socket ) ) {
				return false;
			}

			return true;

		}
Beispiel #20
0
void load_events()
{
	// initialize random number generator; it has to be done only once (after reset)
	srand(current_time());
	
	events_count = eeprom_read_byte(&events_count_ee);
	
	// initialize - for testing purposes
	/*
	if (events_count == 0)
	{
	send_string("add_default\r\n");
	add_default_events();
	}
	*/
	
	if (events_count == 0)
	{
		send_line("No events => MANUAL_MODE");
		event_mode = MANUAL_MODE;
		return;
	}
	
	// load events into ram
	eeprom_read_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// prepare
	prepare_actual_events();
	
	// print events
	print_events();
	
	// check current state of pins
	// if the device is power off, and later power on - it doesn't know what should be current state of pins
	
	int32_t time = current_time();
	send_string(" start time: ");
	
	char formatted_date[30];
	timeToString(time, formatted_date);
	send_string(formatted_date);
	send_enter();
	
	current_state();
}
Beispiel #21
0
int helo_syntax(int fd, char *buff)
{
	char *ptr;

	char *helo_ans = calloc(MAX_MSG_SIZE, sizeof(char));

	ptr = strstr(buff, message(MSG_HELO_CMD));

/*
	if (ptr != buff || strlen(buff) == 7) {

		if (send_line(fd, message(MSG_BAD_SYNTAX), strlen(message(MSG_BAD_SYNTAX))) < 0) {
			return (-1);
		}

		return (1);

	} else {
*/

/*  
      	char *helo_ans = calloc(MAX_MSG_SIZE, sizeof(char));
*/
		ptr = strstr(buff, " ");

		strcat(helo_ans, message(MSG_CMD_OK));
		strcat(helo_ans, client_ip);
		strcat(helo_ans, "/");
		strncat(helo_ans, ptr + 1, strlen(ptr + 1) - 2);
		strcat(helo_ans, "\r\n");

		if (send_line(fd, helo_ans, strlen(helo_ans)) < 0) {
			free(helo_ans);
			return (-1);
		}

		free(helo_ans);

/*
	}
*/
	return (NO_ERROR);
}
bool AmSmtpClient::send_command(const string& cmd)
{
  if( send_line(cmd) || get_response()){
    status = st_Error;
    return true;
  }

  if(res_code >= 200 && res_code < 400) {
    status = st_Ok;
  }
  else if(res_code < 600) {
    ERROR("smtp server answered: %i %s\n",res_code,res_msg.c_str());
    status = st_Error;
  }
  else {
    WARN("unknown response from smtp server: %i %s\n",res_code,res_msg.c_str());
    status = st_Unknown;
  }

  return (status != st_Ok);
}
Beispiel #23
0
static void info_pv(int score, move_t* pv)
{
    char str[1024];
    char* pos = str;
    move_t* move;
    int ms = TC_get_time();
    
    if (!ModePost)
        return;
        
    pos += sprintf(pos, "%2u  %7d  %5d  %8d  ", Depth,
                   score * 100 / PieceValue[P_PAWN][PHASE_MG], ms/10, stats_get(ST_NODE));

    for (move = pv; *move != MOVE_NONE; move++)
    {
        pos += sprintf(pos, " %s", move_format(*move));
    }
    if (ModePost)
        send_line(str);
    else
        log_line(str);
}
void take_connection(int sockfd)
{
    license_data_type ld;


    /*
     chek for client ip
     */
    if (strcmp(client_ip,"127.0.0.1")) {
        /*
         ints not local host
         */
        close(sockfd);
        return;
    }

    send_line(sockfd, message(MSG_WELCOME), strlen(message(MSG_WELCOME)));

    if (helo_cmd(sockfd, &ld)) {
        close(sockfd);
        return;
    }

    if (lr_cmd(sockfd, &ld)) {
        close(sockfd);
        return;
    }

    if (bye_cmd(sockfd)) {
        close(sockfd);
        return;
    }

    sleep(1);

    close(sockfd);
}
Beispiel #25
0
int helo_syntax(int fd, char *buff) {

	char *ptr;
	char *helo_ans = calloc(MAX_MSG_SIZE, sizeof(char));
	ptr = strstr(buff, message(MSG_HELO_CMD));

	ptr = strstr(buff, " ");

	strcat(helo_ans, message(MSG_CMD_OK));
	strcat(helo_ans, client_ip);
	strcat(helo_ans, "/");
	strncat(helo_ans, ptr + 1, strlen(ptr + 1) - 2);
	strcat(helo_ans, "\r\n");

	if (send_line(fd, helo_ans, strlen(helo_ans)) < 0) {
		free(helo_ans);

		return (-1);
	}

	free(helo_ans);

	return (NO_ERROR);
}
Beispiel #26
0
static void make_freq_file(char *str, int make_marks, double f1, double f2)
{
    int i = 0, njoin, image = 0;
    FILE *fpr, *fpw, *fopen();
    string f_file, t_file, foo;
    char buf[MAXBUFSIZE];
    double offset, fl, fu, f0, f2LO=0.0;
    SLAIM data;
    
    void XS_system(), send_line();
    double SpecUnitConv();
    char *GetTmpFile();
    
    fl = f1; fu = f2;
    
    if ((make_marks == 2 || make_marks == -1) && vP->s) {
        f2LO = 2.0 * vP->s->lofreq;
        fl = f2LO - f2;
        fu = f2LO - f1;
	image = 1;
    }
    f0 = (fl + fu)/2.0;

    if (strncmp(str, "SLAIM", 5)==0) {
        if (f0 > 200.0 && f0 < 300.0) {
            sprintf(f_file, "%s/%s2", pP->slaimDir, pP->slaimFile);
        } else if (f0 >= 300.0) {
            sprintf(f_file, "%s/%s3", pP->slaimDir, pP->slaimFile);
        } else {
            sprintf(f_file, "%s/%s1", pP->slaimDir, pP->slaimFile);
        }
        strcpy(t_file, GetTmpFile("slaim"));
        offset = 0.1 + image*0.1;
    } else if (strncmp(str, "JPL", 3)==0) {
        if (f0 > 15.0 && f0 < 70.0) {
            sprintf(f_file, "%s/jpl.015-070", pP->jplDir);
        } else if (f0 >=  70.0 && f0 < 120.0) {
            sprintf(f_file, "%s/jpl.070-120", pP->jplDir);
        } else if (f0 >= 120.0 && f0 < 200.0) {
            sprintf(f_file, "%s/jpl.120-200", pP->jplDir);
        } else if (f0 >= 200.0 && f0 < 300.0) {
            sprintf(f_file, "%s/jpl.200-300", pP->jplDir);
        } else if (f0 >= 300.0 && f0 < 400.0) {
            sprintf(f_file, "%s/jpl.300-400", pP->jplDir);
        } else if (f0 >= 400.0 && f0 < 500.0) {
            sprintf(f_file, "%s/jpl.400-500", pP->jplDir);
        } else if (f0 >= 500.0 && f0 < 600.0) {
            sprintf(f_file, "%s/jpl.500-600", pP->jplDir);
        } else {
            sprintf(f_file, "Don't have a JPL file for f=%f GHz.", f0);
            send_line(f_file);
            return;
        }
        strcpy(t_file, GetTmpFile("jpl"));
        offset = 0.2 + image*0.1;
    } else if (strncmp(str, "IDENT", 5)==0) {
        sprintf(f_file, "%s/%s", pP->identDir, pP->identFile);
        strcpy(t_file, GetTmpFile("ident"));
        offset = 0.3;
    } else if (strncmp(str, "sgrb2", 5)==0) {
        sprintf(f_file, "%s/%s", pP->identDir, str);
        strcpy(t_file, GetTmpFile(str));
        offset = 0.1;
    } else if (strncmp(str, "orion", 5)==0) {
        sprintf(f_file, "%s/%s", pP->identDir, str);
        strcpy(t_file, GetTmpFile(str));
        offset = 0.0;
    } else if (strncmp(str, "LOVAS", 5)==0) {
        sprintf(f_file, "%s/%s", pP->lovasDir, pP->lovasFile);
        strcpy(t_file, GetTmpFile("lovas"));
        offset = 0.4 + image*0.1;
    } else {
        return;
    }
    if ((fpr = fopen(f_file, "r")) == NULL) {
        sprintf(foo, "Unable to open %s for reading.", f_file);
        PostErrorDialog(NULL, foo);
        return;
    }
    sprintf(foo, "%s %s", pP->unixRmCmd, t_file);
    XS_system(foo, 0);
    if ((fpw = fopen(t_file, "w")) == NULL) {
        sprintf(foo, "Unable to open %s for writing.", t_file);
        PostErrorDialog(NULL, foo);
        if (fpr) fclose(fpr);
        return;
    }

    while((fgets(buf, MAXBUFSIZE, fpr)) != NULL) {
        buf[strlen(buf)-1] = '\0';
        if (strncmp(str, "SLAIM", 5)==0) { 
            obtain_slaim_data(buf, &data);
        } 
        if (strncmp(str, "JPL", 3)==0) {
            obtain_jpl_data(buf, &data);
        } 
        if (strncmp(str, "IDENT", 5)==0) {
            if (buf[0] != ' ') continue;
            obtain_ident_data(buf, &data);
        }
        if (strncmp(str, "sgrb2", 5)==0 || strncmp(str, "orion", 5)==0) {
            if (str[0] == '#' || str[0] == '!') continue;
            obtain_sgrb2_data(buf, &data);
        }
        if (strncmp(str, "LOVAS", 5)==0) {
            obtain_lovas_data(buf, &data);
        }
        if (data.fre_cal >= 1000.0*fl && data.fre_cal <= 1000.0*fu) {
            fprintf(fpw, "%s\n", buf);
            if (make_marks >= 1 && nmark < MAXMARK) {
                mark_xunit = vP->xunit;
		if (image) {
                  f0 = SpecUnitConv(mark_xunit, UNIT_FRE,
		                     f2LO - data.fre_cal/1000.0);
		} else {
                  f0 = SpecUnitConv(mark_xunit, UNIT_FRE, data.fre_cal/1000.0);
		}
                marks[nmark].mode = 0;
                marks[nmark].x = f0;
                if (offset == 0.0) {
                    marks[nmark].y = data.line_str;
                    marks[nmark].align = 0.0;
                    marks[nmark].type  = MARK_TYPE_LINE;
                } else {
                    marks[nmark].y = vP->yupper - offset*vP->yrange;
                    marks[nmark].align = 0.5;
                    marks[nmark].type  = MARK_TYPE_ARROW;
                }
                marks[nmark].angle = 90.0;
                marks[nmark].xlength = 20;
                marks[nmark].ylength = 20;
                marks[nmark].tagged = 0;
                njoin = nmark + data.joined;
                if (njoin != nmark && njoin >= 0 && njoin < MAXMARK)
                    marks[nmark].mark = &marks[njoin];
                else
                    marks[nmark].mark = NULL;
                marks[nmark].dir = MARK_DIR_DOWN;
                strcpy(marks[nmark].label, data.mol);
                nmark++;
            }
            i++;
        }
    }
    fclose(fpw);
    fclose(fpr);
    if (make_marks <= 0) {
        sprintf(foo, "%s %s &", pP->editor, t_file);
        XS_system(foo, 1);
    }
}
Beispiel #27
0
// sending email
void sendemail(char *email, char *body)
{
    int sockfd;
    int retval = 0;
    int err;
    char *host_name = "smtp.fakessh.eu";
    struct sockaddr_in their_addr;
    struct hostent *hent;
    char buf[1500] = {0};
    char rbuf[1500] = {0};
    char login[128] = {0};
    char pass[128] = {0};

    //initialize SSL
    SSL_CTX *ctx;
    SSL *ssl;
    SSL_METHOD *meth;

    SSLeay_add_ssl_algorithms();
    meth = SSLv23_method();
    SSL_load_error_strings();
    SSL_library_init();
    ctx = SSL_CTX_new(meth);
    CHK_NULL(ctx);

    fd_set readfds;
    struct timeval timeout;

    //Define a timeout for resending data.
    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

#ifdef WIN32
    WSADATA WSAData;
    WSAStartup(MAKEWORD(2, 2), &WSAData);
#endif

    hent = gethostbyname(host_name);
    memset(&their_addr, 0, sizeof(their_addr));
    their_addr.sin_family = AF_INET;
    their_addr.sin_port = htons(587);
    their_addr.sin_addr = *((struct in_addr *)hent->h_addr);

    //connecting mail server and reconnecting if no response in 2 seconds
    sockfd = open_socket((struct sockaddr *)&their_addr);
    memset(rbuf,0,1500);
    FD_ZERO(&readfds);
    FD_SET(sockfd, &readfds);
    retval = select(sockfd+1, &readfds, NULL, NULL, &timeout);
    while(retval <= 0)
    {
        printf("reconnect...\n");
        sleep(2);
        close(sockfd);
        sockfd = open_socket((struct sockaddr *)&their_addr);
        memset(rbuf,0,1500);
        FD_ZERO(&readfds);
        FD_SET(sockfd, &readfds);
        retval = select(sockfd+1, &readfds, NULL, NULL, &timeout);
    }

    memset(rbuf, 0, 1500);
    recv(sockfd, rbuf, 1500, 0);
    printf("%s\n", rbuf);

    //EHLO
    memset(buf, 0, 1500);
    sprintf(buf, "EHLO localhost\r\n");
    send(sockfd, buf, strlen(buf), 0);
    memset(rbuf, 0, 1500);
    recv(sockfd, rbuf, 1500, 0);
    printf("%s\n", rbuf);

    //START_TLS with OPENSSL
    memset(buf,0, 1500);
    sprintf(buf, "STARTTLS\r\n");
    send(sockfd, buf, strlen(buf), 0);
    memset(rbuf, 0, 1500);
    recv(sockfd, rbuf, 1500, 0);
    printf("%s\n", rbuf);


    //AUTH LOGIN
    ssl   =   SSL_new(ctx);
    CHK_NULL(ssl);
    SSL_set_fd   (ssl,   sockfd);
    err   =   SSL_connect(ssl);
    CHK_SSL(err);

    memset(buf,0, 1500);
    sprintf(buf, "EHLO localhost\r\n");
    send_line(ssl,buf);
    recv_line(ssl);


    memset(buf,0, 1500);
    sprintf(buf, "AUTH LOGIN\r\n");
    send_line(ssl,buf);
    recv_line(ssl);

    //USER
    memset(buf, 0, 1500);
    sprintf(buf,"fakessh");
    memset(login, 0, 128);
    base64(login, buf, strlen(buf));
    sprintf(buf, "%s\r\n", login);
    send_line(ssl,buf);
    recv_line(ssl);

    //PASSWORD
    memset(buf, 0, 1500);
    sprintf(buf, "----");
    memset(pass, 0, 128);
    base64(pass, buf, strlen(buf));
    sprintf(buf, "%s\r\n", pass);
    send_line(ssl,buf);
    recv_line(ssl);

    //MAIL FROM
    memset(buf,0, 1500);
    sprintf(buf, "MAIL FROM:<*****@*****.**>\r\n");
    send_line(ssl,buf);
    recv_line(ssl);

    //RCPT TO first receiver
    memset(buf, 0, 1500);
    sprintf(buf, "RCPT TO:<*****@*****.**>\r\n");
    send_line(ssl,buf);
    recv_line(ssl);

    //RCPT TO second receiver and more receivers can be added
    //memset(buf, 0, 1500);
    //sprintf(buf, "RCPT TO:<*****@*****.**>\r\n");
    //send_line(ssl,buf);
    //recv_line(ssl);

    //DATA ready to send mail content
    send_line(ssl,"DATA\r\n");
    recv_line(ssl);

    //send mail content£¬"\r\n.\r\n" is the end mark of content
    memset(buf, 0, 1500);
    sprintf(buf, "%s\r\n.\r\n", body);
    send_line(ssl,buf);
    recv_line(ssl);
    printf("mail send!\n");

    //QUIT
    send_line(ssl,"QUIT\r\n");
    recv_line(ssl);

    //free SSL and close socket
    SSL_shutdown (ssl);
    close(sockfd);
    SSL_free (ssl);
    SSL_CTX_free (ctx);

#ifdef WIN32
    WSACleanup();
#endif

    return;
}
Beispiel #28
0
void loop_xboard(void)
{
    position_t* pos = position_new();
    color_t engineColor = C_BLACK;
    
    IF.info_depth = info_depth;
    IF.info_pv = info_pv;
    IF.info_curmove = info_curmove;
    IF.search_done = search_done;

    log_set_mode(MODE_GUI);
    log_line("xboard mode");
    
    threads_init(pos);
    
    while (1)
    {
        char* line = get_line();
        char* token = arg_start(line);
        
        if (!strcmp(token, "new"))
        {
            position_reset(pos);
            TT_clear();
            engineColor = C_BLACK;
            InGame = 1;
        }
        else if (!strcmp(token, "quit"))
        {
            InGame = 0;
            threads_search_stop();
            break;
        }
        else if (!strcmp(token, "protover"))
        {
            char* v = arg_next();
            if (v && atoi(v) == 2)
            {
                send_line("feature myname=\"Walce\"");
                send_line("feature setboard=1 usermove=1 sigint=0 sigterm=0");
                send_line("feature playother=1 ping=1 time=1 colors=0 name=1");
                send_line("feature ics=1 analyze=1");
                send_line("feature option=\"Search Depth -spin %d 0 20\"", 0);
                send_line("feature option=\"Thinking Time -spin %d 0 600000\"", 0);
                send_line("feature done=1");
            }
        }
        else if (!strcmp(token, "random") ||
                 !strcmp(token, "bk") ||
                 !strcmp(token, "ics") ||
                 !strcmp(token, "name") ||
                 !strcmp(token, "accepted") ||
                 !strcmp(token, "computer") )
        {
            ; // IGNORE
        }
        else if (!strcmp(token, "variant") ||
                 !strcmp(token, "rejected") ||
                 !strcmp(token, "draw") ||
                 !strcmp(token, "hint") ||
                 !strcmp(token, "hard") ||
                 !strcmp(token, "easy") ||
                 !strcmp(token, "rating") ||
                 !strcmp(token, "pause") ||
                 !strcmp(token, "resume") ||
                 !strcmp(token, "memory") ||
                 !strcmp(token, "cores") ||
                 !strcmp(token, "egtpath") )
        {
            send_line("Error (not implemented yet): %s", token);
        }
        else if (!strcmp(token, "?"))
        {
            threads_search_stop();
        }
        else if (!strcmp(token, "st"))
        {
            token = arg_next();
            if (token)
                TC.l_time = atoi(token) * 1000;
        }
        else if (!strcmp(token, "level"))
        {
            char* moves = arg_next();
            char* min = arg_next();
            char* inc = arg_next();
            char* sec = min ? strchr(min, ':') : NULL;
            
            if (sec)
                *sec++ = 0;

            if (inc)
            {
                int t = atoi(min) * 60 + (sec ? atoi(sec) : 0);

                TC.togo = atoi(moves);
                TC.ctime[0] = TC.otime[0] = t * 1000;
                TC.ctime[1] = TC.otime[1] = atoi(inc) * 1000;
            }
        }
        else if (!strcmp(token, "time"))
        {
            token = arg_next();
            if (token)
                TC.ctime[0] = atoi(token) * 10;
        }
        else if (!strcmp(token, "otim"))
        {
            token = arg_next();
            if (token)
                TC.otime[0] = atoi(token) * 10;
        }
        else if (!strcmp(token, "analyze"))
        {
            ModeAnalyze = 1;
            TC.infinite = 1;
            engineColor = pos->to_move;

            threads_search();
        }
        else if (ModeAnalyze && !strcmp(token, "exit"))
        {
            threads_search_stop();
            ModeAnalyze = 0;
            TC.infinite = 0;
        }
        else if (ModeAnalyze && !strcmp(token, "."))
        {
            //send_line("Error (not implemented yet): %s", token);
        }
        else if (!strncmp(line, "result", 6))
        {
            InGame = 0;
            threads_search_stop();
        }
        else if (!strncmp(line, "force", 5))
        {
            engineColor = C_NONE;
        }
        else if (!strcmp(token, "go"))
        {
            engineColor = pos->to_move;
            threads_search();
        }
        else if (!strcmp(token, "playother"))
        {
            engineColor = 1 ^ pos->to_move;
        }
        else if (!strcmp(token, "white"))
        {
            pos->to_move = C_WHITE;
            engineColor = C_BLACK;
        }
        else if (!strcmp(token, "black"))
        {
            pos->to_move = C_BLACK;
            engineColor = C_WHITE;
        }
        else if (!strcmp(token, "sd"))
        {
            char* d = arg_next();
            if (d)
                TC.l_depth = atoi(d);
        }
        else if (!strcmp(token, "ping"))
        {
            char* a = arg_rest();
            if (a)
                send_line("pong %s", a);
            else
                send_line("pong");
        }
        else if (!strcmp(token, "edit"))
        {
            send_line("Error (command not implemented): %s", token);
        }
        else if (!strcmp(token, "undo"))
        {
            if (!position_unmove(pos))
                send_line("Error (command not legal now): %s", token);
        }
        else if (!strcmp(token, "remove"))
        {
            if (!position_unmove(pos) || !position_unmove(pos))
                send_line("Error (command not legal now): %s", token);
        }
        else if (!strcmp(token, "setboard"))
        {
            char* b = arg_rest();
            if (!b)
                send_line("Error (missing argument): %s", token);
            else
                position_set(pos, b);
        }
        else if (!strcmp(token, "post"))
        {
            ModePost = 1;
        }
        else if (!strcmp(token, "nopost"))
        {
            ModePost = 1;
        }
        else if (!strcmp(token, "option"))
        {
            char* o = arg_next_sep('=');
            char* v = arg_next();
            if (!o)
                log_line("missing option");
            else if (!strcmp(o, "Thinking Time"))
            {
                if (v)
                    TC.l_time = atoi(v);
            }
            else if (!strcmp(o, "Search Depth"))
            {
                if (v)
                    TC.l_depth = atoi(v);
            }
            else
                log_line("unknown option: %s", o);
        }
        else
        {
            if (!strcmp(token, "usermove"))
                token = arg_next();
            
            threads_search_stop();
            
            move_t move = parse_move(pos, token);
            if (!move)
            {
                send_line("Illegal move: %s", token);
            }
            else
            {
                position_move(pos, move);
                position_print(pos, C_WHITE);
                if (ModeAnalyze || engineColor == pos->to_move)
                    threads_search();
            }
        }
    }

    threads_exit();
    position_destroy(pos);
}
Beispiel #29
0
void Core::write_string(string s){
	Line line(s);
	send_line(line);
	launch_output_refresh();
}
Beispiel #30
0
static void
socket_starttls(socket_st * socket)
{
	char buf[512];

	if (socket->secure)
		return;

	if (socket->app_proto == NULL || strcasecmp(socket->app_proto, "https") == 0)
		return;

	if (strcasecmp(socket->app_proto, "smtp") == 0 || strcasecmp(socket->app_proto, "submission") == 0) {
		if (socket->verbose)
			printf("Negotiating SMTP STARTTLS\n");

		wait_for_text(socket, "220 ", 4);
		snprintf(buf, sizeof(buf), "EHLO %s\r\n", socket->hostname);
		send_line(socket, buf);
		wait_for_text(socket, "250 ", 4);
		send_line(socket, "STARTTLS\r\n");
		wait_for_text(socket, "220 ", 4);
	} else if (strcasecmp(socket->app_proto, "imap") == 0 || strcasecmp(socket->app_proto, "imap2") == 0) {
		if (socket->verbose)
			printf("Negotiating IMAP STARTTLS\n");

		send_line(socket, "a CAPABILITY\r\n");
		wait_for_text(socket, "a OK", 4);
		send_line(socket, "a STARTTLS\r\n");
		wait_for_text(socket, "a OK", 4);
	} else if (strcasecmp(socket->app_proto, "xmpp") == 0) {
		if (socket->verbose)
			printf("Negotiating XMPP STARTTLS\n");

		snprintf(buf, sizeof(buf), "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' version='1.0'>\n", socket->hostname);
		send_line(socket, buf);
		wait_for_text(socket, "<?", 2);
		send_line(socket, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
		wait_for_text(socket, "<proceed", 8);
	} else if (strcasecmp(socket->app_proto, "ldap") == 0) {
		if (socket->verbose)
			printf("Negotiating LDAP STARTTLS\n");
#define LDAP_STR "\x30\x1d\x02\x01\x01\x77\x18\x80\x16\x31\x2e\x33\x2e\x36\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x34\x36\x36\x2e\x32\x30\x30\x33\x37"
		send(socket->fd, LDAP_STR, sizeof(LDAP_STR)-1, 0);
		wait_for_text(socket, NULL, 0);
	} else if (strcasecmp(socket->app_proto, "ftp") == 0 || strcasecmp(socket->app_proto, "ftps") == 0) {
		if (socket->verbose)
			printf("Negotiating FTP STARTTLS\n");

		send_line(socket, "FEAT\r\n");
		wait_for_text(socket, "211 ", 4);
		send_line(socket, "AUTH TLS\r\n");
		wait_for_text(socket, "234", 3);
	} else if (strcasecmp(socket->app_proto, "lmtp") == 0) {
		if (socket->verbose)
			printf("Negotiating LMTP STARTTLS\n");

		wait_for_text(socket, "220 ", 4);
		snprintf(buf, sizeof(buf), "LHLO %s\r\n", socket->hostname);
		send_line(socket, buf);
		wait_for_text(socket, "250 ", 4);
		send_line(socket, "STARTTLS\r\n");
		wait_for_text(socket, "220 ", 4);
	} else if (strcasecmp(socket->app_proto, "pop3") == 0) {
		if (socket->verbose)
			printf("Negotiating POP3 STARTTLS\n");

		wait_for_text(socket, "+OK", 3);
		send_line(socket, "STLS\r\n");
		wait_for_text(socket, "+OK", 3);
	} else if (strcasecmp(socket->app_proto, "nntp") == 0) {
		if (socket->verbose)
			printf("Negotiating NNTP STARTTLS\n");

		wait_for_text(socket, "200 ", 4);
		send_line(socket, "STARTTLS\r\n");
		wait_for_text(socket, "382 ", 4);
	} else if (strcasecmp(socket->app_proto, "sieve") == 0) {
		if (socket->verbose)
			printf("Negotiating Sieve STARTTLS\n");

		wait_for_text(socket, "OK ", 3);
		send_line(socket, "STARTTLS\r\n");
		wait_for_text(socket, "OK ", 3);
	} else if (strcasecmp(socket->app_proto, "postgres") == 0 || strcasecmp(socket->app_proto, "postgresql") == 0) {
		if (socket->verbose)
			printf("Negotiating PostgreSQL STARTTLS\n");

#define POSTGRES_STR "\x00\x00\x00\x08\x04\xD2\x16\x2F"
		send(socket->fd, POSTGRES_STR, sizeof(POSTGRES_STR)-1, 0);
		wait_for_text(socket, NULL, 0);
	} else {
		if (!c_isdigit(socket->app_proto[0])) {
			static int warned = 0;
			if (warned == 0) {
				fprintf(stderr, "unknown protocol '%s'\n", socket->app_proto);
				warned = 1;
			}
		}
	}

	return;
}