Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: webrtc/examples/peerconnection/server/peer_channel.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 const size_t kMaxNameLength = 512; 49 const size_t kMaxNameLength = 512;
50 50
51 // 51 //
52 // ChannelMember 52 // ChannelMember
53 // 53 //
54 54
55 int ChannelMember::s_member_id_ = 0; 55 int ChannelMember::s_member_id_ = 0;
56 56
57 ChannelMember::ChannelMember(DataSocket* socket) 57 ChannelMember::ChannelMember(DataSocket* socket)
58 : waiting_socket_(NULL), id_(++s_member_id_), 58 : waiting_socket_(nullptr),
59 connected_(true), timestamp_(time(NULL)) { 59 id_(++s_member_id_),
60 connected_(true),
61 timestamp_(time(nullptr)) {
60 assert(socket); 62 assert(socket);
61 assert(socket->method() == DataSocket::GET); 63 assert(socket->method() == DataSocket::GET);
62 assert(socket->PathEquals("/sign_in")); 64 assert(socket->PathEquals("/sign_in"));
63 name_ = rtc::s_url_decode(socket->request_arguments()); 65 name_ = rtc::s_url_decode(socket->request_arguments());
64 if (name_.empty()) 66 if (name_.empty())
65 name_ = "peer_" + int2str(id_); 67 name_ = "peer_" + int2str(id_);
66 else if (name_.length() > kMaxNameLength) 68 else if (name_.length() > kMaxNameLength)
67 name_.resize(kMaxNameLength); 69 name_.resize(kMaxNameLength);
68 70
69 std::replace(name_.begin(), name_.end(), ',', '_'); 71 std::replace(name_.begin(), name_.end(), ',', '_');
70 } 72 }
71 73
72 ChannelMember::~ChannelMember() { 74 ChannelMember::~ChannelMember() {
73 } 75 }
74 76
75 bool ChannelMember::is_wait_request(DataSocket* ds) const { 77 bool ChannelMember::is_wait_request(DataSocket* ds) const {
76 return ds && ds->PathEquals(kRequestPaths[kWait]); 78 return ds && ds->PathEquals(kRequestPaths[kWait]);
77 } 79 }
78 80
79 bool ChannelMember::TimedOut() { 81 bool ChannelMember::TimedOut() {
80 return waiting_socket_ == NULL && (time(NULL) - timestamp_) > 30; 82 return waiting_socket_ == nullptr && (time(nullptr) - timestamp_) > 30;
81 } 83 }
82 84
83 std::string ChannelMember::GetPeerIdHeader() const { 85 std::string ChannelMember::GetPeerIdHeader() const {
84 std::string ret(kPeerIdHeader + int2str(id_) + "\r\n"); 86 std::string ret(kPeerIdHeader + int2str(id_) + "\r\n");
85 return ret; 87 return ret;
86 } 88 }
87 89
88 bool ChannelMember::NotifyOfOtherMember(const ChannelMember& other) { 90 bool ChannelMember::NotifyOfOtherMember(const ChannelMember& other) {
89 assert(&other != this); 91 assert(&other != this);
90 QueueResponse("200 OK", "text/plain", GetPeerIdHeader(), 92 QueueResponse("200 OK", "text/plain", GetPeerIdHeader(),
(...skipping 25 matching lines...) Expand all
116 printf("Client %s sending to %s\n", 118 printf("Client %s sending to %s\n",
117 name_.c_str(), peer->name().c_str()); 119 name_.c_str(), peer->name().c_str());
118 peer->QueueResponse("200 OK", ds->content_type(), extra_headers, 120 peer->QueueResponse("200 OK", ds->content_type(), extra_headers,
119 ds->data()); 121 ds->data());
120 ds->Send("200 OK", true, "text/plain", "", ""); 122 ds->Send("200 OK", true, "text/plain", "", "");
121 } 123 }
122 } 124 }
123 125
124 void ChannelMember::OnClosing(DataSocket* ds) { 126 void ChannelMember::OnClosing(DataSocket* ds) {
125 if (ds == waiting_socket_) { 127 if (ds == waiting_socket_) {
126 waiting_socket_ = NULL; 128 waiting_socket_ = nullptr;
127 timestamp_ = time(NULL); 129 timestamp_ = time(nullptr);
128 } 130 }
129 } 131 }
130 132
131 void ChannelMember::QueueResponse(const std::string& status, 133 void ChannelMember::QueueResponse(const std::string& status,
132 const std::string& content_type, 134 const std::string& content_type,
133 const std::string& extra_headers, 135 const std::string& extra_headers,
134 const std::string& data) { 136 const std::string& data) {
135 if (waiting_socket_) { 137 if (waiting_socket_) {
136 assert(queue_.size() == 0); 138 assert(queue_.size() == 0);
137 assert(waiting_socket_->method() == DataSocket::GET); 139 assert(waiting_socket_->method() == DataSocket::GET);
138 bool ok = waiting_socket_->Send(status, true, content_type, extra_headers, 140 bool ok = waiting_socket_->Send(status, true, content_type, extra_headers,
139 data); 141 data);
140 if (!ok) { 142 if (!ok) {
141 printf("Failed to deliver data to waiting socket\n"); 143 printf("Failed to deliver data to waiting socket\n");
142 } 144 }
143 waiting_socket_ = NULL; 145 waiting_socket_ = nullptr;
144 timestamp_ = time(NULL); 146 timestamp_ = time(nullptr);
145 } else { 147 } else {
146 QueuedResponse qr; 148 QueuedResponse qr;
147 qr.status = status; 149 qr.status = status;
148 qr.content_type = content_type; 150 qr.content_type = content_type;
149 qr.extra_headers = extra_headers; 151 qr.extra_headers = extra_headers;
150 qr.data = data; 152 qr.data = data;
151 queue_.push(qr); 153 queue_.push(qr);
152 } 154 }
153 } 155 }
154 156
155 void ChannelMember::SetWaitingSocket(DataSocket* ds) { 157 void ChannelMember::SetWaitingSocket(DataSocket* ds) {
156 assert(ds->method() == DataSocket::GET); 158 assert(ds->method() == DataSocket::GET);
157 if (ds && !queue_.empty()) { 159 if (ds && !queue_.empty()) {
158 assert(waiting_socket_ == NULL); 160 assert(waiting_socket_ == nullptr);
159 const QueuedResponse& response = queue_.front(); 161 const QueuedResponse& response = queue_.front();
160 ds->Send(response.status, true, response.content_type, 162 ds->Send(response.status, true, response.content_type,
161 response.extra_headers, response.data); 163 response.extra_headers, response.data);
162 queue_.pop(); 164 queue_.pop();
163 } else { 165 } else {
164 waiting_socket_ = ds; 166 waiting_socket_ = ds;
165 } 167 }
166 } 168 }
167 169
168 // 170 //
169 // PeerChannel 171 // PeerChannel
170 // 172 //
171 173
172 // static 174 // static
173 bool PeerChannel::IsPeerConnection(const DataSocket* ds) { 175 bool PeerChannel::IsPeerConnection(const DataSocket* ds) {
174 assert(ds); 176 assert(ds);
175 return (ds->method() == DataSocket::POST && ds->content_length() > 0) || 177 return (ds->method() == DataSocket::POST && ds->content_length() > 0) ||
176 (ds->method() == DataSocket::GET && ds->PathEquals("/sign_in")); 178 (ds->method() == DataSocket::GET && ds->PathEquals("/sign_in"));
177 } 179 }
178 180
179 ChannelMember* PeerChannel::Lookup(DataSocket* ds) const { 181 ChannelMember* PeerChannel::Lookup(DataSocket* ds) const {
180 assert(ds); 182 assert(ds);
181 183
182 if (ds->method() != DataSocket::GET && ds->method() != DataSocket::POST) 184 if (ds->method() != DataSocket::GET && ds->method() != DataSocket::POST)
183 return NULL; 185 return nullptr;
184 186
185 size_t i = 0; 187 size_t i = 0;
186 for (; i < ARRAYSIZE(kRequestPaths); ++i) { 188 for (; i < ARRAYSIZE(kRequestPaths); ++i) {
187 if (ds->PathEquals(kRequestPaths[i])) 189 if (ds->PathEquals(kRequestPaths[i]))
188 break; 190 break;
189 } 191 }
190 192
191 if (i == ARRAYSIZE(kRequestPaths)) 193 if (i == ARRAYSIZE(kRequestPaths))
192 return NULL; 194 return nullptr;
193 195
194 std::string args(ds->request_arguments()); 196 std::string args(ds->request_arguments());
195 static const char kPeerId[] = "peer_id="; 197 static const char kPeerId[] = "peer_id=";
196 size_t found = args.find(kPeerId); 198 size_t found = args.find(kPeerId);
197 if (found == std::string::npos) 199 if (found == std::string::npos)
198 return NULL; 200 return nullptr;
199 201
200 int id = atoi(&args[found + ARRAYSIZE(kPeerId) - 1]); 202 int id = atoi(&args[found + ARRAYSIZE(kPeerId) - 1]);
201 Members::const_iterator iter = members_.begin(); 203 Members::const_iterator iter = members_.begin();
202 for (; iter != members_.end(); ++iter) { 204 for (; iter != members_.end(); ++iter) {
203 if (id == (*iter)->id()) { 205 if (id == (*iter)->id()) {
204 if (i == kWait) 206 if (i == kWait)
205 (*iter)->SetWaitingSocket(ds); 207 (*iter)->SetWaitingSocket(ds);
206 if (i == kSignOut) 208 if (i == kSignOut)
207 (*iter)->set_disconnected(); 209 (*iter)->set_disconnected();
208 return *iter; 210 return *iter;
209 } 211 }
210 } 212 }
211 213
212 return NULL; 214 return nullptr;
213 } 215 }
214 216
215 ChannelMember* PeerChannel::IsTargetedRequest(const DataSocket* ds) const { 217 ChannelMember* PeerChannel::IsTargetedRequest(const DataSocket* ds) const {
216 assert(ds); 218 assert(ds);
217 // Regardless of GET or POST, we look for the peer_id parameter 219 // Regardless of GET or POST, we look for the peer_id parameter
218 // only in the request_path. 220 // only in the request_path.
219 const std::string& path = ds->request_path(); 221 const std::string& path = ds->request_path();
220 size_t args = path.find('?'); 222 size_t args = path.find('?');
221 if (args == std::string::npos) 223 if (args == std::string::npos)
222 return NULL; 224 return nullptr;
223 size_t found; 225 size_t found;
224 const char kTargetPeerIdParam[] = "to="; 226 const char kTargetPeerIdParam[] = "to=";
225 do { 227 do {
226 found = path.find(kTargetPeerIdParam, args); 228 found = path.find(kTargetPeerIdParam, args);
227 if (found == std::string::npos) 229 if (found == std::string::npos)
228 return NULL; 230 return nullptr;
229 if (found == (args + 1) || path[found - 1] == '&') { 231 if (found == (args + 1) || path[found - 1] == '&') {
230 found += ARRAYSIZE(kTargetPeerIdParam) - 1; 232 found += ARRAYSIZE(kTargetPeerIdParam) - 1;
231 break; 233 break;
232 } 234 }
233 args = found + ARRAYSIZE(kTargetPeerIdParam) - 1; 235 args = found + ARRAYSIZE(kTargetPeerIdParam) - 1;
234 } while (true); 236 } while (true);
235 int id = atoi(&path[found]); 237 int id = atoi(&path[found]);
236 Members::const_iterator i = members_.begin(); 238 Members::const_iterator i = members_.begin();
237 for (; i != members_.end(); ++i) { 239 for (; i != members_.end(); ++i) {
238 if ((*i)->id() == id) { 240 if ((*i)->id() == id) {
239 return *i; 241 return *i;
240 } 242 }
241 } 243 }
242 return NULL; 244 return nullptr;
243 } 245 }
244 246
245 bool PeerChannel::AddMember(DataSocket* ds) { 247 bool PeerChannel::AddMember(DataSocket* ds) {
246 assert(IsPeerConnection(ds)); 248 assert(IsPeerConnection(ds));
247 ChannelMember* new_guy = new ChannelMember(ds); 249 ChannelMember* new_guy = new ChannelMember(ds);
248 Members failures; 250 Members failures;
249 BroadcastChangedState(*new_guy, &failures); 251 BroadcastChangedState(*new_guy, &failures);
250 HandleDeliveryFailures(&failures); 252 HandleDeliveryFailures(&failures);
251 members_.push_back(new_guy); 253 members_.push_back(new_guy);
252 254
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 std::string response(member.GetEntry()); 357 std::string response(member.GetEntry());
356 for (Members::iterator i = members_.begin(); i != members_.end(); ++i) { 358 for (Members::iterator i = members_.begin(); i != members_.end(); ++i) {
357 if (member.id() != (*i)->id()) { 359 if (member.id() != (*i)->id()) {
358 assert((*i)->connected()); 360 assert((*i)->connected());
359 response += (*i)->GetEntry(); 361 response += (*i)->GetEntry();
360 } 362 }
361 } 363 }
362 364
363 return response; 365 return response;
364 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698