trunk: sync from 1.4.3

make & cmake fixes
This commit is contained in:
Marian Krivos 2012-02-04 17:03:09 +00:00
parent 0afd04898b
commit 8b70c37260
55 changed files with 2797 additions and 2229 deletions

View File

@ -1,14 +1,32 @@
// //
// ApacheApplication.h // ApacheApplication.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheApplication.h#2 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheApplication.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheChannel.h // ApacheChannel.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheChannel.h#1 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheChannel.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheConnector.h // ApacheConnector.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheConnector.h#3 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheConnector.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //
@ -47,7 +65,7 @@ public:
void setContentType(const std::string& mediaType); void setContentType(const std::string& mediaType);
/// Sets the response content type. /// Sets the response content type.
void redirect(const std::string& uri); void redirect(const std::string& uri, int status);
/// Redirects the response to the given uri. /// Redirects the response to the given uri.
void sendErrorResponse(int status); void sendErrorResponse(int status);

View File

@ -1,14 +1,32 @@
// //
// ApacheRequestHandlerFactory.h // ApacheRequestHandlerFactory.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheRequestHandlerFactory.h#5 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheRequestHandlerFactory.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheServerRequest.h // ApacheServerRequest.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheServerRequest.h#6 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheServerRequest.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheServerResponse.h // ApacheServerResponse.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheServerResponse.h#6 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheServerResponse.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //
@ -87,8 +105,10 @@ public:
/// Must not be called after send(), sendFile() /// Must not be called after send(), sendFile()
/// or redirect() has been called. /// or redirect() has been called.
void redirect(const std::string& uri); void redirect(const std::string& uri, Poco::Net::HTTPResponse::HTTPStatus status);
/// Sets the status code to 302 (Found) /// Sets the status code, which must be one of
/// HTTP_MOVED_PERMANENTLY (301), HTTP_FOUND (302),
/// or HTTP_SEE_OTHER (303),
/// and sets the "Location" header field /// and sets the "Location" header field
/// to the given URI, which according to /// to the given URI, which according to
/// the HTTP specification, must be absolute. /// the HTTP specification, must be absolute.

View File

@ -1,14 +1,32 @@
// //
// ApacheStream.h // ApacheStream.h
// //
// $Id: //poco/Main/ApacheConnector/include/ApacheStream.h#5 $ // $Id: //poco/1.4/ApacheConnector/include/ApacheStream.h#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// FormServer.cpp // FormServer.cpp
// //
// $Id: //poco/Main/ApacheConnector/samples/FormServer/src/FormServer.cpp#2 $ // $Id: //poco/1.4/ApacheConnector/samples/FormServer/src/FormServer.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// TimeServer.cpp // TimeServer.cpp
// //
// $Id: //poco/Main/ApacheConnector/samples/TimeServer/src/TimeServer.cpp#1 $ // $Id: //poco/1.4/ApacheConnector/samples/TimeServer/src/TimeServer.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheApplication.cpp // ApacheApplication.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheApplication.cpp#2 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheApplication.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheApplication.cpp // ApacheApplication.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheChannel.cpp#1 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheChannel.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheConnector.cpp // ApacheConnector.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheConnector.cpp#6 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheConnector.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //
@ -18,6 +36,7 @@
#include "ApacheServerResponse.h" #include "ApacheServerResponse.h"
#include "ApacheRequestHandlerFactory.h" #include "ApacheRequestHandlerFactory.h"
#include "Poco/Net/HTTPRequestHandler.h" #include "Poco/Net/HTTPRequestHandler.h"
#include <memory>
#include "httpd.h" #include "httpd.h"
#include "http_connection.h" #include "http_connection.h"
#include "http_config.h" #include "http_config.h"
@ -35,7 +54,6 @@
#include "http_request.h" #include "http_request.h"
#include "util_filter.h" #include "util_filter.h"
#include <memory>
using Poco::Net::HTTPServerRequest; using Poco::Net::HTTPServerRequest;
using Poco::Net::HTTPServerResponse; using Poco::Net::HTTPServerResponse;
@ -70,11 +88,11 @@ void ApacheRequestRec::writeResponse(const char* buffer, int length)
} }
void ApacheRequestRec::redirect(const std::string& uri) void ApacheRequestRec::redirect(const std::string& uri, int status)
{ {
apr_table_set(_pRec->headers_out, "Location", uri.c_str()); apr_table_set(_pRec->headers_out, "Location", uri.c_str());
_pRec->connection->keepalive = AP_CONN_CLOSE; _pRec->connection->keepalive = AP_CONN_CLOSE;
_pRec->status = 302; _pRec->status = status;
ap_set_keepalive(_pRec); ap_set_keepalive(_pRec);
ap_send_error_response(_pRec, 0); ap_send_error_response(_pRec, 0);
} }
@ -153,7 +171,7 @@ void ApacheRequestRec::copyHeaders(ApacheServerRequest& request)
void ApacheConnector::log(const char* file, int line, int level, int status, const char *text) void ApacheConnector::log(const char* file, int line, int level, int status, const char *text)
{ {
ap_log_error(file, line, level, 0, NULL, text); ap_log_error(file, line, level, 0, NULL, "%s", text);
} }

View File

@ -1,14 +1,32 @@
// //
// ApacheRequestHandlerFactory.cpp // ApacheRequestHandlerFactory.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheRequestHandlerFactory.cpp#8 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheRequestHandlerFactory.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheServerRequest.cpp // ApacheServerRequest.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheServerRequest.cpp#9 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheServerRequest.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -1,14 +1,32 @@
// //
// ApacheServerResponse.cpp // ApacheServerResponse.cpp
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheServerResponse.cpp#8 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheServerResponse.cpp#3 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //
@ -102,7 +120,7 @@ void ApacheServerResponse::sendBuffer(const void* pBuffer, std::size_t length)
} }
void ApacheServerResponse::redirect(const std::string& uri) void ApacheServerResponse::redirect(const std::string& uri, HTTPStatus status)
{ {
poco_assert (!_pStream); poco_assert (!_pStream);
@ -110,7 +128,7 @@ void ApacheServerResponse::redirect(const std::string& uri)
try try
{ {
_pApacheRequest->redirect(uri); _pApacheRequest->redirect(uri, status);
} }
catch (Poco::Exception&) catch (Poco::Exception&)
{ {

View File

@ -1,14 +1,32 @@
// //
// ApacheStream.h // ApacheStream.h
// //
// $Id: //poco/Main/ApacheConnector/src/ApacheStream.cpp#9 $ // $Id: //poco/1.4/ApacheConnector/src/ApacheStream.cpp#2 $
// //
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// All rights reserved. // and Contributors.
// //
// This is unpublished proprietary source code of Applied Informatics. // Permission is hereby granted, free of charge, to any person or organization
// The contents of this file may not be disclosed to third parties, // obtaining a copy of the software and accompanying documentation covered by
// copied or duplicated in any form, in whole or in part. // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// //

View File

@ -17,7 +17,7 @@ SET(PROJECT_VERSION ${COMPLETE_VERSION})
if(NOT MSVC_IDE) if(NOT MSVC_IDE)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release" FORCE) "Choose the type of build, options are: None Debug Release" FORCE)
endif() endif()
message(STATUS "Setting Poco build type - ${CMAKE_BUILD_TYPE}") message(STATUS "Setting Poco build type - ${CMAKE_BUILD_TYPE}")

View File

@ -41,7 +41,7 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/err.h> #include <openssl/err.h>
#if SSLEAY_VERSION_NUMBER >= 0x0907000L #if OPENSSL_VERSION_NUMBER >= 0x0907000L
#include <openssl/conf.h> #include <openssl/conf.h>
#endif #endif
@ -61,7 +61,7 @@ int OpenSSLInitializer::_rc(0);
OpenSSLInitializer::OpenSSLInitializer() OpenSSLInitializer::OpenSSLInitializer()
{ {
initialize(); initialize();
} }

View File

@ -16,7 +16,7 @@ objects = Binder Extractor SessionImpl Connector \
MySQLStatementImpl ResultMetadata MySQLException \ MySQLStatementImpl ResultMetadata MySQLException \
SessionHandle StatementExecutor SessionHandle StatementExecutor
target = PocoMySQL target = PocoDataMySQL
target_version = $(LIBVERSION) target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation target_libs = PocoData PocoFoundation

View File

@ -44,7 +44,7 @@ objects = Binder ConnectionHandle Connector EnvironmentHandle \
Extractor ODBCMetaColumn ODBCException ODBCStatementImpl \ Extractor ODBCMetaColumn ODBCException ODBCStatementImpl \
Parameter Preparator SessionImpl TypeInfo Unicode Utility Parameter Preparator SessionImpl TypeInfo Unicode Utility
target = PocoODBC target = PocoDataODBC
target_version = $(LIBVERSION) target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation target_libs = PocoData PocoFoundation

View File

@ -17,7 +17,7 @@ objects = Binder Extractor SessionImpl Connector \
SQLiteException SQLiteStatementImpl Utility \ SQLiteException SQLiteStatementImpl Utility \
sqlite3 sqlite3
target = PocoSQLite target = PocoDataSQLite
target_version = $(LIBVERSION) target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation target_libs = PocoData PocoFoundation

View File

@ -60,6 +60,10 @@
// #define POCO_NO_SHAREDMEMORY // #define POCO_NO_SHAREDMEMORY
// Define if no <locale> header is available (such as on WinCE)
// #define POCO_NO_LOCALE
// Define to desired default thread stack size // Define to desired default thread stack size
// Zero means OS default // Zero means OS default
#ifndef POCO_THREAD_STACK_SIZE #ifndef POCO_THREAD_STACK_SIZE

View File

@ -52,12 +52,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osVersionImpl(); static std::string osDisplayNameImpl();
static std::string osArchitectureImpl(); static std::string osVersionImpl();
static std::string nodeNameImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();

View File

@ -59,20 +59,20 @@ std::string Foundation_API format(const std::string& fmt, const Any& value);
/// ///
/// The format string can consist of any sequence of characters; certain /// The format string can consist of any sequence of characters; certain
/// characters have a special meaning. Characters without a special meaning /// characters have a special meaning. Characters without a special meaning
/// are copied verbatim to the result. A percent sign (%) marks the beginning /// are copied verbatim to the result. A percent sign (%) marks the beginning
/// of a format specification. Format specifications have the following syntax: /// of a format specification. Format specifications have the following syntax:
/// ///
/// %[<index>][<flags>][<width>][.<precision>][<modifier>]<type> /// %[<index>][<flags>][<width>][.<precision>][<modifier>]<type>
/// ///
/// Index, flags, width, precision and prefix are optional. The only required part of /// Index, flags, width, precision and prefix are optional. The only required part of
/// the format specification, apart from the percent sign, is the type. /// the format specification, apart from the percent sign, is the type.
/// ///
/// The optional index argument has the format "[<n>]" and allows to /// The optional index argument has the format "[<n>]" and allows to
/// address an argument by its zero-based position (see the example below). /// address an argument by its zero-based position (see the example below).
/// ///
/// Following are valid type specifications and their meaning: /// Following are valid type specifications and their meaning:
/// ///
/// * b boolean (true = 1, false = 0) /// * b boolean (true = 1, false = 0)
/// * c character /// * c character
/// * d signed decimal integer /// * d signed decimal integer
/// * i signed decimal integer /// * i signed decimal integer
@ -86,13 +86,13 @@ std::string Foundation_API format(const std::string& fmt, const Any& value);
/// * s std::string /// * s std::string
/// * z std::size_t /// * z std::size_t
/// ///
/// The following flags are supported: /// The following flags are supported:
/// ///
/// * - left align the result within the given field width /// * - left align the result within the given field width
/// * + prefix the output value with a sign (+ or -) if the output value is of a signed type /// * + prefix the output value with a sign (+ or -) if the output value is of a signed type
/// * 0 if width is prefixed with 0, zeros are added until the minimum width is reached /// * 0 if width is prefixed with 0, zeros are added until the minimum width is reached
/// * # For o, x, X, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively; /// * # For o, x, X, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively;
/// for e, E, f, the # flag forces the output value to contain a decimal point in all cases. /// for e, E, f, the # flag forces the output value to contain a decimal point in all cases.
/// ///
/// The following modifiers are supported: /// The following modifiers are supported:
/// ///
@ -106,20 +106,23 @@ std::string Foundation_API format(const std::string& fmt, const Any& value);
/// If the number of characters in the output value is less than the specified width, blanks or /// If the number of characters in the output value is less than the specified width, blanks or
/// leading zeros are added, according to the specified flags (-, +, 0). /// leading zeros are added, according to the specified flags (-, +, 0).
/// ///
/// Precision is a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters /// Precision is a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters
/// to be printed, the number of decimal places, or the number of significant digits. /// to be printed, the number of decimal places, or the number of significant digits.
/// ///
/// Throws a BadCastException if an argument does not correspond to the type of its format specification.
/// Throws an InvalidArgumentException if an argument index is out of range. /// Throws an InvalidArgumentException if an argument index is out of range.
/// ///
/// Starting with release 1.4.3, an argument that does not match the format
/// specifier no longer results in a BadCastException. The string [ERRFMT] is
/// written to the result string instead.
///
/// If there are more format specifiers than values, the format specifiers without a corresponding value /// If there are more format specifiers than values, the format specifiers without a corresponding value
/// are copied verbatim to output. /// are copied verbatim to output.
/// ///
/// If there are more values than format specifiers, the superfluous values are ignored. /// If there are more values than format specifiers, the superfluous values are ignored.
/// ///
/// Usage Examples: /// Usage Examples:
/// std::string s1 = format("The answer to life, the universe, and everything is %d", 42); /// std::string s1 = format("The answer to life, the universe, and everything is %d", 42);
/// std::string s2 = format("second: %[1]d, first: %[0]d", 1, 2); /// std::string s2 = format("second: %[1]d, first: %[0]d", 1, 2);
std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2); std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2);
std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3); std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3);

