예제 #1
0
void dav_request_execute(DavServer *server, DavRequest *request) {
	dav_response_clear(server, request);

	/* check url */
	if (0 == request->url_path->len) {
		dav_response_error(server, request, 400);
		return;
	}

	if ('/' != request->url_path->str[0]) {
		/* only the OPTIONS method allows an url not starting with "/", and it must be "*", nothing else */
		if ('*' != request->url_path->str[0] || 1 != request->url_path->len || DAV_OPTIONS != request->method) {
			dav_response_error(server, request, 400);
			return;
		}
	}

	switch (request->method) {
	case DAV_OPTIONS:
		request_options(server, request);
		break;
	case DAV_PROPFIND:
		request_propfind(server, request);
		break;
	case DAV_PROPPATCH:
		request_proppatch(server, request);
		break;
	case DAV_MKCOL:
		request_mkcol(server, request);
		break;
	case DAV_GET:
	case DAV_HEAD:
		request_get_and_head(server, request);
		break;
	case DAV_DELETE:
		request_del(server, request);
		break;
	case DAV_PUT:
		request_put(server, request);
		break;
	case DAV_COPY:
	case DAV_MOVE:
	case DAV_LOCK:
	case DAV_UNLOCK:
		break;
	}

	if (0 == request->response_status) {
		dav_response_error(server, request, 500);
	}

	if (NULL != request->response_text) {
		g_string_append_printf(dav_response_get_header(server, request), "Content-Length: %" G_GOFFSET_FORMAT "\r\n", (goffset) request->response_text->len);
	} else if (NULL == request->response_filename && -1 == request->response_fd) {
		if (DAV_HEAD != request->method || 200 != request->response_status) {
			g_string_append_len(dav_response_get_header(server, request), CONST_STR_LEN("Content-Length: 0\r\n"));
		}
	}
}
int
main (int, char *[])
{
  ACE_MMAP_Memory_Pool_Options request_options (REQUEST_BASE_ADDR);

  // Create an adapter version of an allocator.
  ACE_Allocator_Adapter<TEST_MALLOC> *adapter_ptr = 0;
  ACE_NEW_RETURN (adapter_ptr,
                  ACE_Allocator_Adapter<TEST_MALLOC> ("request_file",
                                                      "request_lock",
                                                      &request_options),
                  1);

  auto_ptr <ACE_Allocator_Adapter<TEST_MALLOC> > shmem_request (adapter_ptr);
  ACE_MMAP_Memory_Pool_Options response_options (RESPONSE_BASE_ADDR);

  TEST_MALLOC *ptr = 0;
  // Create a non-adapter version of an allocator.
  ACE_NEW_RETURN (ptr,
                  TEST_MALLOC ("response_file",
                               "response_lock",
                               &response_options),
                  1);
  auto_ptr <TEST_MALLOC> shmem_response (ptr);
  void *data = 0;

  // If we find "foo" then we're running the "second" time, so we must
  // release the resources.
  if (shmem_request->find ("foo",
                           data) == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "%s\n",
                  data));
      shmem_request->remove ();
    }

  // This is the first time in, so we allocate the memory and bind it
  // to the name "foo".
  else
    {
      ACE_ALLOCATOR_RETURN (data,
                            shmem_request->malloc (ACE_OS::strlen (request_string) + 1),
                            1);
      ACE_OS::strcpy ((char *) data,
                      request_string);

      if (shmem_request->bind ("foo",
                               data) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "bind"),
                          1);
    }
  data = 0;

  // If we find "foo" then we're running the "second" time, so we must
  // release the resources.
  if (shmem_response->find ("foo",
                            data) == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "%s\n",
                  data));
      shmem_response->remove ();
      ACE_DEBUG ((LM_DEBUG,
                  "all shared memory resources have been released\n"));
    }

  // This is the first time in, so we allocate the memory and bind it
  // to the name "foo".
  else
    {
      ACE_ALLOCATOR_RETURN (data,
                            shmem_response->malloc (ACE_OS::strlen (response_string) + 1),
                            1);
      ACE_OS::strcpy ((char *) data,
                      response_string);

      if (shmem_response->bind ("foo",
                                data) == -1)
        ACE_ERROR ((LM_ERROR,
                    "%p\n",
                    "bind"));
      else
        ACE_DEBUG ((LM_DEBUG,
                    "Run again to see results and release resources.\n"));
    }

  return 0;
}