blob: 7af175ae6ec2d145ddae713bf1978f87968fbbb5 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread.h"
#include "net/base/net_export.h"
#include "net/socket/udp_socket.h"
namespace net {
class IPEndPoint;
class UdpSocketFactory;
class HttpServerRequestInfo;
class NET_EXPORT DialUdpServer {
DialUdpServer(const std::string& location_url,
const std::string& server_agent);
virtual ~DialUdpServer();
virtual void DidRead(int rv);
virtual void DidClose(UDPSocket* sock);
void WriteComplete(scoped_refptr<WrappedIOBuffer>,
int rv);
FRIEND_TEST_ALL_PREFIXES(DialUdpServerTest, ParseSearchRequest);
void Start();
void Stop();
// Create the listen socket. Runs on a separate thread.
void CreateAndBind();
void Shutdown();
void AcceptAndProcessConnection();
// Construct the appropriate search response.
std::string ConstructSearchResponse() const;
// Parse a request to make sure it is a M-Search.
static bool ParseSearchRequest(const std::string& request);
// Is the valid SSDP request a valid M-Search request too ?
static bool IsValidMSearchRequest(const HttpServerRequestInfo& info);
std::unique_ptr<UDPSocket> socket_;
std::unique_ptr<UdpSocketFactory> factory_;
// Value to pass in LOCATION: header
std::string location_url_;
// Value to pass in SERVER: header
std::string server_agent_;
base::Thread thread_;
bool is_running_;
scoped_refptr<IOBuffer> read_buf_;
IPEndPoint client_address_;
} // namespace net