int dash_eval(char *line, char *std_input, char *origin) { if (line == NULL) return 1; int num_tokens; char **tokens = str_split(line, " ", &num_tokens); char *token; int i; int remote_pipe_pos = -1; for (i = 0; i < num_tokens; i++) { if (strcmp(tokens[i], REMOTE_PIPE) == 0) { remote_pipe_pos = i; break; } } if (remote_pipe_pos == -1) // No remote pipes { char *msg_data = dash_exec_scmd(tokens, remote_pipe_pos + 1, num_tokens, std_input); if (std_input == NULL) { printf("%s", msg_data); return 1; } else { // Send to origin char *fio_msg = dashp_fio(msg_data); send_to_host(fio_msg, origin); return 1; } } else // Remote pipe at remote_pipe_pos { char *subcommand = join_strings(tokens, " ", remote_pipe_pos+1, num_tokens); char *remotehost = extract_host(subcommand); char *maincommand = join_strings(tokens, " ", 0, remote_pipe_pos); char *msg_data = dash_exec_scmd(tokens, 0, remote_pipe_pos, std_input); char *send_msg; if (std_input == NULL) { // TODO: MAKE IP ADDRESS FUNCTION WORK! char *fin_remote_host = (char *) malloc (strlen(remotehost) + 1); strcat(fin_remote_host, remotehost); strcat(fin_remote_host, ":"); remove_substring(subcommand, fin_remote_host); free (fin_remote_host); subcommand[strlen(subcommand)-1] = '\0'; send_msg = dashp_pip(msg_data, "127.0.0.1", subcommand); } else { send_msg = dashp_pip(msg_data, origin, subcommand); } send_to_host(send_msg, remotehost); printf("Sent"); return 2; } }
int log_in_host(connection * connection, url * url, int debug_mode) { char * user = malloc(sizeof(url->user) + 5 * sizeof(char)); sprintf(user, "user %s\r\n", url->user); debug_sub_msg(debug_mode, "Sending user to host..."); if (send_to_host(connection->fd, user) == ERROR) { printf("\t->Error sending a message to host."); return ERROR; } debug_sub_msg(debug_mode, "User sent!"); debug_sub_msg(debug_mode, "Receiving message from host..."); if (read_from_host(connection->fd, user, debug_mode, "331") == ERROR) { printf("\nNot a valid user message!\n\n"); return ERROR; } debug_sub_msg(debug_mode, "Message received!"); char * password = malloc(sizeof(url->password) + 5 * sizeof(char)); sprintf(password, "pass %s\r\n", url->password); debug_sub_msg(debug_mode, "Sending password to host..."); if (send_to_host(connection->fd, password) == ERROR) { printf("\t->Error sending a message to host."); return ERROR; } debug_sub_msg(debug_mode, "Password sent!"); debug_sub_msg(debug_mode, "Receiving message from host..."); if (read_from_host(connection->fd, password, debug_mode, "230") == ERROR) { printf("\nLog in failed!\n\n"); return ERROR; } free(password); debug_sub_msg(debug_mode, "Message received!"); return OK; }
int def_path(connection * connectionA, char * path, int debug_mode) { char * retr = malloc(1024 * sizeof(char)); sprintf(retr, "retr %s\r\n", path); char * path_info = malloc(1024 * sizeof(char)); sprintf(path_info, "File: %s", path); debug_sub_msg(debug_mode, path_info); debug_sub_msg(debug_mode, "Sending 'retr' command to host..."); if (send_to_host(connectionA->fd, retr) == ERROR) { printf("\t->Error sending a message to host."); return ERROR; } debug_sub_msg(debug_mode, "Command sent!"); debug_sub_msg(debug_mode, "Receiving message from host..."); if (read_from_host(connectionA->fd, retr, debug_mode, "150") == ERROR) { printf("\nPath is not valid!\n\n"); return ERROR; } free(retr); free(path_info); debug_sub_msg(debug_mode, "Message received!"); return OK; }
int pasv_host(connection * connectionA, url * url, int debug_mode, connection * connectionB) { char * pasv = malloc(7 * sizeof(char)); sprintf(pasv, "pasv \r\n"); debug_sub_msg(debug_mode, "Sending passive message to host..."); if (send_to_host(connectionA->fd, pasv) == ERROR) { printf("\t->Error sending a message to host."); return ERROR; } debug_sub_msg(debug_mode, "Passive message sent!"); debug_sub_msg(debug_mode, "Interpreting passive message from host..."); char * ip = malloc(50 * sizeof(char)); int port; if( get_pasv_from_host(connectionA->fd, ip, &port, debug_mode) < 0 ) { printf("\t->Error interpreting passive message.\n"); return ERROR; } char * ip_info = malloc(1024 * sizeof(char)); strcpy(ip_info, "Interpreted IP: \0"); strcat(ip_info, ip); debug_sub_msg(debug_mode, ip_info); char * port_info = malloc(1024 * sizeof(char)); if (sprintf(port_info, "Interpreted Port: %d", port) < 0) { printf("\t->Error printing port to string.\n"); return ERROR; } connectionB->ip = ip; connectionB->port = port; debug_sub_msg(debug_mode, port_info); debug_sub_msg(debug_mode, "Completed!"); return OK; }
int disconnect_host(connection * connectionA, url * url, int debug_mode) { char * quitA = malloc(6 * sizeof(char)); sprintf(quitA, "quit\r\n"); debug_sub_msg(debug_mode, "Sending 'quit' command to host..."); if (send_to_host(connectionA->fd, quitA) == ERROR) { printf("\t->Error sending a message to host A."); return ERROR; } debug_sub_msg(debug_mode, "Closing socket..."); if (connectionA->fd) { close(connectionA->fd); free(connectionA); } free(url); return OK; }
void at_s( uint8_t *at_cmd , int32_t at_cmd_len ) { int32_t ret; static uint8_t idx; static uint8_t ats_action1,ats_action2 ; uint8_t ack_buf[64]; InsParam_t ins_param_at[8] ; static uint8_t param_num = 0 ; memset( ack_buf , 0 ,sizeof(ack_buf) ); ret = get_ins_ats_action( at_cmd , &ats_action1, &ats_action2 ); if( ERR_SUCCESS != ret ) return ; switch( ats_action1 ) { case '?': break; case '=': switch ( ats_action2 ) { case 0x00: memset( ins_param_at , 0 ,sizeof(ins_param_at) ); idx = 5 ; param_num = get_ins_param( &at_cmd[idx],at_cmd_len-idx-2, ins_param_at );//2//--表示0d,0a if( 1 != param_num ) { send_to_host(AT_ERROR ,strlen(AT_ERROR) ); break; } g_config_at_t.banud = atoi( (char*)&ins_param_at[0].value[0] ); HAL_UART_BandRateChange( g_config_at_t.banud); break; case 0x01: memset( ins_param_at , 0 ,sizeof(ins_param_at) ); idx = 5; param_num = get_ins_param( &at_cmd[idx],at_cmd_len-idx-2, ins_param_at ); if( 4 != param_num ) { send_to_host( AT_ERROR ,strlen(AT_ERROR) ); break; } g_config_at_t.tx_rx = ins_param_at[0].value[0]; g_config_at_t.phy_modulation= atoi((char *)&ins_param_at[1].value[0]); g_config_at_t.phy_freq = atoi((char *)&ins_param_at[2].value[0]); g_config_at_t.phy_sf = atoi((char *)&ins_param_at[3].value[0]); if( g_config_at_t.tx_rx == 'S' ) { g_at_set_tx = true; Tx_dutycycle = 1000; g_macData.phySF = g_config_at_t.phy_sf; g_macData.phyFrequency = g_config_at_t.phy_freq; g_macData.phyModulation = g_config_at_t.phy_modulation; LoRaMac_setMacLayerParameter(&g_macData, PARAMETER_PHY_FREQUENCY|PARAMETER_PHY_SPREADING_FACTOR|PARAMETER_PHY_MODULATION_MODE); LoRaMac_setMode(MODE_PHY); osal_set_event(APP_taskID,APP_PERIOD_SEND); } else if( g_config_at_t.tx_rx == 'R' ) { g_at_set_tx = false; g_macData.phySF = g_config_at_t.phy_sf; g_macData.phyFrequency = g_config_at_t.phy_freq; g_macData.phyModulation = g_config_at_t.phy_modulation; LoRaMac_setMacLayerParameter(&g_macData, PARAMETER_PHY_FREQUENCY|PARAMETER_PHY_SPREADING_FACTOR|PARAMETER_PHY_MODULATION_MODE); LoRaMac_setMode(MODE_PHY); } break; case 0x02: memset( ins_param_at , 0 ,sizeof(ins_param_at) ); idx = 5 ; param_num = get_ins_param( &at_cmd[idx],at_cmd_len-idx-2, ins_param_at );//2//--表示0d,0a if( 2 != param_num ) { send_to_host( AT_ERROR ,strlen(AT_ERROR) ); break; } g_at_set_diffrq = atoi( (char*)&ins_param_at[0].value[0] ); if( g_at_set_diffrq == 1 ) { LoRa_SetDifFrq( atoi( (char*)&ins_param_at[1].value[0] ) ); } break; default: break; } break; default: break; } }