View File

@ -337,16 +337,16 @@ public:
static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2, const std::string& arg3); static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2, const std::string& arg3);
/// Replaces all occurences of $<n> in fmt with the string given in arg<n> and /// Replaces all occurences of $<n> in fmt with the string given in arg<n> and
/// returns the result. To include a dollar sign in the result string, /// returns the result. To include a dollar sign in the result string,
/// specify two dollar signs ($$) in the format string. /// specify two dollar signs ($$) in the format string.
static void formatDump(std::string& message, const void* buffer, std::size_t length); static void formatDump(std::string& message, const void* buffer, std::size_t length);
/// Creates a hex-dump of the given buffer and appends it to the /// Creates a hex-dump of the given buffer and appends it to the
/// given message string. /// given message string.
static void setLevel(const std::string& name, int level); static void setLevel(const std::string& name, int level);
/// Sets the given log level on all loggers that are /// Sets the given log level on all loggers that are
/// descendants of the Logger with the given name. /// descendants of the Logger with the given name.
static void setChannel(const std::string& name, Channel* pChannel); static void setChannel(const std::string& name, Channel* pChannel);
/// Attaches the given Channel to all loggers that are /// Attaches the given Channel to all loggers that are
@ -396,10 +396,27 @@ public:
/// Loggers. /// Loggers.
static void names(std::vector<std::string>& names); static void names(std::vector<std::string>& names);
/// Fills the given vector with the names /// Fills the given vector with the names
/// of all currently defined loggers. /// of all currently defined loggers.
static const std::string ROOT; /// The name of the root logger (""). static int parseLevel(const std::string& level);
/// Parses a symbolic log level from a string and
/// returns the resulting numeric level.
///
/// Valid symbolic levels are:
/// - none (turns off logging)
/// - fatal
/// - critical
/// - error
/// - warning
/// - notice
/// - information
/// - debug
/// - trace
///
/// The level is not case sensitive.
static const std::string ROOT; /// The name of the root logger ("").
protected: protected:
typedef std::map<std::string, Logger*> LoggerMap; typedef std::map<std::string, Logger*> LoggerMap;
@ -408,12 +425,12 @@ protected:
~Logger(); ~Logger();
void log(const std::string& text, Message::Priority prio); void log(const std::string& text, Message::Priority prio);
void log(const std::string& text, Message::Priority prio, const char* file, int line); void log(const std::string& text, Message::Priority prio, const char* file, int line);
static std::string format(const std::string& fmt, int argc, std::string argv[]); static std::string format(const std::string& fmt, int argc, std::string argv[]);
static Logger& parent(const std::string& name); static Logger& parent(const std::string& name);
static void add(Logger* pLogger); static void add(Logger* pLogger);
static Logger* find(const std::string& name); static Logger* find(const std::string& name);
private: private:
Logger(); Logger();

View File

@ -151,11 +151,17 @@ public:
/// int rc = ph.wait(); /// int rc = ph.wait();
static int wait(const ProcessHandle& handle); static int wait(const ProcessHandle& handle);
/// Waits for the process specified by handle to terminate /// Waits for the process specified by handle to terminate
/// and returns the exit code of the process. /// and returns the exit code of the process.
static void kill(PID pid); static void kill(const ProcessHandle& handle);
/// Kills the process with the given pid. /// Kills the process specified by handle.
///
/// This is preferable on Windows where process IDs
/// may be reused.
static void kill(PID pid);
/// Kills the process with the given pid.
static void requestTermination(PID pid); static void requestTermination(PID pid);
/// Requests termination of the process with the give PID. /// Requests termination of the process with the give PID.

View File

@ -72,11 +72,12 @@ public:
typedef pid_t PIDImpl; typedef pid_t PIDImpl;
typedef std::vector<std::string> ArgsImpl; typedef std::vector<std::string> ArgsImpl;
static PIDImpl idImpl(); static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime); static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe); static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
static void killImpl(PIDImpl pid); static void killImpl(const ProcessHandleImpl& handle);
static void requestTerminationImpl(PIDImpl pid); static void killImpl(PIDImpl pid);
static void requestTerminationImpl(PIDImpl pid);
}; };

View File

@ -74,11 +74,12 @@ public:
typedef int PIDImpl; typedef int PIDImpl;
typedef std::vector<std::string> ArgsImpl; typedef std::vector<std::string> ArgsImpl;
static PIDImpl idImpl(); static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime); static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe); static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
static void killImpl(PIDImpl pid); static void killImpl(const ProcessHandleImpl& handle);
static void requestTerminationImpl(PIDImpl pid); static void killImpl(PIDImpl pid);
static void requestTerminationImpl(PIDImpl pid);
}; };

View File

@ -56,10 +56,11 @@ class Foundation_API ProcessHandleImpl: public RefCountedObject
{ {
public: public:
ProcessHandleImpl(HANDLE _hProcess, UInt32 pid); ProcessHandleImpl(HANDLE _hProcess, UInt32 pid);
~ProcessHandleImpl(); ~ProcessHandleImpl();
UInt32 id() const; UInt32 id() const;
int wait() const; HANDLE process() const;
int wait() const;
private: private:
HANDLE _hProcess; HANDLE _hProcess;
@ -76,12 +77,13 @@ public:
typedef UInt32 PIDImpl; typedef UInt32 PIDImpl;
typedef std::vector<std::string> ArgsImpl; typedef std::vector<std::string> ArgsImpl;
static PIDImpl idImpl(); static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime); static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe); static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
static void killImpl(PIDImpl pid); static void killImpl(const ProcessHandleImpl& handle);
static void requestTerminationImpl(PIDImpl pid); static void killImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid); static void requestTerminationImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid);
}; };

