mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-03-12 03:56:27 +00:00
Update copyright boilerplate, 2022 edition (Breakpad)
sed -i '' -E -e 's/Copyright (\(c\) )?([0-9-]+),? (Google|The Chromium Authors).*(\r)?$/Copyright \2 Google LLC\4/' -e '/^((\/\/|#| \*) )?All rights reserved\.?\r?$/d' -e 's/name of Google Inc\. nor the/name of Google LLC nor the/' -e 's/POSSIBILITY OF SUCH DAMAGE$/POSSIBILITY OF SUCH DAMAGE./' $(git grep -El 'Copyright (\(c\) )?([0-9-]+),? (Google|The Chromium Authors).*$')
Plus manual fixes for src/processor/disassembler_x86.{cc,h}.
Plus some conversions from CRLF to LF line endings in .cc and .h files.
Bug: chromium:1098010
Change-Id: I8030e804eecd9f5a1ec9d66ae166efd8418c2a67
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3878302
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2012, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2012 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2020, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2011 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2009, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2009 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2011 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2011 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2020, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
# Copyright 2014 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2010 Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2010 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// -*- mode: c++ -*-
|
||||
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2011 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -13,7 +12,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2010 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
# Copyright 2014 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* Copyright 2014, Google Inc.
|
||||
All rights reserved.
|
||||
/* Copyright 2014 Google LLC
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@ notice, this list of conditions and the following disclaimer.
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* Copyright 2014, Google Inc.
|
||||
All rights reserved.
|
||||
/* Copyright 2014 Google LLC
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@ notice, this list of conditions and the following disclaimer.
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* Copyright 2014, Google Inc.
|
||||
All rights reserved.
|
||||
/* Copyright 2014 Google LLC
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@ notice, this list of conditions and the following disclaimer.
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright 2016 Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2016 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -12,7 +11,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2012 Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2012 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -12,7 +11,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2012 Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2012 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -12,7 +11,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright (c) 2007, Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2007 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2007 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2007, Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2007 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -13,7 +12,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2007 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2014 Google Inc. All rights reserved.
|
||||
# Copyright 2014 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2007 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
# Copyright 2013 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2007 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
# Copyright 2013 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,99 +1,99 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Base64 escaping methods to encode/decode strings.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace strings {
|
||||
|
||||
using std::string;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Base64Escape()
|
||||
// WebSafeBase64Escape()
|
||||
// Encode "src" to "dest" using base64 encoding.
|
||||
// src is not null terminated, instead specify len.
|
||||
// 'dest' should have at least CalculateBase64EscapedLen() length.
|
||||
// RETURNS the length of dest.
|
||||
// The WebSafe variation use '-' instead of '+' and '_' instead of '/'
|
||||
// so that we can place the out in the URL or cookies without having
|
||||
// to escape them. It also has an extra parameter "do_padding",
|
||||
// which when set to false will prevent padding with "=".
|
||||
// ----------------------------------------------------------------------
|
||||
void Base64Escape(const string& src, string* dest);
|
||||
int Base64Escape(const unsigned char* src, int slen, char* dest, int szdest);
|
||||
// Encode src into dest with padding.
|
||||
void Base64Escape(const unsigned char* src, int szsrc,
|
||||
string* dest, bool do_padding);
|
||||
|
||||
int WebSafeBase64Escape(const unsigned char* src, int slen, char* dest,
|
||||
int szdest, bool do_padding);
|
||||
// Encode src into dest web-safely without padding.
|
||||
void WebSafeBase64Escape(const string& src, string* dest);
|
||||
// Encode src into dest web-safely with padding.
|
||||
void WebSafeBase64EscapeWithPadding(const string& src, string* dest);
|
||||
void WebSafeBase64Escape(const unsigned char* src, int szsrc,
|
||||
string* dest, bool do_padding);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Base64Unescape()
|
||||
// WebSafeBase64Unescape()
|
||||
// Copies "src" to "dest", where src is in base64 and is written to its
|
||||
// ASCII equivalents. src is not null terminated, instead specify len.
|
||||
// I recommend that slen<szdest, but we honor szdest anyway.
|
||||
// RETURNS the length of dest, or -1 if src contains invalid chars.
|
||||
// The WebSafe variation use '-' instead of '+' and '_' instead of '/'.
|
||||
// The variations that store into a string clear the string first, and
|
||||
// return false (with dest empty) if src contains invalid chars; for
|
||||
// these versions src and dest must be different strings.
|
||||
// ----------------------------------------------------------------------
|
||||
int Base64Unescape(const char* src, int slen, char* dest, int szdest);
|
||||
bool Base64Unescape(const char* src, int slen, string* dest);
|
||||
inline bool Base64Unescape(const string& src, string* dest) {
|
||||
return Base64Unescape(src.data(), src.size(), dest);
|
||||
}
|
||||
|
||||
|
||||
int WebSafeBase64Unescape(const char* src, int slen, char* dest, int szdest);
|
||||
bool WebSafeBase64Unescape(const char* src, int slen, string* dest);
|
||||
bool WebSafeBase64Unescape(const string& src, string* dest);
|
||||
|
||||
// Return the length to use for the output buffer given to the base64 escape
|
||||
// routines. Make sure to use the same value for do_padding in both.
|
||||
// This function may return incorrect results if given input_len values that
|
||||
// are extremely high, which should happen rarely.
|
||||
int CalculateBase64EscapedLen(int input_len, bool do_padding);
|
||||
// Use this version when calling Base64Escape without a do_padding arg.
|
||||
int CalculateBase64EscapedLen(int input_len);
|
||||
} // namespace strings
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Base64 escaping methods to encode/decode strings.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace strings {
|
||||
|
||||
using std::string;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Base64Escape()
|
||||
// WebSafeBase64Escape()
|
||||
// Encode "src" to "dest" using base64 encoding.
|
||||
// src is not null terminated, instead specify len.
|
||||
// 'dest' should have at least CalculateBase64EscapedLen() length.
|
||||
// RETURNS the length of dest.
|
||||
// The WebSafe variation use '-' instead of '+' and '_' instead of '/'
|
||||
// so that we can place the out in the URL or cookies without having
|
||||
// to escape them. It also has an extra parameter "do_padding",
|
||||
// which when set to false will prevent padding with "=".
|
||||
// ----------------------------------------------------------------------
|
||||
void Base64Escape(const string& src, string* dest);
|
||||
int Base64Escape(const unsigned char* src, int slen, char* dest, int szdest);
|
||||
// Encode src into dest with padding.
|
||||
void Base64Escape(const unsigned char* src, int szsrc,
|
||||
string* dest, bool do_padding);
|
||||
|
||||
int WebSafeBase64Escape(const unsigned char* src, int slen, char* dest,
|
||||
int szdest, bool do_padding);
|
||||
// Encode src into dest web-safely without padding.
|
||||
void WebSafeBase64Escape(const string& src, string* dest);
|
||||
// Encode src into dest web-safely with padding.
|
||||
void WebSafeBase64EscapeWithPadding(const string& src, string* dest);
|
||||
void WebSafeBase64Escape(const unsigned char* src, int szsrc,
|
||||
string* dest, bool do_padding);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Base64Unescape()
|
||||
// WebSafeBase64Unescape()
|
||||
// Copies "src" to "dest", where src is in base64 and is written to its
|
||||
// ASCII equivalents. src is not null terminated, instead specify len.
|
||||
// I recommend that slen<szdest, but we honor szdest anyway.
|
||||
// RETURNS the length of dest, or -1 if src contains invalid chars.
|
||||
// The WebSafe variation use '-' instead of '+' and '_' instead of '/'.
|
||||
// The variations that store into a string clear the string first, and
|
||||
// return false (with dest empty) if src contains invalid chars; for
|
||||
// these versions src and dest must be different strings.
|
||||
// ----------------------------------------------------------------------
|
||||
int Base64Unescape(const char* src, int slen, char* dest, int szdest);
|
||||
bool Base64Unescape(const char* src, int slen, string* dest);
|
||||
inline bool Base64Unescape(const string& src, string* dest) {
|
||||
return Base64Unescape(src.data(), src.size(), dest);
|
||||
}
|
||||
|
||||
|
||||
int WebSafeBase64Unescape(const char* src, int slen, char* dest, int szdest);
|
||||
bool WebSafeBase64Unescape(const char* src, int slen, string* dest);
|
||||
bool WebSafeBase64Unescape(const string& src, string* dest);
|
||||
|
||||
// Return the length to use for the output buffer given to the base64 escape
|
||||
// routines. Make sure to use the same value for do_padding in both.
|
||||
// This function may return incorrect results if given input_len values that
|
||||
// are extremely high, which should happen rarely.
|
||||
int CalculateBase64EscapedLen(int input_len, bool do_padding);
|
||||
// Use this version when calling Base64Escape without a do_padding arg.
|
||||
int CalculateBase64EscapedLen(int input_len);
|
||||
} // namespace strings
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_ESCAPING_H_
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
#define TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
|
||||
typedef void* HttpHandle;
|
||||
|
||||
namespace crash {
|
||||
|
||||
// HttpClient provides an abstract layer for HTTP APIs. The actual
|
||||
// implementation can be based on either WinHttp or WinInet.
|
||||
class HttpClient {
|
||||
public:
|
||||
enum AccessType {
|
||||
ACCESS_TYPE_PRECONFIG,
|
||||
ACCESS_TYPE_DIRECT,
|
||||
ACCESS_TYPE_PROXY,
|
||||
};
|
||||
|
||||
virtual ~HttpClient() {}
|
||||
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const = 0;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const = 0;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const = 0;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const = 0;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const = 0;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const = 0;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const = 0;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const = 0;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const = 0;
|
||||
virtual bool Close(HttpHandle handle) const = 0;
|
||||
|
||||
static const DWORD kUnknownContentLength = (DWORD)-1;
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
#define TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
|
||||
typedef void* HttpHandle;
|
||||
|
||||
namespace crash {
|
||||
|
||||
// HttpClient provides an abstract layer for HTTP APIs. The actual
|
||||
// implementation can be based on either WinHttp or WinInet.
|
||||
class HttpClient {
|
||||
public:
|
||||
enum AccessType {
|
||||
ACCESS_TYPE_PRECONFIG,
|
||||
ACCESS_TYPE_DIRECT,
|
||||
ACCESS_TYPE_PROXY,
|
||||
};
|
||||
|
||||
virtual ~HttpClient() {}
|
||||
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const = 0;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const = 0;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const = 0;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const = 0;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const = 0;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const = 0;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const = 0;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const = 0;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const = 0;
|
||||
virtual bool Close(HttpHandle handle) const = 0;
|
||||
|
||||
static const DWORD kUnknownContentLength = (DWORD)-1;
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_
|
||||
|
||||
@@ -1,326 +1,326 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <Windows.h>
|
||||
#include <WinInet.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "tools/windows/converter_exe/http_download.h"
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
#include "tools/windows/converter_exe/wininet_client.h"
|
||||
|
||||
namespace crash {
|
||||
static const std::vector<char>::size_type kVectorChunkSize = 4096; // 4 KB
|
||||
|
||||
using std::vector;
|
||||
|
||||
// Class that atuo closes the contained HttpHandle when the object
|
||||
// goes out of scope.
|
||||
class AutoHttpHandle {
|
||||
public:
|
||||
AutoHttpHandle() : handle_(NULL) {}
|
||||
explicit AutoHttpHandle(HttpHandle handle) : handle_(handle) {}
|
||||
~AutoHttpHandle() {
|
||||
if (handle_) {
|
||||
InternetCloseHandle(handle_);
|
||||
}
|
||||
}
|
||||
|
||||
HttpHandle get() { return handle_; }
|
||||
HttpHandle* get_handle_addr () { return &handle_; }
|
||||
|
||||
private:
|
||||
HttpHandle handle_;
|
||||
};
|
||||
|
||||
// Template class for auto releasing the contained pointer when
|
||||
// the object goes out of scope.
|
||||
template<typename T>
|
||||
class AutoPtr {
|
||||
public:
|
||||
explicit AutoPtr(T* ptr) : ptr_(ptr) {}
|
||||
~AutoPtr() {
|
||||
if (ptr_) {
|
||||
delete ptr_;
|
||||
}
|
||||
}
|
||||
|
||||
T* get() { return ptr_; }
|
||||
T* operator -> () { return ptr_; }
|
||||
|
||||
private:
|
||||
T* ptr_;
|
||||
};
|
||||
|
||||
// CheckParameters ensures that the parameters in |parameters| are safe for
|
||||
// use in an HTTP URL. Returns true if they are, false if unsafe characters
|
||||
// are present.
|
||||
static bool CheckParameters(const map<wstring, wstring>* parameters) {
|
||||
for (map<wstring, wstring>::const_iterator iterator = parameters->begin();
|
||||
iterator != parameters->end();
|
||||
++iterator) {
|
||||
const wstring& key = iterator->first;
|
||||
if (key.empty()) {
|
||||
// Disallow empty parameter names.
|
||||
return false;
|
||||
}
|
||||
for (unsigned int i = 0; i < key.size(); ++i) {
|
||||
wchar_t c = key[i];
|
||||
if (c < 32 || c == '"' || c == '?' || c == '&' || c > 127) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const wstring& value = iterator->second;
|
||||
for (unsigned int i = 0; i < value.size(); ++i) {
|
||||
wchar_t c = value[i];
|
||||
if (c < 32 || c == '"' || c == '?' || c == '&' || c > 127) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HttpClient* HTTPDownload::CreateHttpClient(const wchar_t* url) {
|
||||
const TCHAR* kHttpApiPolicyEnvironmentVariable = TEXT("USE_WINHTTP");
|
||||
TCHAR buffer[2] = {0};
|
||||
HttpClient* http_client = NULL;
|
||||
|
||||
if (::GetEnvironmentVariable(kHttpApiPolicyEnvironmentVariable,
|
||||
buffer,
|
||||
sizeof(buffer)/sizeof(buffer[0])) > 0) {
|
||||
fprintf(stdout,
|
||||
"Environment variable [%ws] is set, use WinHttp\n",
|
||||
kHttpApiPolicyEnvironmentVariable);
|
||||
http_client = CreateWinHttpClient(url);
|
||||
if (http_client == NULL) {
|
||||
fprintf(stderr, "WinHttpClient not created, Is the protocol HTTPS? "
|
||||
"Fall back to WinInet API.\n");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Environment variable [%ws] is NOT set, use WinInet API\n",
|
||||
kHttpApiPolicyEnvironmentVariable);
|
||||
}
|
||||
|
||||
if (http_client == NULL) {
|
||||
return CreateWinInetClient(url);
|
||||
}
|
||||
|
||||
return http_client;
|
||||
}
|
||||
|
||||
// static
|
||||
bool HTTPDownload::Download(const wstring& url,
|
||||
const map<wstring, wstring>* parameters,
|
||||
string *content, int *status_code) {
|
||||
assert(content);
|
||||
AutoPtr<HttpClient> http_client(CreateHttpClient(url.c_str()));
|
||||
|
||||
if (!http_client.get()) {
|
||||
fprintf(stderr, "Failed to create any http client.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status_code) {
|
||||
*status_code = 0;
|
||||
}
|
||||
|
||||
wchar_t scheme[16] = {0};
|
||||
wchar_t host[256] = {0};
|
||||
wchar_t path[256] = {0};
|
||||
int port = 0;
|
||||
if (!http_client->CrackUrl(url.c_str(),
|
||||
0,
|
||||
scheme,
|
||||
sizeof(scheme)/sizeof(scheme[0]),
|
||||
host,
|
||||
sizeof(host)/sizeof(host[0]),
|
||||
path,
|
||||
sizeof(path)/sizeof(path[0]),
|
||||
&port)) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: InternetCrackUrl: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool secure = false;
|
||||
if (_wcsicmp(scheme, L"https") == 0) {
|
||||
secure = true;
|
||||
} else if (wcscmp(scheme, L"http") != 0) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: scheme must be http or https for %ws\n",
|
||||
url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoHttpHandle internet;
|
||||
if (!http_client->Open(NULL, // user agent
|
||||
HttpClient::ACCESS_TYPE_PRECONFIG,
|
||||
NULL, // proxy name
|
||||
NULL, // proxy bypass
|
||||
internet.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: Open: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoHttpHandle connection;
|
||||
if (!http_client->Connect(internet.get(),
|
||||
host,
|
||||
port,
|
||||
connection.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: InternetConnect: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
wstring request_string = path;
|
||||
if (parameters) {
|
||||
// TODO(mmentovai): escape bad characters in parameters instead of
|
||||
// forbidding them.
|
||||
if (!CheckParameters(parameters)) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: invalid characters in parameters\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool added_parameter = false;
|
||||
for (map<wstring, wstring>::const_iterator iterator = parameters->begin();
|
||||
iterator != parameters->end();
|
||||
++iterator) {
|
||||
request_string.append(added_parameter ? L"&" : L"?");
|
||||
request_string.append(iterator->first);
|
||||
request_string.append(L"=");
|
||||
request_string.append(iterator->second);
|
||||
added_parameter = true;
|
||||
}
|
||||
}
|
||||
|
||||
AutoHttpHandle request;
|
||||
if (!http_client->OpenRequest(connection.get(),
|
||||
L"GET",
|
||||
request_string.c_str(),
|
||||
NULL, // version
|
||||
NULL, // referer
|
||||
secure,
|
||||
request.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::OpenRequest: error %lu for %ws, request: %ws\n",
|
||||
GetLastError(), url.c_str(), request_string.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!http_client->SendRequest(request.get(), NULL, 0)) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::SendRequest: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!http_client->ReceiveResponse(request.get())) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReceiveResponse: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int http_status = 0;
|
||||
if (!http_client->GetHttpStatusCode(request.get(), &http_status)) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::GetHttpStatusCode: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
if (http_status != 200) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: HTTP status code %d for %ws\n",
|
||||
http_status, url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD content_length = 0;
|
||||
vector<char>::size_type buffer_size = 0;
|
||||
http_client->GetContentLength(request.get(), &content_length);
|
||||
if (content_length == HttpClient::kUnknownContentLength) {
|
||||
buffer_size = kVectorChunkSize;
|
||||
} else {
|
||||
buffer_size = content_length;
|
||||
}
|
||||
|
||||
if (content_length != 0) {
|
||||
vector<char> response_buffer = vector<char>(buffer_size+1);
|
||||
DWORD size_read;
|
||||
DWORD total_read = 0;
|
||||
bool read_result;
|
||||
do {
|
||||
if (content_length == HttpClient::kUnknownContentLength
|
||||
&& buffer_size == total_read) {
|
||||
// The content length wasn't specified in the response header, so we
|
||||
// have to keep growing the buffer until we're done reading.
|
||||
buffer_size += kVectorChunkSize;
|
||||
response_buffer.resize(buffer_size);
|
||||
}
|
||||
read_result = !!http_client->ReadData(
|
||||
request.get(),
|
||||
&response_buffer[total_read],
|
||||
static_cast<DWORD>(buffer_size) - total_read,
|
||||
&size_read);
|
||||
total_read += size_read;
|
||||
} while (read_result && (size_read != 0));
|
||||
|
||||
if (!read_result) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReadData: error %lu for %ws\n",
|
||||
GetLastError(),
|
||||
url.c_str());
|
||||
return false;
|
||||
} else if (size_read != 0) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReadData: error %lu/%lu for %ws\n",
|
||||
total_read,
|
||||
content_length,
|
||||
url.c_str());
|
||||
return false;
|
||||
}
|
||||
content->assign(&response_buffer[0], total_read);
|
||||
} else {
|
||||
content->clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <Windows.h>
|
||||
#include <WinInet.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "tools/windows/converter_exe/http_download.h"
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
#include "tools/windows/converter_exe/wininet_client.h"
|
||||
|
||||
namespace crash {
|
||||
static const std::vector<char>::size_type kVectorChunkSize = 4096; // 4 KB
|
||||
|
||||
using std::vector;
|
||||
|
||||
// Class that atuo closes the contained HttpHandle when the object
|
||||
// goes out of scope.
|
||||
class AutoHttpHandle {
|
||||
public:
|
||||
AutoHttpHandle() : handle_(NULL) {}
|
||||
explicit AutoHttpHandle(HttpHandle handle) : handle_(handle) {}
|
||||
~AutoHttpHandle() {
|
||||
if (handle_) {
|
||||
InternetCloseHandle(handle_);
|
||||
}
|
||||
}
|
||||
|
||||
HttpHandle get() { return handle_; }
|
||||
HttpHandle* get_handle_addr () { return &handle_; }
|
||||
|
||||
private:
|
||||
HttpHandle handle_;
|
||||
};
|
||||
|
||||
// Template class for auto releasing the contained pointer when
|
||||
// the object goes out of scope.
|
||||
template<typename T>
|
||||
class AutoPtr {
|
||||
public:
|
||||
explicit AutoPtr(T* ptr) : ptr_(ptr) {}
|
||||
~AutoPtr() {
|
||||
if (ptr_) {
|
||||
delete ptr_;
|
||||
}
|
||||
}
|
||||
|
||||
T* get() { return ptr_; }
|
||||
T* operator -> () { return ptr_; }
|
||||
|
||||
private:
|
||||
T* ptr_;
|
||||
};
|
||||
|
||||
// CheckParameters ensures that the parameters in |parameters| are safe for
|
||||
// use in an HTTP URL. Returns true if they are, false if unsafe characters
|
||||
// are present.
|
||||
static bool CheckParameters(const map<wstring, wstring>* parameters) {
|
||||
for (map<wstring, wstring>::const_iterator iterator = parameters->begin();
|
||||
iterator != parameters->end();
|
||||
++iterator) {
|
||||
const wstring& key = iterator->first;
|
||||
if (key.empty()) {
|
||||
// Disallow empty parameter names.
|
||||
return false;
|
||||
}
|
||||
for (unsigned int i = 0; i < key.size(); ++i) {
|
||||
wchar_t c = key[i];
|
||||
if (c < 32 || c == '"' || c == '?' || c == '&' || c > 127) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const wstring& value = iterator->second;
|
||||
for (unsigned int i = 0; i < value.size(); ++i) {
|
||||
wchar_t c = value[i];
|
||||
if (c < 32 || c == '"' || c == '?' || c == '&' || c > 127) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HttpClient* HTTPDownload::CreateHttpClient(const wchar_t* url) {
|
||||
const TCHAR* kHttpApiPolicyEnvironmentVariable = TEXT("USE_WINHTTP");
|
||||
TCHAR buffer[2] = {0};
|
||||
HttpClient* http_client = NULL;
|
||||
|
||||
if (::GetEnvironmentVariable(kHttpApiPolicyEnvironmentVariable,
|
||||
buffer,
|
||||
sizeof(buffer)/sizeof(buffer[0])) > 0) {
|
||||
fprintf(stdout,
|
||||
"Environment variable [%ws] is set, use WinHttp\n",
|
||||
kHttpApiPolicyEnvironmentVariable);
|
||||
http_client = CreateWinHttpClient(url);
|
||||
if (http_client == NULL) {
|
||||
fprintf(stderr, "WinHttpClient not created, Is the protocol HTTPS? "
|
||||
"Fall back to WinInet API.\n");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Environment variable [%ws] is NOT set, use WinInet API\n",
|
||||
kHttpApiPolicyEnvironmentVariable);
|
||||
}
|
||||
|
||||
if (http_client == NULL) {
|
||||
return CreateWinInetClient(url);
|
||||
}
|
||||
|
||||
return http_client;
|
||||
}
|
||||
|
||||
// static
|
||||
bool HTTPDownload::Download(const wstring& url,
|
||||
const map<wstring, wstring>* parameters,
|
||||
string *content, int *status_code) {
|
||||
assert(content);
|
||||
AutoPtr<HttpClient> http_client(CreateHttpClient(url.c_str()));
|
||||
|
||||
if (!http_client.get()) {
|
||||
fprintf(stderr, "Failed to create any http client.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status_code) {
|
||||
*status_code = 0;
|
||||
}
|
||||
|
||||
wchar_t scheme[16] = {0};
|
||||
wchar_t host[256] = {0};
|
||||
wchar_t path[256] = {0};
|
||||
int port = 0;
|
||||
if (!http_client->CrackUrl(url.c_str(),
|
||||
0,
|
||||
scheme,
|
||||
sizeof(scheme)/sizeof(scheme[0]),
|
||||
host,
|
||||
sizeof(host)/sizeof(host[0]),
|
||||
path,
|
||||
sizeof(path)/sizeof(path[0]),
|
||||
&port)) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: InternetCrackUrl: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool secure = false;
|
||||
if (_wcsicmp(scheme, L"https") == 0) {
|
||||
secure = true;
|
||||
} else if (wcscmp(scheme, L"http") != 0) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: scheme must be http or https for %ws\n",
|
||||
url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoHttpHandle internet;
|
||||
if (!http_client->Open(NULL, // user agent
|
||||
HttpClient::ACCESS_TYPE_PRECONFIG,
|
||||
NULL, // proxy name
|
||||
NULL, // proxy bypass
|
||||
internet.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: Open: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoHttpHandle connection;
|
||||
if (!http_client->Connect(internet.get(),
|
||||
host,
|
||||
port,
|
||||
connection.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: InternetConnect: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
wstring request_string = path;
|
||||
if (parameters) {
|
||||
// TODO(mmentovai): escape bad characters in parameters instead of
|
||||
// forbidding them.
|
||||
if (!CheckParameters(parameters)) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: invalid characters in parameters\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool added_parameter = false;
|
||||
for (map<wstring, wstring>::const_iterator iterator = parameters->begin();
|
||||
iterator != parameters->end();
|
||||
++iterator) {
|
||||
request_string.append(added_parameter ? L"&" : L"?");
|
||||
request_string.append(iterator->first);
|
||||
request_string.append(L"=");
|
||||
request_string.append(iterator->second);
|
||||
added_parameter = true;
|
||||
}
|
||||
}
|
||||
|
||||
AutoHttpHandle request;
|
||||
if (!http_client->OpenRequest(connection.get(),
|
||||
L"GET",
|
||||
request_string.c_str(),
|
||||
NULL, // version
|
||||
NULL, // referer
|
||||
secure,
|
||||
request.get_handle_addr())) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::OpenRequest: error %lu for %ws, request: %ws\n",
|
||||
GetLastError(), url.c_str(), request_string.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!http_client->SendRequest(request.get(), NULL, 0)) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::SendRequest: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!http_client->ReceiveResponse(request.get())) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReceiveResponse: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int http_status = 0;
|
||||
if (!http_client->GetHttpStatusCode(request.get(), &http_status)) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::GetHttpStatusCode: error %lu for %ws\n",
|
||||
GetLastError(), url.c_str());
|
||||
return false;
|
||||
}
|
||||
if (http_status != 200) {
|
||||
fprintf(stderr,
|
||||
"HTTPDownload::Download: HTTP status code %d for %ws\n",
|
||||
http_status, url.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD content_length = 0;
|
||||
vector<char>::size_type buffer_size = 0;
|
||||
http_client->GetContentLength(request.get(), &content_length);
|
||||
if (content_length == HttpClient::kUnknownContentLength) {
|
||||
buffer_size = kVectorChunkSize;
|
||||
} else {
|
||||
buffer_size = content_length;
|
||||
}
|
||||
|
||||
if (content_length != 0) {
|
||||
vector<char> response_buffer = vector<char>(buffer_size+1);
|
||||
DWORD size_read;
|
||||
DWORD total_read = 0;
|
||||
bool read_result;
|
||||
do {
|
||||
if (content_length == HttpClient::kUnknownContentLength
|
||||
&& buffer_size == total_read) {
|
||||
// The content length wasn't specified in the response header, so we
|
||||
// have to keep growing the buffer until we're done reading.
|
||||
buffer_size += kVectorChunkSize;
|
||||
response_buffer.resize(buffer_size);
|
||||
}
|
||||
read_result = !!http_client->ReadData(
|
||||
request.get(),
|
||||
&response_buffer[total_read],
|
||||
static_cast<DWORD>(buffer_size) - total_read,
|
||||
&size_read);
|
||||
total_read += size_read;
|
||||
} while (read_result && (size_read != 0));
|
||||
|
||||
if (!read_result) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReadData: error %lu for %ws\n",
|
||||
GetLastError(),
|
||||
url.c_str());
|
||||
return false;
|
||||
} else if (size_read != 0) {
|
||||
fprintf(stderr,
|
||||
"HttpClient::ReadData: error %lu/%lu for %ws\n",
|
||||
total_read,
|
||||
content_length,
|
||||
url.c_str());
|
||||
return false;
|
||||
}
|
||||
content->assign(&response_buffer[0], total_read);
|
||||
} else {
|
||||
content->clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
class HTTPDownload {
|
||||
public:
|
||||
// Retrieves the resource located at |url|, a http or https URL, via WinInet.
|
||||
// The request is fetched with GET request; the optional |parameters| are
|
||||
// appended to the URL. Returns true on success, placing the content of the
|
||||
// retrieved resource in |content|. Returns false on failure. HTTP status
|
||||
// codes other than 200 cause Download to return false. If |status_code| is
|
||||
// supplied, it will be set to the value of the HTTP status code, if an HTTP
|
||||
// transaction occurs. If Download fails before a transaction can occur,
|
||||
// |status_code| will be set to 0. Any failures will result in messages
|
||||
// being printed to stderr.
|
||||
static bool Download(const wstring& url,
|
||||
const map<wstring, wstring>* parameters,
|
||||
string *content, int *status_code);
|
||||
private:
|
||||
static HttpClient* CreateHttpClient(const wchar_t*);
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
class HTTPDownload {
|
||||
public:
|
||||
// Retrieves the resource located at |url|, a http or https URL, via WinInet.
|
||||
// The request is fetched with GET request; the optional |parameters| are
|
||||
// appended to the URL. Returns true on success, placing the content of the
|
||||
// retrieved resource in |content|. Returns false on failure. HTTP status
|
||||
// codes other than 200 cause Download to return false. If |status_code| is
|
||||
// supplied, it will be set to the value of the HTTP status code, if an HTTP
|
||||
// transaction occurs. If Download fails before a transaction can occur,
|
||||
// |status_code| will be set to 0. Any failures will result in messages
|
||||
// being printed to stderr.
|
||||
static bool Download(const wstring& url,
|
||||
const map<wstring, wstring>* parameters,
|
||||
string *content, int *status_code);
|
||||
private:
|
||||
static HttpClient* CreateHttpClient(const wchar_t*);
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_HTTP_DOWNLOAD_H_
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "tools/windows/converter_exe/tokenizer.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
// static
|
||||
void Tokenizer::Tokenize(const string& delimiters, const string& input,
|
||||
vector<string>* output) {
|
||||
assert(output);
|
||||
output->clear();
|
||||
|
||||
string::size_type position = 0; // Where to begin looking for a delimiter
|
||||
string::size_type new_position; // Position of found delimiter
|
||||
string token;
|
||||
|
||||
while ((new_position = input.find_first_of(delimiters, position)) !=
|
||||
string::npos) {
|
||||
token = input.substr(position, new_position - position);
|
||||
output->push_back(token);
|
||||
|
||||
// Next time, begin looking right after this delimiter.
|
||||
position = new_position + 1;
|
||||
}
|
||||
|
||||
// There are no more delimiters in the string. Take everything from the
|
||||
// final delimiter up to the end of the string as a token. This may be
|
||||
// an empty string.
|
||||
token = input.substr(position);
|
||||
output->push_back(token);
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "tools/windows/converter_exe/tokenizer.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
// static
|
||||
void Tokenizer::Tokenize(const string& delimiters, const string& input,
|
||||
vector<string>* output) {
|
||||
assert(output);
|
||||
output->clear();
|
||||
|
||||
string::size_type position = 0; // Where to begin looking for a delimiter
|
||||
string::size_type new_position; // Position of found delimiter
|
||||
string token;
|
||||
|
||||
while ((new_position = input.find_first_of(delimiters, position)) !=
|
||||
string::npos) {
|
||||
token = input.substr(position, new_position - position);
|
||||
output->push_back(token);
|
||||
|
||||
// Next time, begin looking right after this delimiter.
|
||||
position = new_position + 1;
|
||||
}
|
||||
|
||||
// There are no more delimiters in the string. Take everything from the
|
||||
// final delimiter up to the end of the string as a token. This may be
|
||||
// an empty string.
|
||||
token = input.substr(position);
|
||||
output->push_back(token);
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace crash {
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
// Splits |input| into a series of tokens delimited in the input string by
|
||||
// any of the characters in |delimiters|. The tokens are passed back in the
|
||||
// |output| vector.
|
||||
static void Tokenize(const string& delimiters, const string& input,
|
||||
vector<string>* output);
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace crash {
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
// Splits |input| into a series of tokens delimited in the input string by
|
||||
// any of the characters in |delimiters|. The tokens are passed back in the
|
||||
// |output| vector.
|
||||
static void Tokenize(const string& delimiters, const string& input,
|
||||
vector<string>* output);
|
||||
};
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_TOKENIZER_H_
|
||||
|
||||
@@ -1,307 +1,307 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <vector>
|
||||
|
||||
namespace crash {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This class implements HttpClient based on WinInet APIs.
|
||||
class WinHttpClient : public HttpClient {
|
||||
public:
|
||||
virtual ~WinHttpClient() {}
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const;
|
||||
virtual bool Close(HttpHandle handle) const;
|
||||
|
||||
private:
|
||||
static DWORD MapAccessType(DWORD access_type);
|
||||
static HINTERNET ToHINTERNET(HttpHandle handle);
|
||||
static HttpHandle FromHINTERNET(HINTERNET handle);
|
||||
};
|
||||
|
||||
bool WinHttpClient::CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const {
|
||||
assert(url);
|
||||
assert(scheme);
|
||||
assert(host);
|
||||
assert(uri);
|
||||
assert(port);
|
||||
|
||||
URL_COMPONENTS url_comp = {0};
|
||||
url_comp.dwStructSize = sizeof(url_comp);
|
||||
url_comp.lpszScheme = scheme;
|
||||
url_comp.dwSchemeLength = static_cast<DWORD>(scheme_buffer_length);
|
||||
url_comp.lpszHostName = host;
|
||||
url_comp.dwHostNameLength = static_cast<DWORD>(host_buffer_length);
|
||||
url_comp.lpszUrlPath = uri;
|
||||
url_comp.dwUrlPathLength = static_cast<DWORD>(uri_buffer_length);
|
||||
|
||||
bool result = !!::WinHttpCrackUrl(url, 0, flags, &url_comp);
|
||||
if (result) {
|
||||
*port = static_cast<int>(url_comp.nPort);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WinHttpClient::Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const {
|
||||
*session_handle = FromHINTERNET(::WinHttpOpen(user_agent,
|
||||
MapAccessType(access_type),
|
||||
proxy_name,
|
||||
proxy_bypass,
|
||||
0));
|
||||
|
||||
return !!(*session_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const {
|
||||
assert(server);
|
||||
|
||||
// Uses NULL user name and password to connect.
|
||||
*connection_handle = FromHINTERNET(::WinHttpConnect(
|
||||
ToHINTERNET(session_handle),
|
||||
server,
|
||||
static_cast<INTERNET_PORT>(port),
|
||||
NULL));
|
||||
return !!(*connection_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const {
|
||||
assert(connection_handle);
|
||||
assert(verb);
|
||||
assert(uri);
|
||||
assert(request_handle);
|
||||
|
||||
*request_handle = FromHINTERNET(::WinHttpOpenRequest(
|
||||
ToHINTERNET(connection_handle),
|
||||
verb,
|
||||
uri,
|
||||
version,
|
||||
referrer,
|
||||
WINHTTP_DEFAULT_ACCEPT_TYPES,
|
||||
is_secure ? WINHTTP_FLAG_SECURE : 0));
|
||||
return !!(*request_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::WinHttpSendRequest(ToHINTERNET(request_handle),
|
||||
headers,
|
||||
headers_length,
|
||||
NULL,
|
||||
0,
|
||||
WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH,
|
||||
NULL);
|
||||
}
|
||||
|
||||
bool WinHttpClient::ReceiveResponse(HttpHandle request_handle) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::WinHttpReceiveResponse(ToHINTERNET(request_handle), NULL);
|
||||
}
|
||||
|
||||
bool WinHttpClient::GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const {
|
||||
TCHAR http_status_string[4] = {0};
|
||||
DWORD http_status_string_size = sizeof(http_status_string);
|
||||
if (!::WinHttpQueryHeaders(ToHINTERNET(request_handle),
|
||||
WINHTTP_QUERY_STATUS_CODE,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
static_cast<void*>(&http_status_string),
|
||||
&http_status_string_size, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*status_code = static_cast<DWORD>(_tcstol(http_status_string, NULL, 10));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const {
|
||||
assert(request_handle);
|
||||
assert(content_length);
|
||||
|
||||
TCHAR content_length_string[11] = {0};
|
||||
DWORD content_length_string_size = sizeof(content_length_string);
|
||||
if (!::WinHttpQueryHeaders(ToHINTERNET(request_handle),
|
||||
WINHTTP_QUERY_CONTENT_LENGTH,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
static_cast<void*>(&content_length_string),
|
||||
&content_length_string_size, 0)) {
|
||||
*content_length = kUnknownContentLength;
|
||||
} else {
|
||||
*content_length =
|
||||
static_cast<DWORD>(wcstol(content_length_string, NULL, 10));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const {
|
||||
assert(request_handle);
|
||||
assert(buffer);
|
||||
assert(bytes_read);
|
||||
|
||||
DWORD bytes_read_local = 0;
|
||||
if (!::WinHttpReadData(ToHINTERNET(request_handle),
|
||||
buffer,
|
||||
buffer_length,
|
||||
&bytes_read_local)) {
|
||||
return false;
|
||||
}
|
||||
*bytes_read = bytes_read_local;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::Close(HttpHandle handle) const {
|
||||
assert(handle);
|
||||
return !!::WinHttpCloseHandle(ToHINTERNET(handle));
|
||||
}
|
||||
|
||||
DWORD WinHttpClient::MapAccessType(DWORD access_type) {
|
||||
switch (static_cast<AccessType>(access_type)) {
|
||||
case ACCESS_TYPE_PRECONFIG:
|
||||
default:
|
||||
return WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
|
||||
case ACCESS_TYPE_DIRECT:
|
||||
return WINHTTP_ACCESS_TYPE_NO_PROXY;
|
||||
case ACCESS_TYPE_PROXY:
|
||||
return WINHTTP_ACCESS_TYPE_NAMED_PROXY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HINTERNET WinHttpClient::ToHINTERNET(HttpHandle handle) {
|
||||
return static_cast<HINTERNET>(handle);
|
||||
}
|
||||
|
||||
HttpHandle WinHttpClient::FromHINTERNET(HINTERNET handle) {
|
||||
return static_cast<HttpHandle>(handle);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
HttpClient* CreateWinHttpClient(const TCHAR* url) {
|
||||
assert(url);
|
||||
|
||||
internal::WinHttpClient winhttp;
|
||||
wchar_t scheme[16] = {0};
|
||||
wchar_t host[256] = {0};
|
||||
wchar_t path[256] = {0};
|
||||
int port = 0;
|
||||
|
||||
if (!winhttp.CrackUrl(url,
|
||||
0,
|
||||
scheme,
|
||||
sizeof(scheme)/sizeof(scheme[0]),
|
||||
host,
|
||||
sizeof(host)/sizeof(host[0]),
|
||||
path,
|
||||
sizeof(path)/sizeof(path[0]),
|
||||
&port)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_wcsicmp(scheme, L"https") == 0) {
|
||||
// Winhttp under WINE doesn't support wildcard certificates, so avoid
|
||||
// to use it if the scheme is https. The caller should fall back to
|
||||
// use wininet if NULL is returned.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new internal::WinHttpClient();
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "tools/windows/converter_exe/winhttp_client.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <vector>
|
||||
|
||||
namespace crash {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This class implements HttpClient based on WinInet APIs.
|
||||
class WinHttpClient : public HttpClient {
|
||||
public:
|
||||
virtual ~WinHttpClient() {}
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const;
|
||||
virtual bool Close(HttpHandle handle) const;
|
||||
|
||||
private:
|
||||
static DWORD MapAccessType(DWORD access_type);
|
||||
static HINTERNET ToHINTERNET(HttpHandle handle);
|
||||
static HttpHandle FromHINTERNET(HINTERNET handle);
|
||||
};
|
||||
|
||||
bool WinHttpClient::CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const {
|
||||
assert(url);
|
||||
assert(scheme);
|
||||
assert(host);
|
||||
assert(uri);
|
||||
assert(port);
|
||||
|
||||
URL_COMPONENTS url_comp = {0};
|
||||
url_comp.dwStructSize = sizeof(url_comp);
|
||||
url_comp.lpszScheme = scheme;
|
||||
url_comp.dwSchemeLength = static_cast<DWORD>(scheme_buffer_length);
|
||||
url_comp.lpszHostName = host;
|
||||
url_comp.dwHostNameLength = static_cast<DWORD>(host_buffer_length);
|
||||
url_comp.lpszUrlPath = uri;
|
||||
url_comp.dwUrlPathLength = static_cast<DWORD>(uri_buffer_length);
|
||||
|
||||
bool result = !!::WinHttpCrackUrl(url, 0, flags, &url_comp);
|
||||
if (result) {
|
||||
*port = static_cast<int>(url_comp.nPort);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WinHttpClient::Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const {
|
||||
*session_handle = FromHINTERNET(::WinHttpOpen(user_agent,
|
||||
MapAccessType(access_type),
|
||||
proxy_name,
|
||||
proxy_bypass,
|
||||
0));
|
||||
|
||||
return !!(*session_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const {
|
||||
assert(server);
|
||||
|
||||
// Uses NULL user name and password to connect.
|
||||
*connection_handle = FromHINTERNET(::WinHttpConnect(
|
||||
ToHINTERNET(session_handle),
|
||||
server,
|
||||
static_cast<INTERNET_PORT>(port),
|
||||
NULL));
|
||||
return !!(*connection_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const {
|
||||
assert(connection_handle);
|
||||
assert(verb);
|
||||
assert(uri);
|
||||
assert(request_handle);
|
||||
|
||||
*request_handle = FromHINTERNET(::WinHttpOpenRequest(
|
||||
ToHINTERNET(connection_handle),
|
||||
verb,
|
||||
uri,
|
||||
version,
|
||||
referrer,
|
||||
WINHTTP_DEFAULT_ACCEPT_TYPES,
|
||||
is_secure ? WINHTTP_FLAG_SECURE : 0));
|
||||
return !!(*request_handle);
|
||||
}
|
||||
|
||||
bool WinHttpClient::SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::WinHttpSendRequest(ToHINTERNET(request_handle),
|
||||
headers,
|
||||
headers_length,
|
||||
NULL,
|
||||
0,
|
||||
WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH,
|
||||
NULL);
|
||||
}
|
||||
|
||||
bool WinHttpClient::ReceiveResponse(HttpHandle request_handle) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::WinHttpReceiveResponse(ToHINTERNET(request_handle), NULL);
|
||||
}
|
||||
|
||||
bool WinHttpClient::GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const {
|
||||
TCHAR http_status_string[4] = {0};
|
||||
DWORD http_status_string_size = sizeof(http_status_string);
|
||||
if (!::WinHttpQueryHeaders(ToHINTERNET(request_handle),
|
||||
WINHTTP_QUERY_STATUS_CODE,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
static_cast<void*>(&http_status_string),
|
||||
&http_status_string_size, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*status_code = static_cast<DWORD>(_tcstol(http_status_string, NULL, 10));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const {
|
||||
assert(request_handle);
|
||||
assert(content_length);
|
||||
|
||||
TCHAR content_length_string[11] = {0};
|
||||
DWORD content_length_string_size = sizeof(content_length_string);
|
||||
if (!::WinHttpQueryHeaders(ToHINTERNET(request_handle),
|
||||
WINHTTP_QUERY_CONTENT_LENGTH,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX,
|
||||
static_cast<void*>(&content_length_string),
|
||||
&content_length_string_size, 0)) {
|
||||
*content_length = kUnknownContentLength;
|
||||
} else {
|
||||
*content_length =
|
||||
static_cast<DWORD>(wcstol(content_length_string, NULL, 10));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const {
|
||||
assert(request_handle);
|
||||
assert(buffer);
|
||||
assert(bytes_read);
|
||||
|
||||
DWORD bytes_read_local = 0;
|
||||
if (!::WinHttpReadData(ToHINTERNET(request_handle),
|
||||
buffer,
|
||||
buffer_length,
|
||||
&bytes_read_local)) {
|
||||
return false;
|
||||
}
|
||||
*bytes_read = bytes_read_local;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinHttpClient::Close(HttpHandle handle) const {
|
||||
assert(handle);
|
||||
return !!::WinHttpCloseHandle(ToHINTERNET(handle));
|
||||
}
|
||||
|
||||
DWORD WinHttpClient::MapAccessType(DWORD access_type) {
|
||||
switch (static_cast<AccessType>(access_type)) {
|
||||
case ACCESS_TYPE_PRECONFIG:
|
||||
default:
|
||||
return WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
|
||||
case ACCESS_TYPE_DIRECT:
|
||||
return WINHTTP_ACCESS_TYPE_NO_PROXY;
|
||||
case ACCESS_TYPE_PROXY:
|
||||
return WINHTTP_ACCESS_TYPE_NAMED_PROXY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HINTERNET WinHttpClient::ToHINTERNET(HttpHandle handle) {
|
||||
return static_cast<HINTERNET>(handle);
|
||||
}
|
||||
|
||||
HttpHandle WinHttpClient::FromHINTERNET(HINTERNET handle) {
|
||||
return static_cast<HttpHandle>(handle);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
HttpClient* CreateWinHttpClient(const TCHAR* url) {
|
||||
assert(url);
|
||||
|
||||
internal::WinHttpClient winhttp;
|
||||
wchar_t scheme[16] = {0};
|
||||
wchar_t host[256] = {0};
|
||||
wchar_t path[256] = {0};
|
||||
int port = 0;
|
||||
|
||||
if (!winhttp.CrackUrl(url,
|
||||
0,
|
||||
scheme,
|
||||
sizeof(scheme)/sizeof(scheme[0]),
|
||||
host,
|
||||
sizeof(host)/sizeof(host[0]),
|
||||
path,
|
||||
sizeof(path)/sizeof(path[0]),
|
||||
&port)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (_wcsicmp(scheme, L"https") == 0) {
|
||||
// Winhttp under WINE doesn't support wildcard certificates, so avoid
|
||||
// to use it if the scheme is https. The caller should fall back to
|
||||
// use wininet if NULL is returned.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new internal::WinHttpClient();
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
|
||||
#include "tools/windows/converter_exe/http_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
HttpClient* CreateWinHttpClient(const TCHAR* url);
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
|
||||
#include "tools/windows/converter_exe/http_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
HttpClient* CreateWinHttpClient(const TCHAR* url);
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_WINHTTP_CLIENT_H_
|
||||
|
||||
@@ -1,278 +1,278 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "tools/windows/converter_exe/wininet_client.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
namespace crash {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This class implements HttpClient based on WinInet APIs.
|
||||
class WinInetClient : public HttpClient {
|
||||
public:
|
||||
virtual ~WinInetClient() {}
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const;
|
||||
virtual bool Close(HttpHandle handle) const;
|
||||
|
||||
private:
|
||||
static DWORD MapAccessType(DWORD access_type);
|
||||
static HINTERNET ToHINTERNET(HttpHandle handle);
|
||||
static HttpHandle FromHINTERNET(HINTERNET handle);
|
||||
};
|
||||
|
||||
bool WinInetClient::CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const {
|
||||
assert(url);
|
||||
assert(scheme);
|
||||
assert(host);
|
||||
assert(uri);
|
||||
assert(port);
|
||||
|
||||
URL_COMPONENTS url_comp = {0};
|
||||
url_comp.dwStructSize = sizeof(url_comp);
|
||||
url_comp.lpszScheme = scheme;
|
||||
url_comp.dwSchemeLength = static_cast<DWORD>(scheme_buffer_length);
|
||||
url_comp.lpszHostName = host;
|
||||
url_comp.dwHostNameLength = static_cast<DWORD>(host_buffer_length);
|
||||
url_comp.lpszUrlPath = uri;
|
||||
url_comp.dwUrlPathLength = static_cast<DWORD>(uri_buffer_length);
|
||||
|
||||
bool result = !!::InternetCrackUrl(url, 0, flags, &url_comp);
|
||||
if (result) {
|
||||
*port = static_cast<int>(url_comp.nPort);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WinInetClient::Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const {
|
||||
*session_handle = FromHINTERNET(::InternetOpen(user_agent,
|
||||
MapAccessType(access_type),
|
||||
proxy_name,
|
||||
proxy_bypass,
|
||||
0));
|
||||
return !!(*session_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const {
|
||||
assert(server);
|
||||
|
||||
// Uses NULL user name and password to connect. Always uses http service.
|
||||
*connection_handle = FromHINTERNET(::InternetConnect(
|
||||
ToHINTERNET(session_handle),
|
||||
server,
|
||||
static_cast<INTERNET_PORT>(port),
|
||||
NULL,
|
||||
NULL,
|
||||
INTERNET_SERVICE_HTTP,
|
||||
0,
|
||||
0));
|
||||
return !!(*connection_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const {
|
||||
assert(connection_handle);
|
||||
assert(verb);
|
||||
assert(uri);
|
||||
|
||||
*request_handle = FromHINTERNET(::HttpOpenRequest(
|
||||
ToHINTERNET(connection_handle),
|
||||
verb,
|
||||
uri,
|
||||
version,
|
||||
referrer,
|
||||
NULL,
|
||||
is_secure ? INTERNET_FLAG_SECURE : 0,
|
||||
NULL));
|
||||
return !!(*request_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::HttpSendRequest(ToHINTERNET(request_handle),
|
||||
headers,
|
||||
headers_length,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
|
||||
bool WinInetClient::ReceiveResponse(HttpHandle) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const {
|
||||
assert(request_handle);
|
||||
|
||||
TCHAR http_status_string[4] = {0};
|
||||
DWORD http_status_string_size = sizeof(http_status_string);
|
||||
if (!::HttpQueryInfo(ToHINTERNET(request_handle),
|
||||
HTTP_QUERY_STATUS_CODE,
|
||||
static_cast<void*>(&http_status_string),
|
||||
&http_status_string_size,
|
||||
0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*status_code = _tcstol(http_status_string, NULL, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const {
|
||||
assert(request_handle);
|
||||
assert(content_length);
|
||||
|
||||
TCHAR content_length_string[11];
|
||||
DWORD content_length_string_size = sizeof(content_length_string);
|
||||
if (!::HttpQueryInfo(ToHINTERNET(request_handle),
|
||||
HTTP_QUERY_CONTENT_LENGTH,
|
||||
static_cast<void*>(&content_length_string),
|
||||
&content_length_string_size,
|
||||
0)) {
|
||||
*content_length = kUnknownContentLength;
|
||||
} else {
|
||||
*content_length = wcstol(content_length_string, NULL, 10);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const {
|
||||
assert(request_handle);
|
||||
assert(buffer);
|
||||
assert(bytes_read);
|
||||
|
||||
DWORD bytes_read_local = 0;
|
||||
if (!::InternetReadFile(ToHINTERNET(request_handle),
|
||||
buffer,
|
||||
buffer_length,
|
||||
&bytes_read_local)) {
|
||||
return false;
|
||||
}
|
||||
*bytes_read = bytes_read_local;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::Close(HttpHandle handle) const {
|
||||
assert(handle);
|
||||
return !!::InternetCloseHandle(ToHINTERNET(handle));
|
||||
}
|
||||
|
||||
DWORD WinInetClient::MapAccessType(DWORD access_type) {
|
||||
switch (static_cast<AccessType>(access_type)) {
|
||||
case ACCESS_TYPE_PRECONFIG:
|
||||
default:
|
||||
return INTERNET_OPEN_TYPE_PRECONFIG;
|
||||
case ACCESS_TYPE_DIRECT:
|
||||
return INTERNET_OPEN_TYPE_DIRECT;
|
||||
case ACCESS_TYPE_PROXY:
|
||||
return INTERNET_OPEN_TYPE_PROXY;
|
||||
}
|
||||
}
|
||||
|
||||
HINTERNET WinInetClient::ToHINTERNET(HttpHandle handle) {
|
||||
return static_cast<HINTERNET>(handle);
|
||||
}
|
||||
|
||||
HttpHandle WinInetClient::FromHINTERNET(HINTERNET handle) {
|
||||
return static_cast<HttpHandle>(handle);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
HttpClient* CreateWinInetClient(const TCHAR*) {
|
||||
return new internal::WinInetClient();
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "tools/windows/converter_exe/wininet_client.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
namespace crash {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This class implements HttpClient based on WinInet APIs.
|
||||
class WinInetClient : public HttpClient {
|
||||
public:
|
||||
virtual ~WinInetClient() {}
|
||||
virtual bool CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const;
|
||||
virtual bool Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const;
|
||||
virtual bool Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const;
|
||||
virtual bool OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const;
|
||||
virtual bool SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const;
|
||||
virtual bool ReceiveResponse(HttpHandle request_handle) const;
|
||||
virtual bool GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const;
|
||||
virtual bool GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const;
|
||||
virtual bool ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const;
|
||||
virtual bool Close(HttpHandle handle) const;
|
||||
|
||||
private:
|
||||
static DWORD MapAccessType(DWORD access_type);
|
||||
static HINTERNET ToHINTERNET(HttpHandle handle);
|
||||
static HttpHandle FromHINTERNET(HINTERNET handle);
|
||||
};
|
||||
|
||||
bool WinInetClient::CrackUrl(const TCHAR* url,
|
||||
DWORD flags,
|
||||
TCHAR* scheme,
|
||||
size_t scheme_buffer_length,
|
||||
TCHAR* host,
|
||||
size_t host_buffer_length,
|
||||
TCHAR* uri,
|
||||
size_t uri_buffer_length,
|
||||
int* port) const {
|
||||
assert(url);
|
||||
assert(scheme);
|
||||
assert(host);
|
||||
assert(uri);
|
||||
assert(port);
|
||||
|
||||
URL_COMPONENTS url_comp = {0};
|
||||
url_comp.dwStructSize = sizeof(url_comp);
|
||||
url_comp.lpszScheme = scheme;
|
||||
url_comp.dwSchemeLength = static_cast<DWORD>(scheme_buffer_length);
|
||||
url_comp.lpszHostName = host;
|
||||
url_comp.dwHostNameLength = static_cast<DWORD>(host_buffer_length);
|
||||
url_comp.lpszUrlPath = uri;
|
||||
url_comp.dwUrlPathLength = static_cast<DWORD>(uri_buffer_length);
|
||||
|
||||
bool result = !!::InternetCrackUrl(url, 0, flags, &url_comp);
|
||||
if (result) {
|
||||
*port = static_cast<int>(url_comp.nPort);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WinInetClient::Open(const TCHAR* user_agent,
|
||||
DWORD access_type,
|
||||
const TCHAR* proxy_name,
|
||||
const TCHAR* proxy_bypass,
|
||||
HttpHandle* session_handle) const {
|
||||
*session_handle = FromHINTERNET(::InternetOpen(user_agent,
|
||||
MapAccessType(access_type),
|
||||
proxy_name,
|
||||
proxy_bypass,
|
||||
0));
|
||||
return !!(*session_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::Connect(HttpHandle session_handle,
|
||||
const TCHAR* server,
|
||||
int port,
|
||||
HttpHandle* connection_handle) const {
|
||||
assert(server);
|
||||
|
||||
// Uses NULL user name and password to connect. Always uses http service.
|
||||
*connection_handle = FromHINTERNET(::InternetConnect(
|
||||
ToHINTERNET(session_handle),
|
||||
server,
|
||||
static_cast<INTERNET_PORT>(port),
|
||||
NULL,
|
||||
NULL,
|
||||
INTERNET_SERVICE_HTTP,
|
||||
0,
|
||||
0));
|
||||
return !!(*connection_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::OpenRequest(HttpHandle connection_handle,
|
||||
const TCHAR* verb,
|
||||
const TCHAR* uri,
|
||||
const TCHAR* version,
|
||||
const TCHAR* referrer,
|
||||
bool is_secure,
|
||||
HttpHandle* request_handle) const {
|
||||
assert(connection_handle);
|
||||
assert(verb);
|
||||
assert(uri);
|
||||
|
||||
*request_handle = FromHINTERNET(::HttpOpenRequest(
|
||||
ToHINTERNET(connection_handle),
|
||||
verb,
|
||||
uri,
|
||||
version,
|
||||
referrer,
|
||||
NULL,
|
||||
is_secure ? INTERNET_FLAG_SECURE : 0,
|
||||
NULL));
|
||||
return !!(*request_handle);
|
||||
}
|
||||
|
||||
bool WinInetClient::SendRequest(HttpHandle request_handle,
|
||||
const TCHAR* headers,
|
||||
DWORD headers_length) const {
|
||||
assert(request_handle);
|
||||
|
||||
return !!::HttpSendRequest(ToHINTERNET(request_handle),
|
||||
headers,
|
||||
headers_length,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
|
||||
bool WinInetClient::ReceiveResponse(HttpHandle) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::GetHttpStatusCode(HttpHandle request_handle,
|
||||
int* status_code) const {
|
||||
assert(request_handle);
|
||||
|
||||
TCHAR http_status_string[4] = {0};
|
||||
DWORD http_status_string_size = sizeof(http_status_string);
|
||||
if (!::HttpQueryInfo(ToHINTERNET(request_handle),
|
||||
HTTP_QUERY_STATUS_CODE,
|
||||
static_cast<void*>(&http_status_string),
|
||||
&http_status_string_size,
|
||||
0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*status_code = _tcstol(http_status_string, NULL, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::GetContentLength(HttpHandle request_handle,
|
||||
DWORD* content_length) const {
|
||||
assert(request_handle);
|
||||
assert(content_length);
|
||||
|
||||
TCHAR content_length_string[11];
|
||||
DWORD content_length_string_size = sizeof(content_length_string);
|
||||
if (!::HttpQueryInfo(ToHINTERNET(request_handle),
|
||||
HTTP_QUERY_CONTENT_LENGTH,
|
||||
static_cast<void*>(&content_length_string),
|
||||
&content_length_string_size,
|
||||
0)) {
|
||||
*content_length = kUnknownContentLength;
|
||||
} else {
|
||||
*content_length = wcstol(content_length_string, NULL, 10);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::ReadData(HttpHandle request_handle,
|
||||
void* buffer,
|
||||
DWORD buffer_length,
|
||||
DWORD* bytes_read) const {
|
||||
assert(request_handle);
|
||||
assert(buffer);
|
||||
assert(bytes_read);
|
||||
|
||||
DWORD bytes_read_local = 0;
|
||||
if (!::InternetReadFile(ToHINTERNET(request_handle),
|
||||
buffer,
|
||||
buffer_length,
|
||||
&bytes_read_local)) {
|
||||
return false;
|
||||
}
|
||||
*bytes_read = bytes_read_local;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinInetClient::Close(HttpHandle handle) const {
|
||||
assert(handle);
|
||||
return !!::InternetCloseHandle(ToHINTERNET(handle));
|
||||
}
|
||||
|
||||
DWORD WinInetClient::MapAccessType(DWORD access_type) {
|
||||
switch (static_cast<AccessType>(access_type)) {
|
||||
case ACCESS_TYPE_PRECONFIG:
|
||||
default:
|
||||
return INTERNET_OPEN_TYPE_PRECONFIG;
|
||||
case ACCESS_TYPE_DIRECT:
|
||||
return INTERNET_OPEN_TYPE_DIRECT;
|
||||
case ACCESS_TYPE_PROXY:
|
||||
return INTERNET_OPEN_TYPE_PROXY;
|
||||
}
|
||||
}
|
||||
|
||||
HINTERNET WinInetClient::ToHINTERNET(HttpHandle handle) {
|
||||
return static_cast<HINTERNET>(handle);
|
||||
}
|
||||
|
||||
HttpHandle WinInetClient::FromHINTERNET(HINTERNET handle) {
|
||||
return static_cast<HttpHandle>(handle);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
HttpClient* CreateWinInetClient(const TCHAR*) {
|
||||
return new internal::WinInetClient();
|
||||
}
|
||||
|
||||
} // namespace crash
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
// Copyright 2019 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
|
||||
#include "tools/windows/converter_exe/http_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
HttpClient* CreateWinInetClient(const TCHAR* url);
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
#define TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
|
||||
#include "tools/windows/converter_exe/http_client.h"
|
||||
|
||||
namespace crash {
|
||||
|
||||
HttpClient* CreateWinInetClient(const TCHAR* url);
|
||||
|
||||
} // namespace crash
|
||||
|
||||
#endif // TOOLS_WINDOWS_CONVERTER_EXE_WININET_CLIENT_H_
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
# Copyright 2013 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,244 +1,244 @@
|
||||
// Copyright 2003 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "breakpad_googletest_includes.h"
|
||||
|
||||
namespace tools {
|
||||
namespace windows {
|
||||
namespace dump_syms {
|
||||
|
||||
namespace {
|
||||
|
||||
// Root names of PDB and dumped symbol files to be regression tested. These are
|
||||
// specified in complexity of the resulting dumped symbol files.
|
||||
const wchar_t* kRootNames[] = {
|
||||
// A PDB file with no OMAP data.
|
||||
L"dump_syms_regtest",
|
||||
// A PDB file with OMAP data for an image that has been function-level
|
||||
// reordered.
|
||||
L"omap_reorder_funcs",
|
||||
// A PDB file with OMAP data for an image that had new content injected, all
|
||||
// of it with source data.
|
||||
L"omap_stretched_filled",
|
||||
// A PDB file with OMAP data for an image that had new content injected, but
|
||||
// without source data.
|
||||
L"omap_stretched",
|
||||
// A PDB file with OMAP data for an image that has been basic block reordered.
|
||||
L"omap_reorder_bbs",
|
||||
// A 64bit PDB file with no OMAP data.
|
||||
L"dump_syms_regtest64",
|
||||
};
|
||||
|
||||
const wchar_t* kPEOnlyRootNames[] = {
|
||||
L"pe_only_symbol_test",
|
||||
};
|
||||
|
||||
void TrimLastComponent(const std::wstring& path,
|
||||
std::wstring* trimmed,
|
||||
std::wstring* component) {
|
||||
size_t len = path.size();
|
||||
while (len > 0 && path[len - 1] != '\\')
|
||||
--len;
|
||||
|
||||
if (component != NULL)
|
||||
component->assign(path.c_str() + len, path.c_str() + path.size());
|
||||
|
||||
while (len > 0 && path[len - 1] == '\\')
|
||||
--len;
|
||||
|
||||
if (trimmed != NULL)
|
||||
trimmed->assign(path.c_str(), len);
|
||||
}
|
||||
|
||||
// Get the directory of the current executable.
|
||||
bool GetSelfDirectory(std::wstring* self_dir) {
|
||||
std::wstring command_line = GetCommandLineW();
|
||||
|
||||
int num_args = 0;
|
||||
wchar_t** args = NULL;
|
||||
args = ::CommandLineToArgvW(command_line.c_str(), &num_args);
|
||||
if (args == NULL)
|
||||
return false;
|
||||
|
||||
*self_dir = args[0];
|
||||
TrimLastComponent(*self_dir, self_dir, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RunCommand(const std::wstring& command_line,
|
||||
std::string* stdout_string) {
|
||||
// Create a PIPE for the child process stdout.
|
||||
HANDLE child_stdout_read = 0;
|
||||
HANDLE child_stdout_write = 0;
|
||||
SECURITY_ATTRIBUTES sec_attr_stdout = {};
|
||||
sec_attr_stdout.nLength = sizeof(sec_attr_stdout);
|
||||
sec_attr_stdout.bInheritHandle = TRUE;
|
||||
ASSERT_TRUE(::CreatePipe(&child_stdout_read, &child_stdout_write,
|
||||
&sec_attr_stdout, 0));
|
||||
ASSERT_TRUE(::SetHandleInformation(child_stdout_read, HANDLE_FLAG_INHERIT,
|
||||
0));
|
||||
|
||||
// Create a PIPE for the child process stdin.
|
||||
HANDLE child_stdin_read = 0;
|
||||
HANDLE child_stdin_write = 0;
|
||||
SECURITY_ATTRIBUTES sec_attr_stdin = {};
|
||||
sec_attr_stdin.nLength = sizeof(sec_attr_stdin);
|
||||
sec_attr_stdin.bInheritHandle = TRUE;
|
||||
ASSERT_TRUE(::CreatePipe(&child_stdin_read, &child_stdin_write,
|
||||
&sec_attr_stdin, 0));
|
||||
ASSERT_TRUE(::SetHandleInformation(child_stdin_write, HANDLE_FLAG_INHERIT,
|
||||
0));
|
||||
|
||||
// Startup the child.
|
||||
STARTUPINFO startup_info = {};
|
||||
PROCESS_INFORMATION process_info = {};
|
||||
startup_info.cb = sizeof(STARTUPINFO);
|
||||
startup_info.hStdError = NULL;
|
||||
startup_info.hStdInput = child_stdin_read;
|
||||
startup_info.hStdOutput = child_stdout_write;
|
||||
startup_info.dwFlags = STARTF_USESTDHANDLES;
|
||||
ASSERT_TRUE(::CreateProcessW(NULL, (LPWSTR)command_line.c_str(), NULL, NULL,
|
||||
TRUE, 0, NULL, NULL,
|
||||
&startup_info, &process_info));
|
||||
|
||||
// Collect the output.
|
||||
ASSERT_TRUE(::CloseHandle(child_stdout_write));
|
||||
char buffer[4096] = {};
|
||||
DWORD bytes_read = 0;
|
||||
while (::ReadFile(child_stdout_read, buffer, sizeof(buffer), &bytes_read,
|
||||
NULL) && bytes_read > 0) {
|
||||
stdout_string->append(buffer, bytes_read);
|
||||
}
|
||||
|
||||
// Wait for the process to finish.
|
||||
::WaitForSingleObject(process_info.hProcess, INFINITE);
|
||||
|
||||
// Shut down all of our handles.
|
||||
ASSERT_TRUE(::CloseHandle(process_info.hThread));
|
||||
ASSERT_TRUE(::CloseHandle(process_info.hProcess));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdin_write));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdin_read));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdout_read));
|
||||
}
|
||||
|
||||
void GetFileContents(const std::wstring& path, std::string* content) {
|
||||
FILE* f = ::_wfopen(path.c_str(), L"rb");
|
||||
ASSERT_TRUE(f != NULL);
|
||||
|
||||
char buffer[4096] = {};
|
||||
while (true) {
|
||||
size_t bytes_read = ::fread(buffer, 1, sizeof(buffer), f);
|
||||
if (bytes_read == 0)
|
||||
break;
|
||||
content->append(buffer, bytes_read);
|
||||
}
|
||||
}
|
||||
|
||||
class DumpSymsRegressionTest : public testing::TestWithParam<const wchar_t*> {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
std::wstring self_dir;
|
||||
ASSERT_TRUE(GetSelfDirectory(&self_dir));
|
||||
dump_syms_exe = self_dir + L"\\dump_syms.exe";
|
||||
|
||||
TrimLastComponent(self_dir, &testdata_dir, NULL);
|
||||
testdata_dir += L"\\testdata";
|
||||
}
|
||||
|
||||
std::wstring dump_syms_exe;
|
||||
std::wstring testdata_dir;
|
||||
};
|
||||
|
||||
class DumpSymsPEOnlyRegressionTest : public testing::TestWithParam<const wchar_t*> {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
std::wstring self_dir;
|
||||
ASSERT_TRUE(GetSelfDirectory(&self_dir));
|
||||
dump_syms_exe = self_dir + L"\\dump_syms.exe";
|
||||
|
||||
TrimLastComponent(self_dir, &testdata_dir, NULL);
|
||||
testdata_dir += L"\\testdata";
|
||||
}
|
||||
|
||||
std::wstring dump_syms_exe;
|
||||
std::wstring testdata_dir;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
TEST_P(DumpSymsRegressionTest, EnsureDumpedSymbolsMatch) {
|
||||
const wchar_t* root_name = GetParam();
|
||||
std::wstring root_path = testdata_dir + L"\\" + root_name;
|
||||
|
||||
std::wstring sym_path = root_path + L".sym";
|
||||
std::string expected_symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(GetFileContents(sym_path, &expected_symbols));
|
||||
|
||||
std::wstring pdb_path = root_path + L".pdb";
|
||||
std::wstring command_line = L"\"" + dump_syms_exe + L"\" \"" +
|
||||
pdb_path + L"\"";
|
||||
std::string symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(RunCommand(command_line, &symbols));
|
||||
|
||||
EXPECT_EQ(expected_symbols, symbols);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DumpSyms, DumpSymsRegressionTest,
|
||||
testing::ValuesIn(kRootNames));
|
||||
|
||||
TEST_P(DumpSymsPEOnlyRegressionTest, EnsurePEOnlyDumpedSymbolsMatch) {
|
||||
const wchar_t* root_name = GetParam();
|
||||
std::wstring root_path = testdata_dir + L"\\" + root_name;
|
||||
|
||||
std::wstring sym_path = root_path + L".sym";
|
||||
std::string expected_symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(GetFileContents(sym_path, &expected_symbols));
|
||||
|
||||
std::wstring dll_path = root_path + L".dll";
|
||||
std::wstring command_line = L"\"" + dump_syms_exe + L"\" --pe \"" +
|
||||
dll_path + L"\"";
|
||||
std::string symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(RunCommand(command_line, &symbols));
|
||||
|
||||
EXPECT_EQ(expected_symbols, symbols);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PEOnlyDumpSyms, DumpSymsPEOnlyRegressionTest,
|
||||
testing::ValuesIn(kPEOnlyRootNames));
|
||||
|
||||
|
||||
} // namespace dump_syms
|
||||
} // namespace windows
|
||||
} // namespace tools
|
||||
// Copyright 2003 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "breakpad_googletest_includes.h"
|
||||
|
||||
namespace tools {
|
||||
namespace windows {
|
||||
namespace dump_syms {
|
||||
|
||||
namespace {
|
||||
|
||||
// Root names of PDB and dumped symbol files to be regression tested. These are
|
||||
// specified in complexity of the resulting dumped symbol files.
|
||||
const wchar_t* kRootNames[] = {
|
||||
// A PDB file with no OMAP data.
|
||||
L"dump_syms_regtest",
|
||||
// A PDB file with OMAP data for an image that has been function-level
|
||||
// reordered.
|
||||
L"omap_reorder_funcs",
|
||||
// A PDB file with OMAP data for an image that had new content injected, all
|
||||
// of it with source data.
|
||||
L"omap_stretched_filled",
|
||||
// A PDB file with OMAP data for an image that had new content injected, but
|
||||
// without source data.
|
||||
L"omap_stretched",
|
||||
// A PDB file with OMAP data for an image that has been basic block reordered.
|
||||
L"omap_reorder_bbs",
|
||||
// A 64bit PDB file with no OMAP data.
|
||||
L"dump_syms_regtest64",
|
||||
};
|
||||
|
||||
const wchar_t* kPEOnlyRootNames[] = {
|
||||
L"pe_only_symbol_test",
|
||||
};
|
||||
|
||||
void TrimLastComponent(const std::wstring& path,
|
||||
std::wstring* trimmed,
|
||||
std::wstring* component) {
|
||||
size_t len = path.size();
|
||||
while (len > 0 && path[len - 1] != '\\')
|
||||
--len;
|
||||
|
||||
if (component != NULL)
|
||||
component->assign(path.c_str() + len, path.c_str() + path.size());
|
||||
|
||||
while (len > 0 && path[len - 1] == '\\')
|
||||
--len;
|
||||
|
||||
if (trimmed != NULL)
|
||||
trimmed->assign(path.c_str(), len);
|
||||
}
|
||||
|
||||
// Get the directory of the current executable.
|
||||
bool GetSelfDirectory(std::wstring* self_dir) {
|
||||
std::wstring command_line = GetCommandLineW();
|
||||
|
||||
int num_args = 0;
|
||||
wchar_t** args = NULL;
|
||||
args = ::CommandLineToArgvW(command_line.c_str(), &num_args);
|
||||
if (args == NULL)
|
||||
return false;
|
||||
|
||||
*self_dir = args[0];
|
||||
TrimLastComponent(*self_dir, self_dir, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RunCommand(const std::wstring& command_line,
|
||||
std::string* stdout_string) {
|
||||
// Create a PIPE for the child process stdout.
|
||||
HANDLE child_stdout_read = 0;
|
||||
HANDLE child_stdout_write = 0;
|
||||
SECURITY_ATTRIBUTES sec_attr_stdout = {};
|
||||
sec_attr_stdout.nLength = sizeof(sec_attr_stdout);
|
||||
sec_attr_stdout.bInheritHandle = TRUE;
|
||||
ASSERT_TRUE(::CreatePipe(&child_stdout_read, &child_stdout_write,
|
||||
&sec_attr_stdout, 0));
|
||||
ASSERT_TRUE(::SetHandleInformation(child_stdout_read, HANDLE_FLAG_INHERIT,
|
||||
0));
|
||||
|
||||
// Create a PIPE for the child process stdin.
|
||||
HANDLE child_stdin_read = 0;
|
||||
HANDLE child_stdin_write = 0;
|
||||
SECURITY_ATTRIBUTES sec_attr_stdin = {};
|
||||
sec_attr_stdin.nLength = sizeof(sec_attr_stdin);
|
||||
sec_attr_stdin.bInheritHandle = TRUE;
|
||||
ASSERT_TRUE(::CreatePipe(&child_stdin_read, &child_stdin_write,
|
||||
&sec_attr_stdin, 0));
|
||||
ASSERT_TRUE(::SetHandleInformation(child_stdin_write, HANDLE_FLAG_INHERIT,
|
||||
0));
|
||||
|
||||
// Startup the child.
|
||||
STARTUPINFO startup_info = {};
|
||||
PROCESS_INFORMATION process_info = {};
|
||||
startup_info.cb = sizeof(STARTUPINFO);
|
||||
startup_info.hStdError = NULL;
|
||||
startup_info.hStdInput = child_stdin_read;
|
||||
startup_info.hStdOutput = child_stdout_write;
|
||||
startup_info.dwFlags = STARTF_USESTDHANDLES;
|
||||
ASSERT_TRUE(::CreateProcessW(NULL, (LPWSTR)command_line.c_str(), NULL, NULL,
|
||||
TRUE, 0, NULL, NULL,
|
||||
&startup_info, &process_info));
|
||||
|
||||
// Collect the output.
|
||||
ASSERT_TRUE(::CloseHandle(child_stdout_write));
|
||||
char buffer[4096] = {};
|
||||
DWORD bytes_read = 0;
|
||||
while (::ReadFile(child_stdout_read, buffer, sizeof(buffer), &bytes_read,
|
||||
NULL) && bytes_read > 0) {
|
||||
stdout_string->append(buffer, bytes_read);
|
||||
}
|
||||
|
||||
// Wait for the process to finish.
|
||||
::WaitForSingleObject(process_info.hProcess, INFINITE);
|
||||
|
||||
// Shut down all of our handles.
|
||||
ASSERT_TRUE(::CloseHandle(process_info.hThread));
|
||||
ASSERT_TRUE(::CloseHandle(process_info.hProcess));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdin_write));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdin_read));
|
||||
ASSERT_TRUE(::CloseHandle(child_stdout_read));
|
||||
}
|
||||
|
||||
void GetFileContents(const std::wstring& path, std::string* content) {
|
||||
FILE* f = ::_wfopen(path.c_str(), L"rb");
|
||||
ASSERT_TRUE(f != NULL);
|
||||
|
||||
char buffer[4096] = {};
|
||||
while (true) {
|
||||
size_t bytes_read = ::fread(buffer, 1, sizeof(buffer), f);
|
||||
if (bytes_read == 0)
|
||||
break;
|
||||
content->append(buffer, bytes_read);
|
||||
}
|
||||
}
|
||||
|
||||
class DumpSymsRegressionTest : public testing::TestWithParam<const wchar_t*> {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
std::wstring self_dir;
|
||||
ASSERT_TRUE(GetSelfDirectory(&self_dir));
|
||||
dump_syms_exe = self_dir + L"\\dump_syms.exe";
|
||||
|
||||
TrimLastComponent(self_dir, &testdata_dir, NULL);
|
||||
testdata_dir += L"\\testdata";
|
||||
}
|
||||
|
||||
std::wstring dump_syms_exe;
|
||||
std::wstring testdata_dir;
|
||||
};
|
||||
|
||||
class DumpSymsPEOnlyRegressionTest : public testing::TestWithParam<const wchar_t*> {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
std::wstring self_dir;
|
||||
ASSERT_TRUE(GetSelfDirectory(&self_dir));
|
||||
dump_syms_exe = self_dir + L"\\dump_syms.exe";
|
||||
|
||||
TrimLastComponent(self_dir, &testdata_dir, NULL);
|
||||
testdata_dir += L"\\testdata";
|
||||
}
|
||||
|
||||
std::wstring dump_syms_exe;
|
||||
std::wstring testdata_dir;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
TEST_P(DumpSymsRegressionTest, EnsureDumpedSymbolsMatch) {
|
||||
const wchar_t* root_name = GetParam();
|
||||
std::wstring root_path = testdata_dir + L"\\" + root_name;
|
||||
|
||||
std::wstring sym_path = root_path + L".sym";
|
||||
std::string expected_symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(GetFileContents(sym_path, &expected_symbols));
|
||||
|
||||
std::wstring pdb_path = root_path + L".pdb";
|
||||
std::wstring command_line = L"\"" + dump_syms_exe + L"\" \"" +
|
||||
pdb_path + L"\"";
|
||||
std::string symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(RunCommand(command_line, &symbols));
|
||||
|
||||
EXPECT_EQ(expected_symbols, symbols);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DumpSyms, DumpSymsRegressionTest,
|
||||
testing::ValuesIn(kRootNames));
|
||||
|
||||
TEST_P(DumpSymsPEOnlyRegressionTest, EnsurePEOnlyDumpedSymbolsMatch) {
|
||||
const wchar_t* root_name = GetParam();
|
||||
std::wstring root_path = testdata_dir + L"\\" + root_name;
|
||||
|
||||
std::wstring sym_path = root_path + L".sym";
|
||||
std::string expected_symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(GetFileContents(sym_path, &expected_symbols));
|
||||
|
||||
std::wstring dll_path = root_path + L".dll";
|
||||
std::wstring command_line = L"\"" + dump_syms_exe + L"\" --pe \"" +
|
||||
dll_path + L"\"";
|
||||
std::string symbols;
|
||||
ASSERT_NO_FATAL_FAILURE(RunCommand(command_line, &symbols));
|
||||
|
||||
EXPECT_EQ(expected_symbols, symbols);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PEOnlyDumpSyms, DumpSymsPEOnlyRegressionTest,
|
||||
testing::ValuesIn(kPEOnlyRootNames));
|
||||
|
||||
|
||||
} // namespace dump_syms
|
||||
} // namespace windows
|
||||
} // namespace tools
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2006, Google Inc.
|
||||
# All rights reserved.
|
||||
# Copyright 2006 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -13,7 +12,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2007 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
// Copyright 2006 Google LLC
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
@@ -11,7 +10,7 @@
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// * Neither the name of Google LLC nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2013 Google Inc. All rights reserved.
|
||||
# Copyright 2013 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2017 Google Inc. All rights reserved.
|
||||
# Copyright 2017 Google LLC
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
@@ -10,7 +10,7 @@
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# * Neither the name of Google LLC nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user