1 #include "tao/HTTP_Parser.h"
3 #if (TAO_HAS_HTTP_PARSER == 1)
5 #include "tao/HTTP_Client.h"
7 #include "tao/Object.h"
8 #include "tao/SystemException.h"
10 #include "ace/Read_Buffer.h"
11 #include "ace/Malloc_Base.h"
12 #include "ace/Log_Msg.h"
13 #include "ace/OS_NS_stdio.h"
14 #include "ace/OS_NS_string.h"
15 #include "ace/CORBA_macros.h"
17 static const ACE_TCHAR file_prefix
[] = ACE_TEXT ("http:");
19 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
22 TAO_HTTP_Parser::match_prefix (const char *nior_string
) const
24 ACE_TString ior_string
= ACE_TEXT_CHAR_TO_TCHAR (nior_string
);
25 return (ACE_OS::strncmp (ior_string
.c_str (),
27 sizeof (::file_prefix
) - 1) == 0);
31 TAO_HTTP_Parser::parse_string (const char *nior
,
34 // Skip the prefix, we know it is there because this method in only
35 // called if <match_prefix> returns 1.
36 ACE_TString ior
= ACE_TEXT_CHAR_TO_TCHAR (nior
);
37 const ACE_TCHAR
*http_url
=
38 ior
.c_str () + sizeof (::file_prefix
) + 1;
40 ACE_TCHAR
*hostname
= nullptr;
41 ACE_TCHAR
*filename
= nullptr;
42 const ACE_TCHAR
*ptr
= nullptr;
45 if (http_url
[0] == '/')
47 filename
= ACE_OS::strdup (http_url
);
51 ptr
= ACE_OS::strstr (http_url
, ACE_TEXT (":"));
53 port
= ACE_OS::atoi (ptr
+ 1);
55 ptr
= ACE_OS::strstr (http_url
, ACE_TEXT ("/"));
61 size_t const host_len
= ptr
- http_url
;
62 ACE_NEW_RETURN (hostname
, ACE_TCHAR
[host_len
+ 1], nullptr );
63 ACE_OS::strncpy (hostname
, http_url
, host_len
);
64 hostname
[host_len
] = '\0';
65 ptr
= ACE_OS::strstr (ptr
, ACE_TEXT ("/"));
68 filename
= ACE_OS::strdup(ptr
);
78 ACE_Message_Block
* mb
= nullptr;
84 TAO_HTTP_Client client
;
86 if (TAO_debug_level
> 4)
88 TAOLIB_DEBUG ((LM_DEBUG
,
89 ACE_TEXT ("TAO (%P|%t) - HTTP_Parser::parse_string, getting IOR from <%s> <%s> <%d>\n"),
90 hostname
, filename
, port
));
94 if (client
.open (filename
,
103 ACE_OS::free (filename
);
106 if (client
.read (mb
) <= 0)
112 // We get multiple message blocks back, concatenate them to
115 for (ACE_Message_Block
* curr
= mb
; curr
!= nullptr; curr
= curr
->cont ())
116 string
+= curr
->rd_ptr();
118 return orb
->string_to_object (string
.c_str());
121 ACE_STATIC_SVC_DEFINE (TAO_HTTP_Parser
,
122 ACE_TEXT ("HTTP_Parser"),
124 &ACE_SVC_NAME (TAO_HTTP_Parser
),
125 ACE_Service_Type::DELETE_THIS
|
126 ACE_Service_Type::DELETE_OBJ
,
129 ACE_FACTORY_DEFINE (TAO
, TAO_HTTP_Parser
)
131 TAO_END_VERSIONED_NAMESPACE_DECL
134 #endif /* TAO_HAS_HTTP_PARSER == 1 */