View File

@ -56,10 +56,11 @@ class Foundation_API ProcessHandleImpl: public RefCountedObject
{ {
public: public:
ProcessHandleImpl(HANDLE _hProcess, UInt32 pid); ProcessHandleImpl(HANDLE _hProcess, UInt32 pid);
~ProcessHandleImpl(); ~ProcessHandleImpl();
UInt32 id() const; UInt32 id() const;
int wait() const; HANDLE process() const;
int wait() const;
private: private:
HANDLE _hProcess; HANDLE _hProcess;
@ -76,12 +77,13 @@ public:
typedef UInt32 PIDImpl; typedef UInt32 PIDImpl;
typedef std::vector<std::string> ArgsImpl; typedef std::vector<std::string> ArgsImpl;
static PIDImpl idImpl(); static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime); static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe); static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
static void killImpl(PIDImpl pid); static void killImpl(const ProcessHandleImpl& handle);
static void requestTerminationImpl(PIDImpl pid); static void killImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid); static void requestTerminationImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid);
}; };

View File

@ -56,10 +56,11 @@ class Foundation_API ProcessHandleImpl: public RefCountedObject
{ {
public: public:
ProcessHandleImpl(HANDLE _hProcess, UInt32 pid); ProcessHandleImpl(HANDLE _hProcess, UInt32 pid);
~ProcessHandleImpl(); ~ProcessHandleImpl();
UInt32 id() const; UInt32 id() const;
int wait() const; HANDLE process() const;
int wait() const;
private: private:
HANDLE _hProcess; HANDLE _hProcess;
@ -76,12 +77,13 @@ public:
typedef UInt32 PIDImpl; typedef UInt32 PIDImpl;
typedef std::vector<std::string> ArgsImpl; typedef std::vector<std::string> ArgsImpl;
static PIDImpl idImpl(); static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime); static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe); static ProcessHandleImpl* launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
static void killImpl(PIDImpl pid); static void killImpl(const ProcessHandleImpl& handle);
static void requestTerminationImpl(PIDImpl pid); static void killImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid); static void requestTerminationImpl(PIDImpl pid);
static std::string terminationEventName(PIDImpl pid);
}; };

View File

@ -48,20 +48,27 @@ namespace Poco {
template <class M> template <class M>
class ScopedLock class ScopedLock
/// A class that simplifies thread synchronization /// A class that simplifies thread synchronization
/// with a mutex. /// with a mutex.
/// The constructor accepts a Mutex and locks it. /// The constructor accepts a Mutex (and optionally
/// The destructor unlocks the mutex. /// a timeout value in milliseconds) and locks it.
/// The destructor unlocks the mutex.
{ {
public: public:
inline ScopedLock(M& mutex): _mutex(mutex) explicit ScopedLock(M& mutex): _mutex(mutex)
{ {
_mutex.lock(); _mutex.lock();
} }
inline ~ScopedLock()
{ ScopedLock(M& mutex, long milliseconds): _mutex(mutex)
_mutex.unlock(); {
} _mutex.lock(milliseconds);
}
~ScopedLock()
{
_mutex.unlock();
}
private: private:
M& _mutex; M& _mutex;
@ -74,22 +81,28 @@ private:
template <class M> template <class M>
class ScopedLockWithUnlock class ScopedLockWithUnlock
/// A class that simplifies thread synchronization /// A class that simplifies thread synchronization
/// with a mutex. /// with a mutex.
/// The constructor accepts a Mutex and locks it. /// The constructor accepts a Mutex (and optionally
/// The destructor unlocks the mutex. /// a timeout value in milliseconds) and locks it.
/// The unlock() member function allows for manual /// The destructor unlocks the mutex.
/// unlocking of the mutex. /// The unlock() member function allows for manual
/// unlocking of the mutex.
{ {
public: public:
ScopedLockWithUnlock(M& mutex): _pMutex(&mutex) explicit ScopedLockWithUnlock(M& mutex): _pMutex(&mutex)
{ {
_pMutex->lock(); _pMutex->lock();
} }
~ScopedLockWithUnlock() ScopedLockWithUnlock(M& mutex, long milliseconds): _pMutex(&mutex)
{ {
unlock(); _pMutex->lock(milliseconds);
}
~ScopedLockWithUnlock()
{
unlock();
} }
void unlock() void unlock()

View File

@ -360,9 +360,11 @@ typedef uLong FAR uLongf;
# define Z_HAVE_UNISTD_H # define Z_HAVE_UNISTD_H
#endif #endif
#ifndef _WIN32_WCE
#ifdef STDC #ifdef STDC
# include <sys/types.h> /* for off_t */ # include <sys/types.h> /* for off_t */
#endif #endif
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even

View File

@ -38,7 +38,9 @@
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/Ascii.h" #include "Poco/Ascii.h"
#include <sstream> #include <sstream>
#if !defined(POCO_NO_LOCALE)
#include <locale> #include <locale>
#endif
#include <cstddef> #include <cstddef>
@ -167,72 +169,81 @@ namespace
void formatOne(std::string& result, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt, std::vector<Any>::const_iterator& itVal) void formatOne(std::string& result, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt, std::vector<Any>::const_iterator& itVal)
{ {
std::ostringstream str; std::ostringstream str;
#if !defined(POCO_NO_LOCALE)
str.imbue(std::locale::classic()); str.imbue(std::locale::classic());
parseFlags(str, itFmt, endFmt); #endif
parseWidth(str, itFmt, endFmt); try
parsePrec(str, itFmt, endFmt); {
char mod = parseMod(itFmt, endFmt); parseFlags(str, itFmt, endFmt);
if (itFmt != endFmt) parseWidth(str, itFmt, endFmt);
{ parsePrec(str, itFmt, endFmt);
char type = *itFmt++; char mod = parseMod(itFmt, endFmt);
prepareFormat(str, type); if (itFmt != endFmt)
switch (type)
{ {
case 'b': char type = *itFmt++;
str << AnyCast<bool>(*itVal++); prepareFormat(str, type);
break; switch (type)
case 'c':
str << AnyCast<char>(*itVal++);
break;
case 'd':
case 'i':
switch (mod)
{ {
case 'l': str << AnyCast<long>(*itVal++); break; case 'b':
case 'L': str << AnyCast<Int64>(*itVal++); break; str << AnyCast<bool>(*itVal++);
case 'h': str << AnyCast<short>(*itVal++); break; break;
case '?': writeAnyInt(str, *itVal++); break; case 'c':
default: str << AnyCast<int>(*itVal++); break; str << AnyCast<char>(*itVal++);
} break;
break; case 'd':
case 'o': case 'i':
case 'u': switch (mod)
case 'x': {
case 'X': case 'l': str << AnyCast<long>(*itVal++); break;
switch (mod) case 'L': str << AnyCast<Int64>(*itVal++); break;
{ case 'h': str << AnyCast<short>(*itVal++); break;
case 'l': str << AnyCast<unsigned long>(*itVal++); break; case '?': writeAnyInt(str, *itVal++); break;
case 'L': str << AnyCast<UInt64>(*itVal++); break; default: str << AnyCast<int>(*itVal++); break;
case 'h': str << AnyCast<unsigned short>(*itVal++); break; }
case '?': writeAnyInt(str, *itVal++); break; break;
default: str << AnyCast<unsigned>(*itVal++); break; case 'o':
} case 'u':
break; case 'x':
case 'e': case 'X':
case 'E': switch (mod)
case 'f': {
switch (mod) case 'l': str << AnyCast<unsigned long>(*itVal++); break;
{ case 'L': str << AnyCast<UInt64>(*itVal++); break;
case 'l': str << AnyCast<long double>(*itVal++); break; case 'h': str << AnyCast<unsigned short>(*itVal++); break;
case 'L': str << AnyCast<long double>(*itVal++); break; case '?': writeAnyInt(str, *itVal++); break;
case 'h': str << AnyCast<float>(*itVal++); break; default: str << AnyCast<unsigned>(*itVal++); break;
default: str << AnyCast<double>(*itVal++); break; }
} break;
break; case 'e':
case 's': case 'E':
str << RefAnyCast<std::string>(*itVal++); case 'f':
break; switch (mod)
case 'z': {
str << AnyCast<std::size_t>(*itVal++); case 'l': str << AnyCast<long double>(*itVal++); break;
break; case 'L': str << AnyCast<long double>(*itVal++); break;
case 'I': case 'h': str << AnyCast<float>(*itVal++); break;
case 'D': default: str << AnyCast<double>(*itVal++); break;
default: }
str << type; break;
} case 's':
} str << RefAnyCast<std::string>(*itVal++);
result.append(str.str()); break;
} case 'z':
str << AnyCast<std::size_t>(*itVal++);
break;
case 'I':
case 'D':
default:
str << type;
}
}
}
catch (Poco::BadCastException&)
{
str << "[ERRFMT]";
}
result.append(str.str());
}
} }

View File

@ -39,6 +39,7 @@
#include "Poco/LoggingRegistry.h" #include "Poco/LoggingRegistry.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/NumberFormatter.h" #include "Poco/NumberFormatter.h"
#include "Poco/String.h"
namespace Poco { namespace Poco {
@ -83,26 +84,7 @@ void Logger::setLevel(int level)
void Logger::setLevel(const std::string& level) void Logger::setLevel(const std::string& level)
{ {
if (level == "none") setLevel(parseLevel(level));
setLevel(0);
else if (level == "fatal")
setLevel(Message::PRIO_FATAL);
else if (level == "critical")
setLevel(Message::PRIO_CRITICAL);
else if (level == "error")
setLevel(Message::PRIO_ERROR);
else if (level == "warning")
setLevel(Message::PRIO_WARNING);
else if (level == "notice")
setLevel(Message::PRIO_NOTICE);
else if (level == "information")
setLevel(Message::PRIO_INFORMATION);
else if (level == "debug")
setLevel(Message::PRIO_DEBUG);
else if (level == "trace")
setLevel(Message::PRIO_TRACE);
else
throw InvalidArgumentException("Not a valid log level", level);
} }
@ -449,6 +431,31 @@ Logger& Logger::parent(const std::string& name)
} }
int Logger::parseLevel(const std::string& level)
{
if (icompare(level, "none") == 0)
return 0;
else if (icompare(level, "fatal") == 0)
return Message::PRIO_FATAL;
else if (icompare(level, "critical") == 0)
return Message::PRIO_CRITICAL;
else if (icompare(level, "error") == 0)
return Message::PRIO_ERROR;
else if (icompare(level, "warning") == 0)
return Message::PRIO_WARNING;
else if (icompare(level, "notice") == 0)
return Message::PRIO_NOTICE;
else if (icompare(level, "information") == 0)
return Message::PRIO_INFORMATION;
else if (icompare(level, "debug") == 0)
return Message::PRIO_DEBUG;
else if (icompare(level, "trace") == 0)
return Message::PRIO_TRACE;
else
throw InvalidArgumentException("Not a valid log level", level);
}
class AutoLoggerShutdown class AutoLoggerShutdown
{ {
public: public:

View File

@ -37,7 +37,9 @@
#include "Poco/NumberFormatter.h" #include "Poco/NumberFormatter.h"
#include "Poco/MemoryStream.h" #include "Poco/MemoryStream.h"
#include <iomanip> #include <iomanip>
#if !defined(POCO_NO_LOCALE)
#include <locale> #include <locale>
#endif
#include <cstdio> #include <cstdio>
#include <cctype> #include <cctype>
@ -361,9 +363,11 @@ void NumberFormatter::append(std::string& str, float value)
{ {
char buffer[64]; char buffer[64];
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer)); Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
#if !defined(POCO_NO_LOCALE)
ostr.imbue(std::locale::classic()); ostr.imbue(std::locale::classic());
#endif
ostr << std::setprecision(8) << value; ostr << std::setprecision(8) << value;
str.append(buffer, ostr.charsWritten()); str.append(buffer, static_cast<std::string::size_type>(ostr.charsWritten()));
} }
@ -371,33 +375,39 @@ void NumberFormatter::append(std::string& str, double value)
{ {
char buffer[64]; char buffer[64];
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer)); Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
#if !defined(POCO_NO_LOCALE)
ostr.imbue(std::locale::classic()); ostr.imbue(std::locale::classic());
#endif
ostr << std::setprecision(16) << value; ostr << std::setprecision(16) << value;
str.append(buffer, ostr.charsWritten()); str.append(buffer, static_cast<std::string::size_type>(ostr.charsWritten()));
} }
void NumberFormatter::append(std::string& str, double value, int precision) void NumberFormatter::append(std::string& str, double value, int precision)
{ {
poco_assert (precision >= 0 && precision < 32); poco_assert (precision >= 0 && precision < 32);
char buffer[64]; char buffer[64];
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer)); Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
#if !defined(POCO_NO_LOCALE)
ostr.imbue(std::locale::classic()); ostr.imbue(std::locale::classic());
#endif
ostr << std::fixed << std::showpoint << std::setprecision(precision) << value; ostr << std::fixed << std::showpoint << std::setprecision(precision) << value;
str.append(buffer, ostr.charsWritten()); str.append(buffer, static_cast<std::string::size_type>(ostr.charsWritten()));
} }
void NumberFormatter::append(std::string& str, double value, int width, int precision) void NumberFormatter::append(std::string& str, double value, int width, int precision)
{ {
poco_assert (width > 0 && width < 64 && precision >= 0 && precision < width); poco_assert (width > 0 && width < 64 && precision >= 0 && precision < width);
char buffer[64]; char buffer[64];
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer)); Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
#if !defined(POCO_NO_LOCALE)
ostr.imbue(std::locale::classic()); ostr.imbue(std::locale::classic());
#endif
ostr << std::fixed << std::showpoint << std::setw(width) << std::setprecision(precision) << value; ostr << std::fixed << std::showpoint << std::setw(width) << std::setprecision(precision) << value;
str.append(buffer, ostr.charsWritten()); str.append(buffer, static_cast<std::string::size_type>(ostr.charsWritten()));
} }

