Example #1
0
int
Multicast_Manager::insert_hosts_from_file (const char *filename)
{
  ACE_Mem_Map mmap (filename);
  char *host_ptr = (char *) mmap.addr ();

  if (host_ptr == 0)
    return -1;
  else
    {
      for (char *end_ptr = host_ptr + mmap.size ();
           host_ptr < end_ptr;
           )
        {
          Multicast_Manager::add_host (host_ptr);

          while (*host_ptr != '\n')
            host_ptr++;

          *host_ptr++ = '\0';
        }

      return 0;
    }
}
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  parse_args (argc, argv);
  void *cp;
  char buf[BUFSIZ];
  ACE_TLI_Stream sc;
  ACE_TLI_Connector con;

  if (con.connect (sc,
                   ACE_INET_Addr (port_number,
                                  host_name)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open"),
                      -1);

  ACE_Mem_Map mmap (file_name, PROT_READ);

  if (mmap (cp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",

                       "mmap"), -1);

  // Next, send the file's contents.

  if (sc.send_n (cp, mmap.size ()) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",

                       "send_n"), -1);

  if (sc.sndrel () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close_writer"),
                      -1);

  for (int n; (n = sc.recv (buf, sizeof buf)) > 0; )
    if (ACE_OS::write (ACE_STDOUT, buf, n) != n)
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "write"),
                        -1);

  if (sc.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                      -1);
  return 0;
}
Example #3
0
// Send a file
// Takes a file name as an argument. Since we cannot send arbitary
// sized data on an underlying UDP transport, we are going to break
// the file into chunk sizes. By default we will use a chunk size of
// 256 but the user can set a different size
//
// Returns -1 on error and bytes sent on success
size_t FileTransferClient::SendFile (const string &filename)
{

  ACE_Mem_Map mmap; // we choose to use memory mapped files so that we
                    // can access the file contents directly from a
                    // buffer 

  // now map the file into memory
  if (mmap.map (filename.c_str ()) == -1) {
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("[%P] FileTransferClientClient::SendFile - ")
                ACE_TEXT ("failed to map file (%m)\n")));
    return -1;
  }

  // delegate sending of the the file to our reliable protocol handler
  return this->proto_object_->send_data (mmap.addr (),
                                         mmap.size ());
}
Example #4
0
int
ACE_TMAIN (int argc, ACE_TCHAR **argv)
{
  ACE_LOG_MSG->open (argv[0]);

  if (argc != 2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "usage: %n file\n"),
                      -1);

  ACE_Mem_Map mmap;

  if (mmap.map (argv[1], static_cast<size_t> (-1), O_RDWR) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%n: %p\n",
                       "mmap"),
                      -1);

  print_array_in_reverse ((char *) mmap.addr (),
                          ACE_Utils::truncate_cast<int> (mmap.size ()));
  return 0;
}
Example #5
0
int
main (int argc, char **argv)
{
  ACE_LOG_MSG->open (argv[0]);

  if (argc != 2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "usage: %n file\n"),
                      -1);

  ACE_Mem_Map mmap;
  
  if (mmap.map (argv[1], -1, O_RDWR) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, 
                       "%n: %p\n",
                       "mmap"),
                      -1);

  print_array_in_reverse ((char *) mmap.addr (),
                          mmap.size ());
  return 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  parse_arguments (argc, argv);

  ACE_FIFO_Send_Msg fifo;

  if (fifo.open (rendezvous_fifo,
                 O_WRONLY,
                 0666) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Cannot open %s for requesting a new communication channel"
                       "in local_fifo_client_test\n",
                       rendezvous_fifo),
                      -1);
  void *cp = 0;

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Mem_Map mmap (file_name);

  if (mmap (cp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "mmap"),
                      -1);
  //FUZZ: enable check_for_lack_ACE_OS

  // Next, send the file's contents.

  ACE_Str_Buf msg (cp,
                   int (mmap.size ()));

  if (fifo.send (msg) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      -1);
  return 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  parse_arguments (argc, argv);

  ACE_SPIPE_Stream spipe;
  ACE_SPIPE_Connector con;

  if (con.connect (spipe,
                   ACE_SPIPE_Addr (rendezvous_spipe)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Cannot open %s for requesting a new ")
                       ACE_TEXT ("communication channel in %p\n"),
                       rendezvous_spipe,
                       ACE_TEXT ("local_spipe_client_test")),
                      -1);

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Mem_Map mmap (file_name);
  void *cp;

  if (mmap (cp) == -1)
  //FUZZ: enable check_for_lack_ACE_OS
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("mmap")),
                      -1);

  // Next, send the file's contents.

  ACE_Str_Buf msg (cp, int (mmap.size ()));

  if (spipe.send ((ACE_Str_Buf *) 0, &msg) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("send")),
                      -1);
  return 0;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  parse_arguments (argc, argv);

  ACE_SPIPE_Stream spipe;
  ACE_SPIPE_Connector con;

  if (con.connect (spipe,
                   ACE_SPIPE_Addr (rendezvous_spipe)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
		       "Cannot open %s for requesting a new communication channel"
		       " in local_spipe_client_test.\n",
                       rendezvous_spipe),
                      -1);

  ACE_Mem_Map mmap (file_name);
  void *cp;

  if (mmap (cp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "mmap"),
                      -1);

  // Next, send the file's contents.

  ACE_Str_Buf msg (cp, int (mmap.size ()));

  if (spipe.send ((ACE_Str_Buf *) 0, &msg) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      -1);
  return 0;
}
Example #9
0
void
HTTP_Response::normal_response (void)
{
  const char *hv = 0;;

  ACE_DEBUG ((LM_DEBUG, " (%t) %s request for %s [%s], version %s\n",
              request_.method (), request_.uri (), request_.path (),
              (request_.version () ? request_.version () : "HTTP/0.9")));

  switch (this->request_.type ())
    {
    case HTTP_Request::GET :

      this->build_headers ();
      this->io_.transmit_file (this->request_.path (),
                               this->HTTP_HEADER,
                               this->HTTP_HEADER_LENGTH,
                               this->HTTP_TRAILER,
                               this->HTTP_TRAILER_LENGTH);
      break;

    case HTTP_Request::HEAD :
      this->build_headers ();
      this->io_.send_confirmation_message (this->HTTP_HEADER,
                                           this->HTTP_HEADER_LENGTH);
      break;

    case HTTP_Request::POST :
      // What to do here?
      // Standard says this is implementation dependent.
      // Examples: annotations, page updates, etc.
      // This may be a good place to stick CORBA stuff,
      // and mobile code.
      this->error_response (HTTP_Status_Code::STATUS_NOT_IMPLEMENTED,
                            "Requested method is not implemented.");
      break;

    case HTTP_Request::PUT :
      // Only commit to this if we can authenticate it

      // if there is no Authentication: header on the incoming request,
      // deny it
      hv = this->request_.headers ()["Authorization"].value ();
      if (hv == 0 || *hv == '\0')
        this->error_response (HTTP_Status_Code::STATUS_UNAUTHORIZED,
                              "Unauthorized to use PUT method");
      else if (ACE_OS::strncmp (hv, "Basic ", 6) != 0)
        // ``6'' is the length of the string "Basic "
        this->error_response (HTTP_Status_Code::STATUS_UNAUTHORIZED,
                              "Unknown authorization method");
      else
        {
          ACE_Mem_Map mmapfile;
          const char *hvv = hv + 6;
          // Skip past the string "Basic "
          char *buf = new char [ACE_OS::strlen (hv)];
          char *auth
            = HTTP_Helper::HTTP_decode_base64 (ACE_OS::strcpy (buf, hvv));

          if (mmapfile.map (ACE_TEXT ("jaws.auth")) != -1
              && auth != 0
              && ACE_OS::strstr((const char *) mmapfile.addr (), auth) != 0)
            this->io_.receive_file (this->request_.path (),
                                    this->request_.data (),
                                    this->request_.data_length (),
                                    this->request_.content_length ());
          else
            this->error_response (HTTP_Status_Code::STATUS_UNAUTHORIZED,
                                  "Invalid authorization attempt");
          delete [] buf;
        }
      break;

    default :
      this->error_response (HTTP_Status_Code::STATUS_NOT_IMPLEMENTED,
                            "Requested method is not implemented.");
    }
}
int
run_main (int, ACE_TCHAR *[])
{
    ACE_START_TEST (ACE_TEXT ("Mem_Map_Test"));

#if !defined (ACE_LACKS_MMAP)

    // = Initialize the temporary variable names

    ACE_TCHAR test_file[MAXPATHLEN + 1];
    ACE_TCHAR temp_file1[MAXPATHLEN + 1];
    ACE_TCHAR temp_file2[MAXPATHLEN + 1];

    // Get the temporary directory
    // - 18 is for the filenames, ace_mem_map_temp_1 is the longest
    if (ACE::get_temp_dir (test_file, MAXPATHLEN - 18) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Temporary path too long\n")),
                          -1);

    // Copy the temp directory to the other variables
    ACE_OS::strcpy (temp_file1, test_file);
    ACE_OS::strcpy (temp_file2, test_file);

    // Add the filenames to the end
    ACE_OS::strcat (test_file,
                    ACE_TEXT ("ace_mem_map_test"));
    ACE_OS::strcat (temp_file1,
                    ACE_TEXT ("ace_mem_map_temp_1"));
    ACE_OS::strcat (temp_file2,
                    ACE_TEXT ("ace_mem_map_temp_2"));

    // First create a test file to work on
    if (create_test_file (test_file, LINE_LENGTH, NUM_LINES) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Create test file failed\n")),
                          -1);
    ACE_Mem_Map mmap;

    // First memory map the test file
    if (mmap.map (test_file) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%n: %p\n%a"),
                           ACE_TEXT ("mmap")),
                          -1);

    // Now create a temporary file for intermediate processing
    ACE_HANDLE temp_file_handle = ACE_OS::open (temp_file1,
                                  O_RDWR | O_TRUNC | O_CREAT,
                                  ACE_DEFAULT_FILE_PERMS);

    if (temp_file_handle == ACE_INVALID_HANDLE)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Open failed\n")),
                          -1);

    // Reverse the original file and write the output to the temporary
    // file.
    reverse_file (temp_file_handle,
                  (char *) mmap.addr (),
                  mmap.size ());

    ACE_OS::close (temp_file_handle);

    ACE_Mem_Map temp_mmap;

    // Now memory map the temporary file
    if (temp_mmap.map (temp_file1) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%n: %p\n%a"),
                           ACE_TEXT ("mmap")),
                          -1);

    if ((temp_file_handle = ACE_OS::open (temp_file2,
                                          O_RDWR | O_TRUNC | O_CREAT,
                                          ACE_DEFAULT_FILE_PERMS))
            == ACE_INVALID_HANDLE)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Open failed\n")), -1);

    // Now reverse the temporary file and write everything to the second
    // temporary file.
    reverse_file (temp_file_handle,
                  (char *) temp_mmap.addr (),
                  temp_mmap.size ());

    ACE_OS::close (temp_file_handle);

    // Memory map the second temporary file
    ACE_Mem_Map temp_mmap2;

    if (temp_mmap2.map (temp_file2) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%n: %p\n%a"),
                           ACE_TEXT ("mmap")),
                          -1);

    // Now do a memcmp -- the orig file and the second temporary file
    // should be identical.
    ACE_ASSERT (ACE_OS::memcmp (temp_mmap2.addr (),
                                mmap.addr (),
                                mmap.size ()) == 0);

    // Delete the test file
    mmap.remove ();

    // Delete ACE_TEMP_TEST_FILE
    temp_mmap.remove ();

    // Delete ACE_TEMP_TEST_FILE_2
    temp_mmap2.remove ();

