19abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// Copyright (c) 2007, Google Inc.
29abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// All rights reserved.
39abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//
49abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// Redistribution and use in source and binary forms, with or without
59abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// modification, are permitted provided that the following conditions are
69abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// met:
79abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//
89abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//     * Redistributions of source code must retain the above copyright
99abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// notice, this list of conditions and the following disclaimer.
109abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//     * Redistributions in binary form must reproduce the above
119abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// copyright notice, this list of conditions and the following disclaimer
129abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// in the documentation and/or other materials provided with the
139abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// distribution.
149abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//     * Neither the name of Google Inc. nor the names of its
159abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// contributors may be used to endorse or promote products derived from
169abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// this software without specific prior written permission.
179abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//
189abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
199abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
209abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
219abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
229abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
239abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
249abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
259abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
269abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
279abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
289abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
309abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// file_id.h: Return a unique identifier for a file
319abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai//
329abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai// Author: Alfred Peng
339abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
349abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai#ifndef COMMON_SOLARIS_FILE_ID_H__
359abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai#define COMMON_SOLARIS_FILE_ID_H__
369abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
379abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai#include <limits.h>
389abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
399abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovainamespace google_breakpad {
409abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
419abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovaiclass FileID {
429abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai public:
439abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  FileID(const char *path);
449abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  ~FileID() {};
459abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
469abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // Load the identifier for the elf file path specified in the constructor into
479abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // |identifier|.  Return false if the identifier could not be created for the
489abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // file.
499abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // The current implementation will return the MD5 hash of the file's bytes.
509abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  bool ElfFileIdentifier(unsigned char identifier[16]);
519abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
529abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // Convert the |identifier| data to a NULL terminated string.  The string will
539abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // be formatted as a MDCVInfoPDB70 struct.
549abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // The |buffer| should be at least 34 bytes long to receive all of the data
559abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // and termination. Shorter buffers will return false.
569abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  static bool ConvertIdentifierToString(const unsigned char identifier[16],
579abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai                                        char *buffer, int buffer_length);
589abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
599abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai private:
609abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  // Storage for the path specified
619abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai  char path_[PATH_MAX];
629abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai};
639abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
649abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai}  // namespace google_breakpad
659abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai
669abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai#endif  // COMMON_SOLARIS_FILE_ID_H__
67