View File

@ -1,7 +1,7 @@
// //
// NumberParser.cpp // NumberParser.cpp
// //
// $Id: //poco/svn/Foundation/src/NumberParser.cpp#2 $ // $Id: //poco/1.4/Foundation/src/NumberParser.cpp#4 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@ -38,15 +38,19 @@
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/MemoryStream.h" #include "Poco/MemoryStream.h"
#include "Poco/String.h" #include "Poco/String.h"
#ifdef POCO_LOCALE
#include <locale> #include <locale>
#endif
#include <cstdio> #include <cstdio>
#include <cctype> #include <cctype>
#if defined(_MSC_VER) #if defined(POCO_LONG_IS_64_BIT)
#define I64_FMT "I64" #define I64_FMT "l"
#elif defined(_MSC_VER)
#define I64_FMT "I64"
#elif defined(__APPLE__) #elif defined(__APPLE__)
#define I64_FMT "q" #define I64_FMT "q"
#else #else
#define I64_FMT "ll" #define I64_FMT "ll"
#endif #endif
@ -175,10 +179,12 @@ double NumberParser::parseFloat(const std::string& s)
bool NumberParser::tryParseFloat(const std::string& s, double& value) bool NumberParser::tryParseFloat(const std::string& s, double& value)
{ {
Poco::MemoryInputStream istr(s.data(), s.size()); Poco::MemoryInputStream istr(s.data(), s.size());
istr.imbue(std::locale::classic()); #if !defined(POCO_NO_LOCALE)
istr >> value; istr.imbue(std::locale::classic());
return istr.eof() && !istr.fail(); #endif
istr >> value;
return istr.eof() && !istr.fail();
} }

View File

@ -127,9 +127,15 @@ int Process::wait(const ProcessHandle& handle)
} }
void Process::kill(const ProcessHandle& handle)
{
killImpl(*handle._pImpl);
}
void Process::kill(PID pid) void Process::kill(PID pid)
{ {
killImpl(pid); killImpl(pid);
} }

View File