#else /* !ACE_LACKS_MMAP */

    ACE_ERROR ((LM_INFO,
                ACE_TEXT ("mmap is not supported on this platform\n")));

#endif /* !ACE_LACKS_MMAP */

    ACE_END_TEST;
    return 0;
}
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  parse_args (argc, argv);
  ACE_INET_Addr sa (port_number, host_name);
  void *cp;
  char buf[BUFSIZ];
  int n;
  ACE_SOCK_CODgram dc;

  if (dc.open (sa, ACE_Addr::sap_any) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open"),
                      -1);

  // First send the name of the file as a datagram.

  iovec iov[2];

  iov[0].iov_base = (char *) "filename: ";
  iov[0].iov_len  = 11;
  iov[1].iov_base = (char *) file_name;
  iov[1].iov_len  = ACE_OS::strlen (file_name);

  if (dc.send (iov, 2) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      -1);

  ACE_SOCK_Stream sc;
  ACE_SOCK_Connector con;

  if (con.connect (sc, sa) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "connect"),
                      -1);

  ACE_Mem_Map mmap (file_name);

  if (mmap (cp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "mmap"),
                      -1);

  // Next, send the file's contents.

  if (sc.send_n (cp, mmap.size ()) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send_urg"),
                      -1);

  if (sc.close_writer () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close_writer"),
                      -1);

  if ((n = sc.recv_n (buf, sizeof buf)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "recv"),
                      -1);
  else
    ACE_OS::write (ACE_STDOUT, buf, n);

  return 0;
}