Exemplo n.º 1
0
/* ************************************************************************* *
 * コマンド分岐関数
 * ************************************************************************* */
void
exec_command (char	command,
	      char	*parameter, char *str) {
  switch (command) {
  case 'Q':
    command_quit(parameter);
    break;
  case 'C':
    command_check(parameter);
    break;
  case 'P':
    command_print(profile_data, atoi(parameter), str);
    break;
  case 'R':
    command_read(profile_data, parameter);
    break;
  case 'W':
    command_write(profile_data, parameter);    
    break;
  case 'F':
    command_find(profile_data, parameter, str);    
    break;
  case 'S':
    command_sort(profile_data, atoi(parameter), str);    
    break;
  default:
    printf("Invalid command '%c' was found.\n", command);
    break;
  }
}	      
Exemplo n.º 2
0
int main(int c, char **v)
{
   int wfd, rfd;
   Slave_Command cmd;
   void *params = NULL;
   Eina_Module *m;
   Eina_Bool quit = EINA_FALSE;

   if (c < 3)
     return 1;

   eina_init();
   pfx =  eina_prefix_new(v[0], main,
                          "EVAS", "evas", "checkme",
                          PACKAGE_BIN_DIR,
                          PACKAGE_LIB_DIR,
                          PACKAGE_DATA_DIR,
                          PACKAGE_DATA_DIR);

   loaders = eina_hash_string_superfast_new(NULL);
   evas_module_init();

   wfd = atoi(v[1]);
   rfd = atoi(v[2]);

   while (!quit)
     {
        if (!command_read(rfd, &cmd, &params))
          {
             error_send(wfd, CSERVE2_INVALID_COMMAND);
             return 1;
          }
        switch (cmd)
          {
           case IMAGE_OPEN:
             handle_image_open(wfd, params);
             break;
           case IMAGE_LOAD:
             handle_image_load(wfd, params);
             break;
           case SLAVE_QUIT:
             quit = EINA_TRUE;
             break;
           default:
             error_send(wfd, CSERVE2_INVALID_COMMAND);
          }
     }

   evas_module_shutdown();
   eina_hash_free(loaders);

   EINA_LIST_FREE(modules, m)
      eina_module_free(m);

   eina_prefix_free(pfx);
   eina_shutdown();

   return 0;
}
Exemplo n.º 3
0
static int command_readall(HANDLE handle, git_buf *buf)
{
	size_t bytes_read = 0;
	do {
		char buffer[65536];
		command_read(handle, buffer, sizeof(buffer), &bytes_read);
		git_buf_put(buf, buffer, bytes_read);
	} while (bytes_read);

	return 0;
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: isbit/INF1060
int main() {
    command_line = malloc(STDIN_LEN);

    while (1) {
        signal(SIGINT, exit_signal);

        time_shell();

        fgets(command_line, STDIN_LEN, stdin);
        char *readline = strtok(command_line, "\n");
        command_read(readline);
        memset(command_line, 0, STDIN_LEN); // reset the buffer, make sure it doesn't have any data while reading input

    }
    return 0;

}
Exemplo n.º 5
0
int fsdevice_read(vdrive_t *vdrive, BYTE *data, unsigned int secondary)
{
    bufinfo_t *bufinfo = &(fsdevice_dev[vdrive->unit - 8].bufinfo[secondary]);

    if (secondary == 15)
        return fsdevice_error_get_byte(vdrive, data);

    switch (bufinfo->mode) {
      case Write:
      case Append:
        return FLOPPY_ERROR;
      case Read:
        return command_read(bufinfo, data);
      case Directory:
        return command_directory(vdrive, bufinfo, data, secondary);
    }
    return FLOPPY_ERROR;
}
Exemplo n.º 6
0
int wmain(int argc, wchar_t** argv)
{
	if (argc < 3)
	{
		return 1;
	}

	if (wcscmp(argv[1], L"read") == 0)
	{
		command_read(argc, argv);
	}
	else if (wcscmp(argv[1], L"learn") == 0)
	{
		command_learn(argc, argv);
	}

	return 0;
}
Exemplo n.º 7
0
int ALU(int command, int operand)
{
    trace;
    if (command == 10) {
        return command_read(operand);
    } else if (command == 11) {
        return command_write(operand);
    } else if (command == 20) {
        return command_load(operand);
    } else if (command == 21) {
        return command_store(operand);
    } else if (command == 30) {
        return command_add(operand);
    } else if (command == 31) {
        return command_sub(operand);
    } else if (command == 32) {
        return command_divide(operand);
    } else if (command == 33) {
        return command_mul(operand);
    } else if (command == 40) {
        return command_jump(operand);
    } else if (command == 41) {
        return command_jneg(operand);
    } else if (command == 42) {
        return command_jz(operand);
    } else if (command == 43) {
        return command_halt();
    } else if (command == 51) {
        return command_not(operand);
    } else if (command == 52) {
        return command_and(operand);
    } else if (command == 53) {
        return command_or(operand);
    } else if (command == 54) {
        return command_xor(operand);
    } else if (command == 55) {
        return command_jns(operand);
    } else if (command == 56) {
        return command_jc(operand);
    } else if (command == 57) {
        return command_jnc(operand);
    } else if (command == 58) {
        return command_jp(operand);
    } else if (command == 59) {
        return command_jnp(operand);
    } else if (command == 60) {
        return command_chl(operand);
    } else if (command == 61) {
        return command_shr(operand);
    } else if (command == 62) {
        return command_rcl(operand);
    } else if (command == 63) {
        return command_rcr(operand);
    } else if (command == 64) {
        return command_neg(operand);
    } else if (command == 65 || command == 75) {
        return command_addc(operand);
    } else if (command == 66 || command == 76) {
        return command_subc(operand);
    } else if (command == 67) {
        return command_loglc(operand);
    } else if (command == 68) {
        return command_logrc(operand);
    } else if (command == 69) {
        return command_rccl(operand);
    } else if (command == 70) {
        return command_rccr(operand);
    } else if (command == 71) {
        return command_mova(operand);
    } else if (command == 72) {
        return command_movr(operand);
    } else if (command == 73) {
        return command_movca(operand);
    } else if (command == 74) {
        return command_movcr(operand);
    }

    sc_regSet(COMMAND_ERROR, 1);
    return -1;
}
Exemplo n.º 8
0
int command_read_stdout(COMMAND_HANDLE *commandHandle, char *buffer, size_t buf_size, size_t *bytes_read)
{
	return command_read(commandHandle->out, buffer, buf_size, bytes_read);
}
int main(int argc, const char **argv)
{
	po::options_description	options("usage");
	int fd = -1;

	try
	{
		std::string host;
		std::string port;
		std::string filename;
		std::string start_string;
		std::string length_string;
		std::string chunk_size_string;
		unsigned int start, length, chunk_size;
		bool use_udp = false;
		bool verbose = false;
		bool verbose2 = false;
		bool nocommit = false;
		bool noreset = false;
		bool notemp = false;
		bool otawrite = false;
		bool use_force = false;
		bool erase_before_write = false;
		bool cmd_write = false;
		bool cmd_simulate = false;
		bool cmd_verify = false;
		bool cmd_checksum = false;
		bool cmd_read = false;
		bool force_used;
		action_t action;

		options.add_options()
			("checksum,C",	po::bool_switch(&cmd_checksum)->implicit_value(true),				"CHECKSUM")
			("chunksize,c",	po::value<std::string>(&chunk_size_string)->default_value("0"),		"send/receive chunk size")
			("erase,e",		po::bool_switch(&erase_before_write)->implicit_value(true),			"erase before write (instead of during write)")
			("filename,f",	po::value<std::string>(&filename),									"file name")
			("force,F",		po::bool_switch(&use_force)->implicit_value(true),					"use force if image seems to be incompatible")
			("host,h",		po::value<std::string>(&host)->required(),							"host to connect to")
			("length,l",	po::value<std::string>(&length_string)->default_value("0x1000"),	"read length")
			("nocommit,n",	po::bool_switch(&nocommit)->implicit_value(true),					"don't commit after writing")
			("noreset,N",	po::bool_switch(&noreset)->implicit_value(true),					"don't reset after commit")
			("notemp,t",	po::bool_switch(&notemp)->implicit_value(true),						"don't commit temporarily, commit to flash")
			("port,p",		po::value<std::string>(&port)->default_value("24"),					"port to connect to")
			("start,s",		po::value<std::string>(&start_string)->default_value("2147483647"),	"send/receive start address")
			("read,R",		po::bool_switch(&cmd_read)->implicit_value(true),					"READ")
			("simulate,S",	po::bool_switch(&cmd_simulate)->implicit_value(true),				"WRITE simulate")
			("udp,u",		po::bool_switch(&use_udp)->implicit_value(true),					"use UDP instead of TCP")
			("verbose,v",	po::bool_switch(&verbose)->implicit_value(true),					"verbose output")
			("verbose2,x",	po::bool_switch(&verbose2)->implicit_value(true),					"less verbose output")
			("verify,V",	po::bool_switch(&cmd_verify)->implicit_value(true),					"VERIFY")
			("write,W",		po::bool_switch(&cmd_write)->implicit_value(true),					"WRITE");

		po::positional_options_description positional_options;

		po::variables_map varmap;
		po::store(po::parse_command_line(argc, argv, options), varmap);
		po::notify(varmap);

		if(cmd_checksum)
			action = action_checksum;
		else
			if(cmd_verify)
				action = action_verify;
			else
				if(cmd_simulate)
					action = action_simulate;
				else
					if(cmd_write)
						action = action_write;
					else
						if(cmd_read)
							action = action_read;
						else
							action = action_none;

		start = 0;
		chunk_size = 0;

		try
		{
			chunk_size = std::stoi(chunk_size_string, 0, 0);
		}
		catch(...)
		{
			throw(std::string("invalid value for chunk size argument"));
		}

		try
		{
			start = std::stoi(start_string, 0, 0);
		}
		catch(...)
		{
			throw(std::string("invalid value for start argument"));
		}

		try
		{
			length = std::stoi(length_string, 0, 0);
		}
		catch(...)
		{
			throw(std::string("invalid value for length argument"));
		}

		std::string reply;
		std::vector<int> int_value;
		std::vector<std::string> string_value;
		unsigned int flash_sector_size, flash_ota, flash_slots, flash_slot;
		unsigned int flash_address[4];
		unsigned int preferred_chunk_size;

		GenericSocket channel(host, port, use_udp, verbose);

		force_used = false;

		try
		{
			process(channel, "flash-info", reply, "OK [^,]+, sector size: ([0-9]+)[^,]+, OTA update available: ([0-9]+), "
						"slots: ([0-9]+), slot: ([0-9]+), "
						"address: ([0-9]+), address: ([0-9]+), address: ([0-9]+), address: ([0-9]+)"
						"(?:, preferred chunk size: ([0-9]+))?"
						"\\s*",
						string_value, int_value, verbose);
		}
		catch(std::string &e)
		{
			if(use_force)
			{
				std::cout << "OTA incompatible image, trying to continue due to force flag: " << e << std::endl;
				force_used = true;
			}
			else
				throw(std::string("OTA incompatible image: ") + e);
		}

		if(force_used)
		{
			flash_sector_size = 4096;
			flash_ota = 0;
			flash_slots = 0;
			flash_slot = 0;
			flash_address[0] = 0;
			flash_address[1] = 0;
			flash_address[2] = 0;
			flash_address[3] = 0;
			preferred_chunk_size = 512;
		}
		else
		{
			flash_sector_size = int_value[0];
			flash_ota = int_value[1];
			flash_slots = int_value[2];
			flash_slot = int_value[3];
			flash_address[0] = int_value[4];
			flash_address[1] = int_value[5];
			flash_address[2] = int_value[6];
			flash_address[3] = int_value[7];
			preferred_chunk_size = int_value[8];
		}

		std::cout << "flash operations available, sector size: " << flash_sector_size;

		if(flash_ota)
			std::cout << ", OTA update available, slots: " << flash_slots << ", current slot: " << flash_slot
					<< ", address[0]: 0x" << std::setw(6) << std::setfill('0') << std::hex << flash_address[0]
					<< ", address[1]: 0x" << std::setw(6) << std::setfill('0') << std::hex << flash_address[1]
					<< ", address[2]: 0x" << std::setw(6) << std::setfill('0') << std::hex << flash_address[2]
					<< ", address[3]: 0x" << std::setw(6) << std::setfill('0') << std::hex << flash_address[3]
					<< ", preferred chunk size: " << std::setw(0) << std::setfill(' ') << std::dec << preferred_chunk_size << std::endl;
		else
			std::cout << ", OTA update NOT available" << std::endl;

		if(chunk_size == 0)
			chunk_size = preferred_chunk_size;

		if(chunk_size == 0)
			chunk_size = 512;

		if((flash_sector_size % chunk_size) != 0)
			throw(std::string("chunk size should be dividable by flash sector size"));

		if(start == 2147483647)
		{
			if(flash_ota)
			{
				if(action == action_write)
				{
					flash_slot++;

					if(flash_slot >= flash_slots)
						flash_slot = 0;
				}

				start = flash_address[flash_slot];
				otawrite = true;
			}
			else
				throw(std::string("no start address supplied and image does not support OTA updating"));
		}

		if((start % flash_sector_size) != 0)
			throw(std::string("start address should be dividable by flash sector size"));

		int64_t file_length = 0;

		if((action != action_none) && (action != action_read))
		{
			struct stat stat;

			if(filename.empty())
				throw(std::string("file name required"));

			if((fd = open(filename.c_str(), O_RDONLY, 0)) < 0)
				throw(std::string("file not found"));

			fstat(fd, &stat);

			file_length = stat.st_size;
		}

		if(action == action_read)
		{
			if(filename.empty())
				throw(std::string("file name required"));

			if((fd = open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0777)) < 0)
				throw(std::string("can't create file"));

			file_length = 0;
		}

		switch(action)
		{
			case(action_read):
			{
				command_read(channel, fd, start, length, flash_sector_size, chunk_size, verbose);
				break;
			}

			case(action_checksum):
			{
				command_checksum(channel, fd, file_length, start, flash_sector_size, verbose);
				break;
			}

			case(action_write):
			case(action_simulate):
			case(action_verify):
			{
				command_write(channel, fd, file_length, start, flash_sector_size, chunk_size, verbose, action, erase_before_write);
				break;
			}

			case(action_none):
			{
				break;
			}
		}

		if((action == action_write) && otawrite)
		{
			if(!nocommit)
			{
				std::string send_string;
				std::string reply;

				if(notemp)
				{
					send_string = std::string("flash-select ") + std::to_string(flash_slot);
					process(channel, send_string, reply, "OK flash-select: slot ([0-9]+) selected, address ([0-9]+)\\s*", string_value, int_value, verbose || verbose2);
				}
				else
				{
					send_string = std::string("flash-select-once ") + std::to_string(flash_slot);
					process(channel, send_string, reply, "OK flash-select-once: slot ([0-9]+) selected, address ([0-9]+)\\s*", string_value, int_value, verbose ||verbose2);
				}

				if((unsigned int)int_value[0] != flash_slot)
					throw(std::string("flash-select failed, local slot (") + std::to_string(flash_slot) + ") != remote slot (" + std::to_string(int_value[0]) + ")");

				if((unsigned int)int_value[1] != start)
					throw(std::string("flash-select failed, local address (") +  std::to_string(flash_slot) + ") != remote address (" + std::to_string(int_value[0]) + ")");

				if(notemp)
					std::cout << "selected boot slot";
				else
					std::cout << "selected one time boot slot";

				std::cout << ": " << flash_slot << ", address: 0x" << std::hex << std::setw(6) << std::setfill('0') << start << std::dec << std::setw(0) << std::endl;

				if(!noreset)
				{
					std::cout << "rebooting" << std::endl;

					channel.send(1000, std::string("reset"));

					sleep(2);

					channel.reconnect();

					std::cout << "reboot finished" << std::endl;

					if(!notemp)
					{
						process(channel, "flash-info", reply, "OK [^,]+, sector size: ([0-9]+)[^,]+, OTA update available: ([0-9]+), "
									"slots: ([0-9]+), slot: ([0-9]+), "
									"address: ([0-9]+), address: ([0-9]+), address: ([0-9]+), address: ([0-9]+)"
									"(?:, preferred chunk size: ([0-9]+))?"
									"\\s*",
									string_value, int_value, verbose);

						if(int_value[3] != (int)flash_slot)
							std::cout << "boot failed, requested slot: " << flash_slot << ", active slot: " << int_value[3] << std::endl;
						else
						{
							std::cout << "boot succeeded, permanently selecting boot slot: " << flash_slot << ", address: 0x" << std::hex << std::setw(6) << std::setfill('0') << start << std::dec << std::setw(0) << std::endl;

							std::string send_string;
							std::string reply;

							send_string = std::string("flash-select ") + std::to_string(flash_slot);
							process(channel, send_string, reply,
									"OK flash-select: slot ([0-9]+) selected, address ([0-9]+)\\s*",
									string_value, int_value, verbose || verbose2);

							if((unsigned int)int_value[0] != flash_slot)
								throw(std::string("flash-select failed, local slot (") + std::to_string(flash_slot) + ") != remote slot (" + std::to_string(int_value[0]) + ")");

							if((unsigned int)int_value[1] != start)
								throw(std::string("flash-select failed, local address (") + std::to_string(flash_slot) +  ") != remote address (" + std::to_string(int_value[0]) + ")");
						}
					}
				}

				process(channel, "stats", reply, "> firmware version date: ([a-zA-Z0-9: ]+).*", string_value, int_value, verbose, 1000);

				std::cout << "firmware version: " << string_value[0] << std::endl;
			}
		}
	}
	catch(const po::error &e)
	{
		std::cerr << std::endl << "espflash: " << e.what() << std::endl << options;
		goto error;
	}
	catch(const std::exception &e)
	{
		std::cerr << std::endl << "espflash: " << e.what() << std::endl;
		goto error;
	}
	catch(const std::string &e)
	{
		std::cerr << std::endl << "espflash: " << e << std::endl;
		goto error;
	}
	catch(...)
	{
		std::cerr << std::endl << "espflash: unknown exception caught" << std::endl;
		goto error;
	}

	if(fd >= 0)
		close(fd);

	return(0);

error:
	if(fd >= 0)
		close(fd);

	return(1);
}
Exemplo n.º 10
0
Arquivo: hlib.c Projeto: cafiend/W12
/* TODO: Clean up */
Event *GetEvent(Display *display)
{
    Command *cmd = command_read(display->socket);
    Event *e = NULL;
    int len = 0;
    char* str = NULL;
    
    if (cmd == NULL)
        return NULL;
    
    if (cmd->params[0] == NULL)
        return NULL;
    
    len = strlen(cmd->params[0]);

    /* Check for expose */
    if (len == 6 && strncmp(cmd->params[0], "EXPOSE", 6) == 0) {
        e = event_expose_new();
        return e;
    }
    else if (len == 5 && strncmp(cmd->params[0], "SETUP", 5) == 0) {
    	int w 	= atoi(cmd->params[1]);
		int h 	= atoi(cmd->params[2]);

		e = event_setup_new(w,h);
		/* 
		 * Check the display's callbacks and send registration 
		 * message to the browser side as required.
		 * 
		 * Done in a single message, accumulating hanlders to register.
		 * 
		 * NB: When adding events, this string might need to grow!
		 */

		 if (display->callbacks != NULL) {
			 str = calloc(REG_CB_MSG_SIZE, sizeof(char));
			 if(display->callbacks->clickHandlers != NULL) {
				 strcat(str, "\"CLICK\" ");
			 }
			 if(display->callbacks->mouseMoveHandlers != NULL) {
				 strcat(str, "\"MMOVE\" ");
			 }
			 if(display->callbacks->mouseDownHandlers != NULL) {
				 strcat(str, "\"MDOWN\" ");
			 }
			 if(display->callbacks->mouseDragHandlers != NULL) {
				 strcat(str, "\"MDRAG\" ");
			 }
			 if(display->callbacks->mouseDragOutHandlers != NULL) {
				 strcat(str, "\"MDRAGOUT\" ");
			 }
			 if(display->callbacks->fileDropInitHandlers != NULL ||
					 display->callbacks->b64FileDropInitHandlers != NULL) {
				 /* A single callback handler for both un-encoded and base64 encoded transfers */
				 strcat(str, "\"DROP\" ");
			 }
			 if(display->callbacks->resizeHandlers != NULL) {
				 strcat(str, "\"RESIZE\" ");
			 }
			 if (strlen(str) > 0) {
				 /* Change all but the last space to a comma. Only need to do this if one of the callbacks is used */
				 int i = 0;
				 for(i = 0; i < strlen(str)-1; i++) {
					 if (str[i] == ' ') {
						 str[i] = ',';
					 }
				 }
				 /* Eventually, check the return value to determine success here */
				 SendRegisterCallbackMsg(display, str);
			 }
			 free(str);

			 /* Register keyboard handlers if any */
			 CallbackList *cb = display->callbacks->keyTypedHandlers;
			 if (cb != NULL) {
				 SendKeyboardCallbackMsg(display, "CB_KEY_T", (char *)cb->data);
			 }
			 cb = display->callbacks->keyPressedHandlers;
			 if (cb != NULL) {
				 SendKeyboardCallbackMsg(display, "CB_KEY_P", (char *)cb->data);
			 }
			 cb = display->callbacks->keyReleasedHandlers;
			 if (cb != NULL) {
				 SendKeyboardCallbackMsg(display, "CB_KEY_R", (char *)cb->data);
			 }
		 }




		return e;
	}
    else if (len == 5 && strncmp(cmd->params[0], "CLICK", 5) == 0) {
        int x = atoi(cmd->params[1]);
        int y = atoi(cmd->params[2]);
        int button = atoi(cmd->params[3]);
        e = event_click_new(x, y, button);
        return e;
    }
    else if (len == 5 && strncmp(cmd->params[0], "MDOWN", 5) == 0) {
        int x = atoi(cmd->params[1]);
        int y = atoi(cmd->params[2]);
        int button = atoi(cmd->params[3]);
        e = event_mousedown_new(x, y, button);
        return e;
    }
    else if (len == 5 && strncmp(cmd->params[0], "MMOVE", 5) == 0) {
        int x 	= atoi(cmd->params[1]);
        int y 	= atoi(cmd->params[2]);
        int dx	= atoi(cmd->params[3]);
        int dy	= atoi(cmd->params[4]);
        
        e = event_mousemove_new(x, y, dx, dy);
        return e;
    }
    else if (len == 5 && strncmp(cmd->params[0], "MDRAG", 5) == 0) {
        int x 	= atoi(cmd->params[1]);
        int y 	= atoi(cmd->params[2]);
        int dx	= atoi(cmd->params[3]);
        int dy	= atoi(cmd->params[4]);
        int button = atoi(cmd->params[5]);
        e = event_mousedrag_new(x, y, dx, dy, button);
        return e;
    }
    else if (len == 8 && strncmp(cmd->params[0], "MDRAGOUT", 8) == 0) {
    	int x 	= atoi(cmd->params[1]);
    	int y 	= atoi(cmd->params[2]);
    	int dx	= atoi(cmd->params[3]);
    	int dy	= atoi(cmd->params[4]);
    	int button = atoi(cmd->params[5]);
    	e = event_mousedragout_new(x, y, dx, dy, button);
    	return e;
    }
    else if (len == 7 && strncmp(cmd->params[0], "PRELOAD", 7) == 0) {
        e = event_preload_new();
        return e;
    }
    else if (len == 6 && strncmp(cmd->params[0], "RESIZE", 6) == 0) {
		int w 	= atoi(cmd->params[1]);
		int h 	= atoi(cmd->params[2]);

		e = event_resize_new(w,h);
		return e;
	}
    else if (len == 8 && strncmp(cmd->params[0], "KEYTYPED", 8) == 0) {
    	int k = atoi(cmd->params[1]);

    	e = event_key_typed_new(k);
    	return e;
	}
    else if (len == 10 && strncmp(cmd->params[0], "KEYPRESSED", 10)  == 0) {
    	int k = atoi(cmd->params[1]);

    	e = event_key_pressed_new(k);
    	return e;
    }
    else if (len == 11 && strncmp(cmd->params[0], "KEYRELEASED", 11) == 0) {
    	int k = atoi(cmd->params[1]);

    	e = event_key_released_new(k);
    	return e;
    }
    else if (len == 4 && strncmp(cmd->params[0], "DROP", 4) == 0) {
		/* It's a paired message approach. First message sets the event
		 * metadata and establishes the number of chunks required for transfer.
		 *
		 * Message 0 format:
		 * 		EVENT DROP INIT <filename> <filetype> <filesize>
		 * 		Caveat: Filetype might not be known. Javascript support for it seems dodgy.
		 *
		 * 1 to N-1 Message pairs then follow in the format:
		 * 		a. EVENT DROP CHUNK <filename> <filetype> <filesize> <current chunk>
		 * 		b. <file chunk X>
		 *
		 * Final Message format:
		 * 		EVENT DROP END <filename> <filetype> <filesize>
		 */
    	char *name	= strdup(cmd->params[2]);
		char *type	= strdup(cmd->params[3]);
		unsigned int size	= atoi(cmd->params[4]);
		unsigned int nchunks	= CEIL((double)(size / CHUNKSIZE));

    	if ( (strlen(cmd->params[1]) == 5) && strncmp(cmd->params[1], "CHUNK", 5) == 0 ) {
    		/* This is a filechunk pair */
    		unsigned int chunk_size	= atoi(cmd->params[5]);
    		unsigned int cur_chunk	= atoi(cmd->params[6]);
    		char buf[CHUNKSIZE];
    		int ret = 0;

    		ret = socket_read(display->socket, buf, chunk_size);

    		e = event_filedrop_chunk_new(name, type, size, nchunks, chunk_size, cur_chunk, buf);
			return e;
    	} else if ( (strlen(cmd->params[1]) == 3) && strncmp(cmd->params[1], "END", 3) == 0 ) {
    		/* This is the end of the transfer */
    		e = event_filedrop_end_new(name, type, size, nchunks);
    		return e;
    	} else {
    		/* Filedrop Initalisation */
    		e = event_filedrop_init_new(name, type, size, nchunks);
    		return e;
    	}
    }
    else if (len == 6 && strncmp(cmd->params[0], "DROP64", 6) == 0) {
		/* The client application is responsible for base64 decoding
		 */
		char *name	= strdup(cmd->params[2]);
		char *type	= strdup(cmd->params[3]);
		unsigned int o_size	= atoi(cmd->params[4]);

		if ( (strlen(cmd->params[1]) == 5) && strncmp(cmd->params[1], "CHUNK", 5) == 0 ) {
			/* This is a filechunk pair */
			unsigned int e_size	= atoi(cmd->params[5]);
			unsigned int chunk_size	= atoi(cmd->params[6]);
			unsigned int cur_chunk	= atoi(cmd->params[7]);

			unsigned int nchunks	= CEIL((double)(e_size / CHUNKSIZE));

			char buf[CHUNKSIZE];
			int ret = 0;

			ret = socket_read(display->socket, buf, chunk_size);

			e = event_filedrop64_chunk_new(name, type, o_size, e_size, nchunks, chunk_size, cur_chunk, buf);
			return e;
		} else if ( (strlen(cmd->params[1]) == 3) && strncmp(cmd->params[1], "END", 3) == 0 ) {
			/* This is the end of the transfer */
			unsigned int e_size	= atoi(cmd->params[5]);
			unsigned int nchunks	= CEIL((double)(e_size / CHUNKSIZE));
			e = event_filedrop64_end_new(name, type, o_size, e_size, nchunks);
			return e;
		} else {
			/* Filedrop Initalisation */
			/* NB we don't actually know the encoded filesize nor the number of chunks yet */
			e = event_filedrop64_init_new(name, type, o_size);
			return e;
		}
	}

    return NULL;
}
Exemplo n.º 11
0
static int dev_do_io (struct devstruct *dev, uaecptr request)
{
    uae_u32 command;
    uae_u32 io_data = get_long (request + 40); // 0x28
    uae_u32 io_length = get_long (request + 36); // 0x24
    uae_u32 io_actual = get_long (request + 32); // 0x20
    uae_u32 io_offset = get_long (request + 44); // 0x2c
    uae_u32 io_error = 0;
    int async = 0;
    struct device_info di;
    struct priv_devstruct *pdev = getpdevstruct (request);

    if (!pdev)
	return 0;
    command = get_word (request+28);

    switch (command)
    {
	case CMD_READ:
	io_error = command_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual);
	break;
	case CMD_WRITE:
	case CMD_FORMAT:
	io_error = 28; /* writeprotect */
	break;
	case CMD_UPDATE:
	case CMD_CLEAR:
	case CMD_FLUSH:
	case CMD_MOTOR:
	case CMD_SEEK:
	io_actual = 0;
	break;
	case CMD_REMOVE:
	io_actual = 0;
	break;
	case CMD_CHANGENUM:
	io_actual = dev->changenum;
	break;
	case CMD_CHANGESTATE:
	io_actual = devinfo(pdev->mode, dev->unitnum, &di)->media_inserted ? 0 : 1;
	break;
	case CMD_PROTSTATUS:
	io_actual = devinfo(pdev->mode, dev->unitnum, &di)->write_protected ? -1 : 0;
	break;
	case CMD_GETDRIVETYPE:
	io_actual = dev->drivetype;
	break;
	case CMD_GETNUMTRACKS:
	io_actual = dev->di.cylinders;
	break;
	case CMD_ADDCHANGEINT:
	io_error = add_async_request (dev, request, ASYNC_REQUEST_CHANGEINT, io_data);
	if (!io_error)
	    async = 1;
	break;
	case CMD_REMCHANGEINT:
	release_async_request (dev, request);
	break;
	case 28: /* HD_SCSICMD */
	if (dev->allow_scsi && pdev->scsi) {
	    uae_u32 sdd = get_long (request + 40);
	    io_error = sys_command_scsi_direct (dev->unitnum, sdd);
	    if (log_scsi)
		write_log ("scsidev: did io: sdd %p request %p error %d\n", sdd, request, get_byte (request + 31));
	}
	break;
	default:
	io_error = -3;
	break;
    }
    put_long (request + 32, io_actual);
    put_byte (request + 31, io_error);
    io_log ("dev_io",request);
    return async;
}