@ -169,9 +169,15 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
} }
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
{
killImpl(handle.id());
}
void ProcessImpl::killImpl(PIDImpl pid) void ProcessImpl::killImpl(PIDImpl pid)
{ {
if (kill(pid, SIGKILL) != 0) if (kill(pid, SIGKILL) != 0)
{ {
switch (errno) switch (errno)
{ {

View File

@ -125,9 +125,15 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
} }
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
{
killImpl(handle.id());
}
void ProcessImpl::killImpl(PIDImpl pid) void ProcessImpl::killImpl(PIDImpl pid)
{ {
if (kill(pid, SIGKILL) != 0) if (kill(pid, SIGKILL) != 0)
{ {
switch (errno) switch (errno)
{ {

View File

@ -89,9 +89,15 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
} }
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
{
throw Poco::NotImplementedException("Process::kill()");
}
void ProcessImpl::killImpl(PIDImpl pid) void ProcessImpl::killImpl(PIDImpl pid)
{ {
throw Poco::NotImplementedException("Process::kill()"); throw Poco::NotImplementedException("Process::kill()");
} }

View File

@ -66,9 +66,15 @@ UInt32 ProcessHandleImpl::id() const
} }
HANDLE ProcessHandleImpl::process() const
{
return _hProcess;
}
int ProcessHandleImpl::wait() const int ProcessHandleImpl::wait() const
{ {
DWORD rc = WaitForSingleObject(_hProcess, INFINITE); DWORD rc = WaitForSingleObject(_hProcess, INFINITE);
if (rc != WAIT_OBJECT_0) if (rc != WAIT_OBJECT_0)
throw SystemException("Wait failed for process", NumberFormatter::format(_pid)); throw SystemException("Wait failed for process", NumberFormatter::format(_pid));
@ -176,9 +182,20 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
} }
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
{
if (TerminateProcess(handle.process(), 0) == 0)
{
CloseHandle(handle.process());
throw SystemException("cannot kill process");
}
CloseHandle(handle.process());
}
void ProcessImpl::killImpl(PIDImpl pid) void ProcessImpl::killImpl(PIDImpl pid)
{ {
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid); HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (hProc) if (hProc)
{ {
if (TerminateProcess(hProc, 0) == 0) if (TerminateProcess(hProc, 0) == 0)

View File

@ -67,9 +67,15 @@ UInt32 ProcessHandleImpl::id() const
} }
HANDLE ProcessHandleImpl::process() const
{
return _hProcess;
}
int ProcessHandleImpl::wait() const int ProcessHandleImpl::wait() const
{ {
DWORD rc = WaitForSingleObject(_hProcess, INFINITE); DWORD rc = WaitForSingleObject(_hProcess, INFINITE);
if (rc != WAIT_OBJECT_0) if (rc != WAIT_OBJECT_0)
throw SystemException("Wait failed for process", NumberFormatter::format(_pid)); throw SystemException("Wait failed for process", NumberFormatter::format(_pid));
@ -180,9 +186,20 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
} }
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
{
if (TerminateProcess(handle.process(), 0) == 0)
{
CloseHandle(handle.process());
throw SystemException("cannot kill process");
}
CloseHandle(handle.process());
}
void ProcessImpl::killImpl(PIDImpl pid) void ProcessImpl::killImpl(PIDImpl pid)
{ {
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid); HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (hProc) if (hProc)
{ {
if (TerminateProcess(hProc, 0) == 0) if (TerminateProcess(hProc, 0) == 0)

View File

@ -360,9 +360,11 @@ typedef uLong FAR uLongf;
# define Z_HAVE_UNISTD_H # define Z_HAVE_UNISTD_H
#endif #endif
#ifndef _WIN32_WCE
#ifdef STDC #ifdef STDC
# include <sys/types.h> /* for off_t */ # include <sys/types.h> /* for off_t */
#endif #endif
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even

View File

@ -20,7 +20,8 @@ objects = \
HTTPFixedLengthStream HTTPServerRequest HTTPServerRequestImpl MultipartWriter StreamSocketImpl \ HTTPFixedLengthStream HTTPServerRequest HTTPServerRequestImpl MultipartWriter StreamSocketImpl \
HTTPHeaderStream HTTPServerResponse HTTPServerResponseImpl NameValueCollection TCPServer \ HTTPHeaderStream HTTPServerResponse HTTPServerResponseImpl NameValueCollection TCPServer \
HTTPMessage HTTPServerSession NetException TCPServerConnection HTTPBufferAllocator \ HTTPMessage HTTPServerSession NetException TCPServerConnection HTTPBufferAllocator \
HTTPRequest HTTPSession HTTPSessionInstantiator HTTPSessionFactory NetworkInterface TCPServerConnectionFactory \ HTTPCredentials HTTPDigestCredentials HTTPAuthenticationParams TCPServerConnectionFactory \
HTTPRequest HTTPSession HTTPSessionInstantiator HTTPSessionFactory NetworkInterface \
HTTPRequestHandler HTTPStream HTTPIOStream ServerSocket TCPServerDispatcher \ HTTPRequestHandler HTTPStream HTTPIOStream ServerSocket TCPServerDispatcher \
HTTPRequestHandlerFactory HTTPStreamFactory ServerSocketImpl TCPServerParams \ HTTPRequestHandlerFactory HTTPStreamFactory ServerSocketImpl TCPServerParams \
QuotedPrintableEncoder QuotedPrintableDecoder StringPartSource \ QuotedPrintableEncoder QuotedPrintableDecoder StringPartSource \
@ -29,7 +30,8 @@ objects = \
MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \ MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \
RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \ RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \
ICMPSocket ICMPSocketImpl ICMPv4PacketImpl \ ICMPSocket ICMPSocketImpl ICMPv4PacketImpl \
RemoteSyslogChannel RemoteSyslogListener SMTPChannel RemoteSyslogChannel RemoteSyslogListener SMTPChannel \
WebSocket WebSocketImpl
target = PocoNet target = PocoNet
target_version = $(LIBVERSION) target_version = $(LIBVERSION)

View File

@ -269,12 +269,20 @@ protected:
/// proxy username and password have been set. /// proxy username and password have been set.
void proxyAuthenticateImpl(HTTPRequest& request); void proxyAuthenticateImpl(HTTPRequest& request);
/// Sets the proxy credentials (Proxy-Authorization header), if /// Sets the proxy credentials (Proxy-Authorization header), if
/// proxy username and password have been set. /// proxy username and password have been set.
StreamSocket proxyConnect();
/// Sends a CONNECT request to the proxy server and returns
/// a StreamSocket for the resulting connection.
void proxyTunnel();
/// Calls proxyConnect() and attaches the resulting StreamSocket
/// to the HTTPClientSession.
private: private:
std::string _host; std::string _host;
Poco::UInt16 _port; Poco::UInt16 _port;
std::string _proxyHost; std::string _proxyHost;
Poco::UInt16 _proxyPort; Poco::UInt16 _proxyPort;
std::string _proxyUsername; std::string _proxyUsername;
@ -287,8 +295,10 @@ private:
std::ostream* _pRequestStream; std::ostream* _pRequestStream;
std::istream* _pResponseStream; std::istream* _pResponseStream;
HTTPClientSession(const HTTPClientSession&); HTTPClientSession(const HTTPClientSession&);
HTTPClientSession& operator = (const HTTPClientSession&); HTTPClientSession& operator = (const HTTPClientSession&);
friend class WebSocket;
}; };

View File

@ -5,7 +5,7 @@
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPCredentials // Module: HTTPCredentials
// //
// Definition of the HTTPCredentials class. // Definition of the HTTPCredentials class.
// //
@ -58,91 +58,107 @@ class HTTPResponse;
class Net_API HTTPCredentials class Net_API HTTPCredentials
/// This is a utility class for working with HTTP /// This is a utility class for working with HTTP
/// authentication (basic or digest) in HTTPRequest objects. /// authentication (basic or digest) in HTTPRequest objects.
/// ///
/// Usage is as follows: /// Usage is as follows:
/// First, create a HTTPCredentials object containing /// First, create a HTTPCredentials object containing
/// the username and password. /// the username and password.
/// Poco::Net::HTTPCredentials creds("user", "s3cr3t"); /// Poco::Net::HTTPCredentials creds("user", "s3cr3t");
/// ///
/// Second, send the HTTP request with Poco::Net::HTTPClientSession. /// Second, send the HTTP request with Poco::Net::HTTPClientSession.
/// Poco::Net::HTTPClientSession session("pocoproject.org"); /// Poco::Net::HTTPClientSession session("pocoproject.org");
/// Poco::Net::HTTPRequest request(HTTPRequest::HTTP_GET, "/index.html", HTTPMessage::HTTP_1_1); /// Poco::Net::HTTPRequest request(HTTPRequest::HTTP_GET, "/index.html", HTTPMessage::HTTP_1_1);
/// session.sendRequest(request); /// session.sendRequest(request);
/// Poco::Net::HTTPResponse; /// Poco::Net::HTTPResponse;
/// std::istream& istr = session.receiveResponse(response); /// std::istream& istr = session.receiveResponse(response);
/// ///
/// If the server responds with a 401 status, authenticate the /// If the server responds with a 401 status, authenticate the
/// request and resend it: /// request and resend it:
/// if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED) /// if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
/// { /// {
/// creds.authenticate(request, response); /// creds.authenticate(request, response);
/// session.sendRequest(request); /// session.sendRequest(request);
/// ... /// ...
/// } /// }
/// ///
/// To perform multiple authenticated requests, call updateAuthInfo() /// To perform multiple authenticated requests, call updateAuthInfo()
/// instead of authenticate() on subsequent requests. /// instead of authenticate() on subsequent requests.
/// creds.updateAuthInfo(request); /// creds.updateAuthInfo(request);
/// session.sendRequest(request); /// session.sendRequest(request);
/// ... /// ...
/// ///
/// Note: Do not forget to read the entire response stream from the 401 response /// Note: Do not forget to read the entire response stream from the 401 response
/// before sending the authenticated request, otherwise there may be /// before sending the authenticated request, otherwise there may be
/// problems if a persistent connection is used. /// problems if a persistent connection is used.
{ {
public: public:
HTTPCredentials(); HTTPCredentials();
/// Creates an empty HTTPCredentials object. /// Creates an empty HTTPCredentials object.
HTTPCredentials(const std::string& username, const std::string& password); HTTPCredentials(const std::string& username, const std::string& password);
/// Creates an HTTPCredentials object with the given username and password. /// Creates an HTTPCredentials object with the given username and password.
~HTTPCredentials(); ~HTTPCredentials();
/// Destroys the HTTPCredentials. /// Destroys the HTTPCredentials.
void fromUserInfo(const std::string& userInfo);
/// Parses username:password string and sets username and password of
/// the credentials object.
/// Throws SyntaxException on invalid user information.
void fromURI(const URI& uri);
/// Extracts username and password from the given URI and sets username
/// and password of the credentials object.
/// Does nothing if URI has no user info part.
void setUsername(const std::string& username); void setUsername(const std::string& username);
/// Sets the username. /// Sets the username.
const std::string& getUsername() const; const std::string& getUsername() const;
/// Returns the username. /// Returns the username.
void setPassword(const std::string& password); void setPassword(const std::string& password);
/// Sets the password. /// Sets the password.
const std::string& getPassword() const; const std::string& getPassword() const;
/// Returns the password. /// Returns the password.
void authenticate(HTTPRequest& request, const HTTPResponse& response); void authenticate(HTTPRequest& request, const HTTPResponse& response);
/// Inspects authenticate header of the response, initializes /// Inspects authenticate header of the response, initializes
/// the internal state (in case of digest authentication) and /// the internal state (in case of digest authentication) and
/// adds required information to the given HTTPRequest. /// adds required information to the given HTTPRequest.
/// ///
/// Does nothing if there is no authentication header in the /// Does nothing if there is no authentication header in the
/// HTTPResponse. /// HTTPResponse.
void updateAuthInfo(HTTPRequest& request); void updateAuthInfo(HTTPRequest& request);
/// Updates internal state (in case of digest authentication) and /// Updates internal state (in case of digest authentication) and
/// replaces authentication information in the request accordingly. /// replaces authentication information in the request accordingly.
static bool isBasicCredentials(const std::string& header); static bool isBasicCredentials(const std::string& header);
/// Returns true if authentication header is for Basic authentication. /// Returns true if authentication header is for Basic authentication.
static bool isDigestCredentials(const std::string& header); static bool isDigestCredentials(const std::string& header);
/// Returns true if authentication header is for Digest authentication. /// Returns true if authentication header is for Digest authentication.
static bool hasBasicCredentials(const HTTPRequest& request);
/// Returns true if Authorization with Basic credentials header is present in the request.
static bool hasDigestCredentials(const HTTPRequest& request);
/// Returns true if Authorization with Digest credentials header is present in the request.
static void extractCredentials(const std::string& userInfo, std::string& username, std::string& password); static void extractCredentials(const std::string& userInfo, std::string& username, std::string& password);
/// Extracts username and password from user:password information string. /// Extracts username and password from user:password information string.
static void extractCredentials(const Poco::URI& uri, std::string& username, std::string& password); static void extractCredentials(const Poco::URI& uri, std::string& username, std::string& password);
/// Extracts username and password from the given URI (e.g.: "http://user:pass@sample.com/secret"). /// Extracts username and password from the given URI (e.g.: "http://user:pass@sample.com/secret").
private: private:
HTTPCredentials(const HTTPCredentials&); HTTPCredentials(const HTTPCredentials&);
HTTPCredentials& operator = (const HTTPCredentials&); HTTPCredentials& operator = (const HTTPCredentials&);
HTTPDigestCredentials _digest; HTTPDigestCredentials _digest;
}; };
@ -151,25 +167,25 @@ private:
// //
inline void HTTPCredentials::setUsername(const std::string& username) inline void HTTPCredentials::setUsername(const std::string& username)
{ {
_digest.setUsername(username); _digest.setUsername(username);
} }
inline const std::string& HTTPCredentials::getUsername() const inline const std::string& HTTPCredentials::getUsername() const
{ {
return _digest.getUsername(); return _digest.getUsername();
} }
inline void HTTPCredentials::setPassword(const std::string& password) inline void HTTPCredentials::setPassword(const std::string& password)
{ {
_digest.setPassword(password); _digest.setPassword(password);
} }
inline const std::string& HTTPCredentials::getPassword() const inline const std::string& HTTPCredentials::getPassword() const
{ {
return _digest.getPassword(); return _digest.getPassword();
} }

View File

@ -70,6 +70,7 @@ POCO_DECLARE_EXCEPTION(Net_API, SMTPException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException) POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException)
POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException) POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, HTMLFormException, NetException) POCO_DECLARE_EXCEPTION(Net_API, HTMLFormException, NetException)
POCO_DECLARE_EXCEPTION(Net_API, WebSocketException, NetException)
} } // namespace Poco::Net } } // namespace Poco::Net

View File

@ -415,4 +415,30 @@ void HTTPClientSession::proxyAuthenticateImpl(HTTPRequest& request)
} }
StreamSocket HTTPClientSession::proxyConnect()
{
HTTPClientSession proxySession(getProxyHost(), getProxyPort());
proxySession.setTimeout(getTimeout());
SocketAddress targetAddress(getHost(), getPort());
HTTPRequest proxyRequest(HTTPRequest::HTTP_CONNECT, targetAddress.toString(), HTTPMessage::HTTP_1_1);
HTTPResponse proxyResponse;
proxyRequest.set("Proxy-Connection", "keep-alive");
proxyRequest.set("Host", getHost());
proxyAuthenticateImpl(proxyRequest);
proxySession.setKeepAlive(true);
proxySession.sendRequest(proxyRequest);
proxySession.receiveResponse(proxyResponse);
if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK)
throw HTTPException("Cannot establish proxy connection", proxyResponse.getReason());
return proxySession.detachSocket();
}
void HTTPClientSession::proxyTunnel()
{
StreamSocket ss = proxyConnect();
attachSocket(ss);
}
} } // namespace Poco::Net } } // namespace Poco::Net

View File

@ -5,7 +5,7 @@
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPCredentials // Module: HTTPCredentials
// //
// Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru). // Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru).
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. // Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
@ -42,6 +42,7 @@
#include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/NetException.h" #include "Poco/Net/NetException.h"
#include "Poco/String.h" #include "Poco/String.h"
#include "Poco/Ascii.h"
#include "Poco/URI.h" #include "Poco/URI.h"
@ -58,7 +59,7 @@ HTTPCredentials::HTTPCredentials()
HTTPCredentials::HTTPCredentials(const std::string& username, const std::string& password): HTTPCredentials::HTTPCredentials(const std::string& username, const std::string& password):
_digest(username, password) _digest(username, password)
{ {
} }
@ -68,77 +69,113 @@ HTTPCredentials::~HTTPCredentials()
} }
void HTTPCredentials::fromUserInfo(const std::string& userInfo)
{
std::string username;
std::string password;
extractCredentials(userInfo, username, password);
setUsername(username);
setPassword(password);
// TODO: Reset digest state?
}
void HTTPCredentials::fromURI(const URI& uri)
{
std::string username;
std::string password;
extractCredentials(uri, username, password);
setUsername(username);
setPassword(password);
// TODO: Reset digest state?
}
void HTTPCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response) void HTTPCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response)
{ {
for (HTTPResponse::ConstIterator iter = response.find("WWW-Authenticate"); iter != response.end(); ++iter) for (HTTPResponse::ConstIterator iter = response.find("WWW-Authenticate"); iter != response.end(); ++iter)
{ {
if (isBasicCredentials(iter->second)) if (isBasicCredentials(iter->second))
{ {
HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request);
return; return;
} }
else if (isDigestCredentials(iter->second)) else if (isDigestCredentials(iter->second))
{ {
_digest.authenticate(request, HTTPAuthenticationParams(iter->second.substr(7))); _digest.authenticate(request, HTTPAuthenticationParams(iter->second.substr(7)));
return; return;
} }
} }
} }
void HTTPCredentials::updateAuthInfo(HTTPRequest& request) void HTTPCredentials::updateAuthInfo(HTTPRequest& request)
{ {
if (request.has("Authorization")) if (request.has(HTTPRequest::AUTHORIZATION))
{ {
const std::string& authorization = request.get("Authorization"); const std::string& authorization = request.get(HTTPRequest::AUTHORIZATION);
if (isBasicCredentials(authorization)) if (isBasicCredentials(authorization))
{ {
HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request);
} }
else if (isDigestCredentials(authorization)) else if (isDigestCredentials(authorization))
{ {
_digest.updateAuthInfo(request); _digest.updateAuthInfo(request);
} }
} }
} }
bool HTTPCredentials::isBasicCredentials(const std::string& header) bool HTTPCredentials::isBasicCredentials(const std::string& header)
{ {
return icompare(header, 0, 6, "Basic ") == 0; return icompare(header, 0, 5, "Basic") == 0 && (header.size() > 5 ? Poco::Ascii::isSpace(header[5]) : true);
} }
bool HTTPCredentials::isDigestCredentials(const std::string& header) bool HTTPCredentials::isDigestCredentials(const std::string& header)
{ {
return icompare(header, 0, 7, "Digest ") == 0; return icompare(header, 0, 6, "Digest") == 0 && (header.size() > 6 ? Poco::Ascii::isSpace(header[6]) : true);
}
bool HTTPCredentials::hasBasicCredentials(const HTTPRequest& request)
{
return request.has(HTTPRequest::AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::AUTHORIZATION));
}
bool HTTPCredentials::hasDigestCredentials(const HTTPRequest& request)
{
return request.has(HTTPRequest::AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::AUTHORIZATION));
} }
void HTTPCredentials::extractCredentials(const std::string& userInfo, std::string& username, std::string& password) void HTTPCredentials::extractCredentials(const std::string& userInfo, std::string& username, std::string& password)
{ {
const std::string::size_type p = userInfo.find(':'); const std::string::size_type p = userInfo.find(':');
if (p != std::string::npos) if (p != std::string::npos)
{ {
username.assign(userInfo, 0, p); username.assign(userInfo, 0, p);
password.assign(userInfo, p + 1, std::string::npos); password.assign(userInfo, p + 1, std::string::npos);
} }
else else
{ {
username.assign(userInfo); username.assign(userInfo);
password.clear(); password.clear();
} }
} }
void HTTPCredentials::extractCredentials(const Poco::URI& uri, std::string& username, std::string& password) void HTTPCredentials::extractCredentials(const Poco::URI& uri, std::string& username, std::string& password)
{ {
if (!uri.getUserInfo().empty()) if (!uri.getUserInfo().empty())
{ {
extractCredentials(uri.getUserInfo(), username, password); extractCredentials(uri.getUserInfo(), username, password);
} }
} }

View File

@ -5,7 +5,7 @@
// //
// Library: Net // Library: Net
// Package: HTTP // Package: HTTP
// Module: HTTPDigestCredentials // Module: HTTPDigestCredentials
// //
// Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru). // Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru).
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. // Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
@ -49,39 +49,39 @@
namespace namespace
{ {
std::string digest(Poco::DigestEngine& engine, std::string digest(Poco::DigestEngine& engine,
const std::string& a, const std::string& a,
const std::string& b, const std::string& b,
const std::string& c = std::string(), const std::string& c = std::string(),
const std::string& d = std::string(), const std::string& d = std::string(),
const std::string& e = std::string(), const std::string& e = std::string(),
const std::string& f = std::string()) const std::string& f = std::string())
{ {
engine.reset(); engine.reset();
engine.update(a); engine.update(a);
engine.update(':'); engine.update(':');
engine.update(b); engine.update(b);
if (!c.empty()) if (!c.empty())
{ {
engine.update(':'); engine.update(':');
engine.update(c); engine.update(c);
if (!d.empty()) if (!d.empty())
{ {
engine.update(':'); engine.update(':');
engine.update(d); engine.update(d);
engine.update(':'); engine.update(':');
engine.update(e); engine.update(e);
engine.update(':'); engine.update(':');
engine.update(f); engine.update(f);
} }
} }
return Poco::DigestEngine::digestToHex(engine.digest()); return Poco::DigestEngine::digestToHex(engine.digest());
} }
std::string formatNonceCounter(int counter) std::string formatNonceCounter(int counter)
{ {
return Poco::NumberFormatter::formatHex(counter, 8); return Poco::NumberFormatter::formatHex(counter, 8);
} }
} }
@ -113,8 +113,8 @@ HTTPDigestCredentials::HTTPDigestCredentials()
HTTPDigestCredentials::HTTPDigestCredentials(const std::string& username, const std::string& password): HTTPDigestCredentials::HTTPDigestCredentials(const std::string& username, const std::string& password):
_username(username), _username(username),
_password(password) _password(password)
{ {
} }
@ -126,67 +126,67 @@ HTTPDigestCredentials::~HTTPDigestCredentials()
void HTTPDigestCredentials::setUsername(const std::string& username) void HTTPDigestCredentials::setUsername(const std::string& username)
{ {
_username = username; _username = username;
} }
void HTTPDigestCredentials::setPassword(const std::string& password) void HTTPDigestCredentials::setPassword(const std::string& password)
{ {
_password = password; _password = password;
} }
void HTTPDigestCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response) void HTTPDigestCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response)
{ {
authenticate(request, HTTPAuthenticationParams(response)); authenticate(request, HTTPAuthenticationParams(response));
} }
void HTTPDigestCredentials::authenticate(HTTPRequest& request, const HTTPAuthenticationParams& responseAuthParams) void HTTPDigestCredentials::authenticate(HTTPRequest& request, const HTTPAuthenticationParams& responseAuthParams)
{ {
createAuthParams(request, responseAuthParams); createAuthParams(request, responseAuthParams);
request.setCredentials(SCHEME, _requestAuthParams.toString()); request.setCredentials(SCHEME, _requestAuthParams.toString());
} }
void HTTPDigestCredentials::updateAuthInfo(HTTPRequest& request) void HTTPDigestCredentials::updateAuthInfo(HTTPRequest& request)
{ {
updateAuthParams(request); updateAuthParams(request);
request.setCredentials(SCHEME, _requestAuthParams.toString()); request.setCredentials(SCHEME, _requestAuthParams.toString());
} }
std::string HTTPDigestCredentials::createNonce() std::string HTTPDigestCredentials::createNonce()
{ {
Poco::FastMutex::ScopedLock lock(_nonceMutex); Poco::FastMutex::ScopedLock lock(_nonceMutex);
MD5Engine md5; MD5Engine md5;
Timestamp::TimeVal now = Timestamp().epochMicroseconds(); Timestamp::TimeVal now = Timestamp().epochMicroseconds();
md5.update(&_nonceCounter, sizeof(_nonceCounter)); md5.update(&_nonceCounter, sizeof(_nonceCounter));
md5.update(&now, sizeof(now)); md5.update(&now, sizeof(now));
++_nonceCounter; ++_nonceCounter;
return DigestEngine::digestToHex(md5.digest()); return DigestEngine::digestToHex(md5.digest());
} }
void HTTPDigestCredentials::createAuthParams(const HTTPRequest& request, const HTTPAuthenticationParams& responseAuthParams) void HTTPDigestCredentials::createAuthParams(const HTTPRequest& request, const HTTPAuthenticationParams& responseAuthParams)
{ {
// Not implemented: "domain" auth parameter and integrity protection. // Not implemented: "domain" auth parameter and integrity protection.
if (!responseAuthParams.has(NONCE_PARAM) || !responseAuthParams.has(REALM_PARAM)) if (!responseAuthParams.has(NONCE_PARAM) || !responseAuthParams.has(REALM_PARAM))
throw InvalidArgumentException("Invalid HTTP authentication parameters"); throw InvalidArgumentException("Invalid HTTP authentication parameters");
const std::string& algorithm = responseAuthParams.get(ALGORITHM_PARAM, DEFAULT_ALGORITHM); const std::string& algorithm = responseAuthParams.get(ALGORITHM_PARAM, DEFAULT_ALGORITHM);
if (icompare(algorithm, DEFAULT_ALGORITHM) != 0) if (icompare(algorithm, DEFAULT_ALGORITHM) != 0)
throw NotImplementedException("Unsupported digest algorithm", algorithm); throw NotImplementedException("Unsupported digest algorithm", algorithm);
const std::string& nonce = responseAuthParams.get(NONCE_PARAM); const std::string& nonce = responseAuthParams.get(NONCE_PARAM);
const std::string& qop = responseAuthParams.get(QOP_PARAM, DEFAULT_QOP); const std::string& qop = responseAuthParams.get(QOP_PARAM, DEFAULT_QOP);
const std::string& realm = responseAuthParams.getRealm(); const std::string& realm = responseAuthParams.getRealm();
_requestAuthParams.clear(); _requestAuthParams.clear();
_requestAuthParams.set(USERNAME_PARAM, _username); _requestAuthParams.set(USERNAME_PARAM, _username);
@ -194,104 +194,108 @@ void HTTPDigestCredentials::createAuthParams(const HTTPRequest& request, const H
_requestAuthParams.set(NONCE_PARAM, nonce); _requestAuthParams.set(NONCE_PARAM, nonce);
_requestAuthParams.setRealm(realm); _requestAuthParams.setRealm(realm);
if (responseAuthParams.has(OPAQUE_PARAM)) if (responseAuthParams.has(OPAQUE_PARAM))
{ {
_requestAuthParams.set(OPAQUE_PARAM, responseAuthParams.get(OPAQUE_PARAM)); _requestAuthParams.set(OPAQUE_PARAM, responseAuthParams.get(OPAQUE_PARAM));
} }
if (qop.empty()) if (qop.empty())
{ {
MD5Engine engine; updateAuthParams(request);
const std::string ha1 = digest(engine, _username, realm, _password);
const std::string ha2 = digest(engine, request.getMethod(), request.getURI());
_requestAuthParams.set(RESPONSE_PARAM, digest(engine, ha1, nonce, ha2));
} }
else else
{ {
Poco::StringTokenizer tok(qop, ",", Poco::StringTokenizer::TOK_TRIM); Poco::StringTokenizer tok(qop, ",", Poco::StringTokenizer::TOK_TRIM);
bool qopSupported = false; bool qopSupported = false;
for (Poco::StringTokenizer::Iterator it = tok.begin(); it != tok.end(); ++it) for (Poco::StringTokenizer::Iterator it = tok.begin(); it != tok.end(); ++it)
{ {
if (icompare(*it, AUTH_PARAM) == 0) if (icompare(*it, AUTH_PARAM) == 0)
{ {
qopSupported = true; qopSupported = true;
_requestAuthParams.set(CNONCE_PARAM, createNonce()); _requestAuthParams.set(CNONCE_PARAM, createNonce());
_requestAuthParams.set(QOP_PARAM, *it); _requestAuthParams.set(QOP_PARAM, *it);
updateAuthParams(request); updateAuthParams(request);
break; break;
} }
} }
if (!qopSupported) if (!qopSupported)
NotImplementedException("Unsupported QoP requested", qop); throw NotImplementedException("Unsupported QoP requested", qop);
} }
} }
void HTTPDigestCredentials::updateAuthParams(const HTTPRequest& request) void HTTPDigestCredentials::updateAuthParams(const HTTPRequest& request)
{ {
MD5Engine engine;
const std::string& qop = _requestAuthParams.get(QOP_PARAM, DEFAULT_QOP); const std::string& qop = _requestAuthParams.get(QOP_PARAM, DEFAULT_QOP);
if (icompare(qop, AUTH_PARAM) == 0) const std::string& realm = _requestAuthParams.getRealm();
{ const std::string& nonce = _requestAuthParams.get(NONCE_PARAM);
MD5Engine engine;
const std::string& nonce = _requestAuthParams.get(NONCE_PARAM); _requestAuthParams.set(URI_PARAM, request.getURI());
const std::string& realm = _requestAuthParams.getRealm();
if (qop.empty())
{
const std::string ha1 = digest(engine, _username, realm, _password);
const std::string ha2 = digest(engine, request.getMethod(), request.getURI());
_requestAuthParams.set(RESPONSE_PARAM, digest(engine, ha1, nonce, ha2));
}
else if (icompare(qop, AUTH_PARAM) == 0)
{
const std::string& cnonce = _requestAuthParams.get(CNONCE_PARAM); const std::string& cnonce = _requestAuthParams.get(CNONCE_PARAM);
const std::string ha1 = digest(engine, _username, realm, _password); const std::string ha1 = digest(engine, _username, realm, _password);
const std::string ha2 = digest(engine, request.getMethod(), request.getURI()); const std::string ha2 = digest(engine, request.getMethod(), request.getURI());
const std::string nc = formatNonceCounter(updateNonceCounter(nonce)); const std::string nc = formatNonceCounter(updateNonceCounter(nonce));
_requestAuthParams.set(NC_PARAM, nc); _requestAuthParams.set(NC_PARAM, nc);
_requestAuthParams.set(RESPONSE_PARAM, digest(engine, ha1, nonce, nc, cnonce, qop, ha2)); _requestAuthParams.set(RESPONSE_PARAM, digest(engine, ha1, nonce, nc, cnonce, qop, ha2));
} }
} }
bool HTTPDigestCredentials::verifyAuthInfo(const HTTPRequest& request) const bool HTTPDigestCredentials::verifyAuthInfo(const HTTPRequest& request) const
{ {
HTTPAuthenticationParams params(request); HTTPAuthenticationParams params(request);
return verifyAuthParams(request, params); return verifyAuthParams(request, params);
} }
bool HTTPDigestCredentials::verifyAuthParams(const HTTPRequest& request, const HTTPAuthenticationParams& params) const bool HTTPDigestCredentials::verifyAuthParams(const HTTPRequest& request, const HTTPAuthenticationParams& params) const
{ {
const std::string& nonce = params.get(NONCE_PARAM); const std::string& nonce = params.get(NONCE_PARAM);
const std::string& realm = params.getRealm(); const std::string& realm = params.getRealm();
const std::string& qop = params.get(QOP_PARAM, DEFAULT_QOP); const std::string& qop = params.get(QOP_PARAM, DEFAULT_QOP);
std::string response; std::string response;
MD5Engine engine; MD5Engine engine;
if (qop.empty()) if (qop.empty())
{ {
const std::string ha1 = digest(engine, _username, realm, _password); const std::string ha1 = digest(engine, _username, realm, _password);
const std::string ha2 = digest(engine, request.getMethod(), request.getURI()); const std::string ha2 = digest(engine, request.getMethod(), request.getURI());
response = digest(engine, ha1, nonce, ha2); response = digest(engine, ha1, nonce, ha2);
} }
else if (icompare(qop, AUTH_PARAM) == 0) else if (icompare(qop, AUTH_PARAM) == 0)
{ {
const std::string& cnonce = params.get(CNONCE_PARAM); const std::string& cnonce = params.get(CNONCE_PARAM);
const std::string& nc = params.get(NC_PARAM); const std::string& nc = params.get(NC_PARAM);
const std::string ha1 = digest(engine, _username, realm, _password); const std::string ha1 = digest(engine, _username, realm, _password);
const std::string ha2 = digest(engine, request.getMethod(), request.getURI()); const std::string ha2 = digest(engine, request.getMethod(), request.getURI());
response = digest(engine, ha1, nonce, nc, cnonce, qop, ha2); response = digest(engine, ha1, nonce, nc, cnonce, qop, ha2);
} }
return response == params.get(RESPONSE_PARAM); return response == params.get(RESPONSE_PARAM);
} }
int HTTPDigestCredentials::updateNonceCounter(const std::string& nonce) int HTTPDigestCredentials::updateNonceCounter(const std::string& nonce)
{ {
NonceCounterMap::iterator iter = _nc.find(nonce); NonceCounterMap::iterator iter = _nc.find(nonce);
if (iter == _nc.end()) if (iter == _nc.end())
{ {
iter = _nc.insert(NonceCounterMap::value_type(nonce, 0)).first; iter = _nc.insert(NonceCounterMap::value_type(nonce, 0)).first;
} }
iter->second++; iter->second++;
return iter->second; return iter->second;
} }

View File

@ -67,6 +67,7 @@ POCO_IMPLEMENT_EXCEPTION(SMTPException, NetException, "SMTP Exception")
POCO_IMPLEMENT_EXCEPTION(POP3Exception, NetException, "POP3 Exception") POCO_IMPLEMENT_EXCEPTION(POP3Exception, NetException, "POP3 Exception")
POCO_IMPLEMENT_EXCEPTION(ICMPException, NetException, "ICMP Exception") POCO_IMPLEMENT_EXCEPTION(ICMPException, NetException, "ICMP Exception")
POCO_IMPLEMENT_EXCEPTION(HTMLFormException, NetException, "HTML Form Exception") POCO_IMPLEMENT_EXCEPTION(HTMLFormException, NetException, "HTML Form Exception")
POCO_IMPLEMENT_EXCEPTION(WebSocketException, NetException, "WebSocket Exception")
} } // namespace Poco::Net } } // namespace Poco::Net

View File

@ -299,14 +299,16 @@ void Application::stopOptionsProcessing()
int Application::run() int Application::run()
{ {
int rc = EXIT_SOFTWARE; int rc = EXIT_CONFIG;
initialize(*this); try
try {
{ initialize(*this);
rc = main(_args); rc = EXIT_SOFTWARE;
} rc = main(_args);
catch (Poco::Exception& exc) uninitialize();
{ }
catch (Poco::Exception& exc)
{
logger().log(exc); logger().log(exc);
} }
catch (std::exception& exc) catch (std::exception& exc)
@ -314,11 +316,10 @@ int Application::run()
logger().error(exc.what()); logger().error(exc.what());
} }
catch (...) catch (...)
{ {
logger().fatal("system exception"); logger().fatal("system exception");
} }
uninitialize(); return rc;
return rc;
} }
@ -368,13 +369,13 @@ void Application::processOptions()
while (it != _args.end() && !_stopOptionsProcessing) while (it != _args.end() && !_stopOptionsProcessing)
{ {
std::string name; std::string name;
std::string value; std::string value;
if (processor.process(*it, name, value)) if (processor.process(*it, name, value))
{ {
if (!name.empty()) // "--" option to end options processing or deferred argument if (!name.empty()) // "--" option to end options processing or deferred argument
{ {
handleOption(name, value); handleOption(name, value);
} }
it = _args.erase(it); it = _args.erase(it);
} }
else ++it; else ++it;

View File

@ -388,12 +388,12 @@ void ServerApplication::registerService()
else else
service.registerService(path, _displayName); service.registerService(path, _displayName);
if (_startup == "auto") if (_startup == "auto")
service.setStartup(WinService::SVC_AUTO_START); service.setStartup(WinService::SVC_AUTO_START);
else if (_startup == "manual") else if (_startup == "manual")
service.setStartup(WinService::SVC_MANUAL_START); service.setStartup(WinService::SVC_MANUAL_START);
if (!_description.empty()) if (!_description.empty())
service.setDescription(_description); service.setDescription(_description);
logger().information("The application has been successfully registered as a service."); logger().information("The application has been successfully registered as a service.");
} }
@ -428,19 +428,19 @@ void ServerApplication::defineOptions(OptionSet& options)
.required(false) .required(false)
.repeatable(false) .repeatable(false)
.argument("name") .argument("name")
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDisplayName))); .callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDisplayName)));
options.addOption( options.addOption(
Option("description", "", "Specify a description for the service (only with /registerService).") Option("description", "", "Specify a description for the service (only with /registerService).")
.required(false) .required(false)
.repeatable(false) .repeatable(false)
.argument("text") .argument("text")
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDescription))); .callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDescription)));
options.addOption( options.addOption(
Option("startup", "", "Specify the startup mode for the service (only with /registerService).") Option("startup", "", "Specify the startup mode for the service (only with /registerService).")
.required(false) .required(false)
.repeatable(false) .repeatable(false)
.argument("automatic|manual") .argument("automatic|manual")
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleStartup))); .callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleStartup)));
} }
@ -466,13 +466,13 @@ void ServerApplication::handleDisplayName(const std::string& name, const std::st
void ServerApplication::handleDescription(const std::string& name, const std::string& value) void ServerApplication::handleDescription(const std::string& name, const std::string& value)
{ {
_description = value; _description = value;
} }
void ServerApplication::handleStartup(const std::string& name, const std::string& value) void ServerApplication::handleStartup(const std::string& name, const std::string& value)
{ {
if (Poco::icompare(value, 4, std::string("auto")) == 0) if (Poco::icompare(value, 4, std::string("auto")) == 0)
_startup = "auto"; _startup = "auto";
else if (Poco::icompare(value, std::string("manual")) == 0) else if (Poco::icompare(value, std::string("manual")) == 0)
_startup = "manual"; _startup = "manual";
@ -496,20 +496,10 @@ int ServerApplication::run(int argc, char** argv)
} }
catch (Exception& exc) catch (Exception& exc)
{ {
logger().log(exc); logger().log(exc);
return EXIT_CONFIG; return EXIT_CONFIG;
} }
int rc = run(); return run();
try
{
uninitialize();
}
catch (Exception& exc)
{
logger().log(exc);
rc = EXIT_CONFIG;
}
return rc;
} }
@ -521,20 +511,10 @@ int ServerApplication::run(const std::vector<std::string>& args)
} }
catch (Exception& exc) catch (Exception& exc)
{ {
logger().log(exc); logger().log(exc);
return EXIT_CONFIG; return EXIT_CONFIG;
} }
int rc = run(); return run();
try
{
uninitialize();
}
catch (Exception& exc)
{
logger().log(exc);
rc = EXIT_CONFIG;
}
return rc;
} }
@ -547,20 +527,10 @@ int ServerApplication::run(int argc, wchar_t** argv)
} }
catch (Exception& exc) catch (Exception& exc)
{ {
logger().log(exc); logger().log(exc);
return EXIT_CONFIG; return EXIT_CONFIG;
} }
int rc = run(); return run();
try
{
uninitialize();
}
catch (Exception& exc)
{
logger().log(exc);
rc = EXIT_CONFIG;
}
return rc;
} }
#endif #endif

View File

@ -53,9 +53,35 @@ namespace Poco {
namespace Util { namespace Util {
namespace
{
class AutoHandle
{
public:
AutoHandle(HMODULE h):
_h(h)
{
}
~AutoHandle()
{
FreeLibrary(_h);
}
HMODULE handle()
{
return _h;
}
private:
HMODULE _h;
};
}
WinRegistryKey::WinRegistryKey(const std::string& key, bool readOnly, REGSAM extraSam): WinRegistryKey::WinRegistryKey(const std::string& key, bool readOnly, REGSAM extraSam):
_hKey(0), _hKey(0),
_readOnly(readOnly), _readOnly(readOnly),
_extraSam(extraSam) _extraSam(extraSam)
{ {
std::string::size_type pos = key.find('\\'); std::string::size_type pos = key.find('\\');
@ -266,17 +292,53 @@ void WinRegistryKey::deleteKey()
std::string subKey(_subKey); std::string subKey(_subKey);
subKey += "\\"; subKey += "\\";
subKey += *it; subKey += *it;
WinRegistryKey subRegKey(_hRootKey, subKey); WinRegistryKey subRegKey(_hRootKey, subKey);
subRegKey.deleteKey(); subRegKey.deleteKey();
} }
// NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later.
// We cannot call it directly as this would prevent the code running on Windows XP 32-bit.
// Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for
// its existence in ADVAPI32.DLL and call it indirectly.
#if defined(POCO_WIN32_UTF8) #if defined(POCO_WIN32_UTF8)
std::wstring usubKey; std::wstring usubKey;
Poco::UnicodeConverter::toUTF16(_subKey, usubKey); Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key()); typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
if (_extraSam != 0)
{
AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL"));
if (advAPI32.handle())
{
RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW"));
if (pRegDeleteKeyExW)
{
if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
throw NotFoundException(key());
return;
}
}
}
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key());
#else #else
if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS) typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved);
throw NotFoundException(key()); if (_extraSam != 0)
{
AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL"));
if (advAPI32.handle())
{
RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA"));
if (pRegDeleteKeyExA)
{
if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
throw NotFoundException(key());
return;
}
}
}
if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key());
#endif #endif
} }